Created
October 2, 2011 19:44
-
-
Save winex/1257839 to your computer and use it in GitHub Desktop.
minecraft: Zan2Rei waypoints converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk -f | |
BEGIN { | |
FS = ":"; | |
nether_mode = 0 | |
if (ARGC > 1) { | |
for (i = 1; i < ARGC; i++) { | |
arg = ARGV[i] | |
if (arg !~ /^-/) | |
break | |
if (arg ~ /(-h|--help)/) { | |
print "Usage: "ARGV[0]" [-n|--nether] POINTS_FILE" >"/dev/stderr" | |
exit 0 | |
} | |
if (arg ~ /(-n|--nether)/) | |
nether_mode = 1 | |
delete ARGV[i] | |
} | |
} | |
} | |
{ | |
# output blank lines and comments as is | |
if (/^([\s]*|#.*)$/) { | |
print $0 | |
next | |
} | |
if (NF != 7) { | |
print "invalid format: wrong number of fields" >"/dev/stderr" | |
exit 1 | |
} | |
x = $2 | |
z = $3 | |
# nether points have coords * 8, not 'n-2, n+3' as i thought before | |
nether_input = ((x % 8) == 0) && ((z % 8) == 0) | |
if (nether_mode) | |
{ | |
if (!nether_input) | |
next | |
x = int(x / 8) | |
z = int(z / 8) | |
} | |
r = int($5 * 255) | |
g = int($6 * 255) | |
b = int($7 * 255) | |
rgb = sprintf("%02X%02X%02X", r, g, b) | |
print $1":"x":"64":"z":"$4":"rgb | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$DEBUG = false; | |
function print_form($script, $upname, $chkboxname) | |
{ | |
echo( | |
"<form enctype='multipart/form-data' action='" . $script . "' method='POST'> | |
Choose Zan's .points file: | |
<input type='hidden' name='MAX_FILE_SIZE' value='1048576' /> | |
<input name='" . $upname . "' type='file' /><input name='" . $chkboxname . "' type='checkbox'>nether mode</input><br/> | |
<input type='submit' value='Convert' /> | |
</form> | |
<p>Note: save to <b>.minecraft/mods/rei_minimap/</b></p> | |
"); | |
} | |
function process($file, $nether_mode) | |
{ | |
global $DEBUG; | |
$file['error'] && die($file['tmp_name']."error: upload failed!\n"); | |
$name = preg_replace("/\.points$/", "", $file['name']); | |
$name .= ".DIM" . ($nether_mode ? "-1" : "0"); | |
$name .= ".points"; | |
$opts = ""; | |
$opts .= ($nether_mode ? "-n" : ""); | |
$out = system("./points-zan2rei.awk " . $opts . " " . escapeshellarg($file['tmp_name']) . " 2>&1", $retval); | |
if ($retval != 0) | |
return; | |
if ($DEBUG) | |
return; | |
header("Content-Type: text/plain"); | |
header("Content-Disposition: attachment; filename=\"" . $name . "\""); | |
} | |
// | |
// main | |
// | |
if (!$_SERVER['QUERY_STRING']) | |
{ | |
print_form($_SERVER['PHP_SELF'] . "?process", "file0", "nether_mode"); | |
return; | |
} | |
if (!$_FILES) { | |
header("Location: " . $_SERVER['PHP_SELF']); | |
return; | |
} | |
if ($DEBUG) { | |
echo("<pre>"); | |
print_r($_POST); | |
print_r($_FILES); | |
echo("</pre>\n"); | |
} | |
$nether_mode = false; | |
if (isset($_POST["nether_mode"])) | |
$nether_mode = strcasecmp($_POST["nether_mode"], "on") == 0; | |
process($_FILES["file0"], $nether_mode); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment