Last active
August 29, 2015 14:18
-
-
Save scottoffen/0add9f81efa1d89204ac to your computer and use it in GitHub Desktop.
Use Perl to create an AutoHotKey (ahk) macro that will run and build out your Minecraft world map
This file contains hidden or 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
#!c:\lang\perl\bin\perl.exe | |
use strict; | |
use warnings; | |
use Fcntl qw(:DEFAULT :flock); | |
# How high you want to be teleported | |
my $y = 200; | |
# The x offset for the center of the map | |
my $offx = 1000; | |
# The z offset for the center of the map | |
my $offz = 1000; | |
# The number of blocks to move in between jumps | |
my $jump = 400; | |
# The desired minimum map size, as an absolute value | |
my $size = 1000; | |
# The output file to save to | |
my $path = "./map.ahk.txt"; | |
# The template used for each jump | |
our $template = <<AUTO; | |
Sleep, [w] | |
SendInput t | |
Sleep, 1000 | |
SendInput /tp [x] [y] [z]{Enter} | |
AUTO | |
mkfile($path, build($jump, $size, $offx, $offz)); | |
sub mkfile | |
{ | |
my ($path, $code) = @_; | |
my $result = open(my $file, ">", $path); | |
flock ($file, LOCK_EX); | |
print $file $code; | |
close($file); | |
return $result; | |
} | |
sub mktime | |
{ | |
my ($time) = @_; | |
$time = sprintf("%.0f", ($time/1000)); | |
my $seconds = $time % 60; | |
my $minutes = (($time - $seconds) / 60) % 60; | |
my $hours = (($time - (($minutes * 60) + $seconds)) / 60) / 60; | |
return join(':', ($hours, $minutes, $seconds)); | |
} | |
sub mksize | |
{ | |
my ($jump, $size) = @_; | |
my $factor = $size / $jump; | |
my $modulo = $size % $jump; | |
$factor = sprintf("%.0f", $factor); | |
$factor += 1 if ($modulo); | |
my $max = $factor * $jump; | |
my $min = $max * -1; | |
return ($max, $min); | |
} | |
sub mkcode | |
{ | |
my ($w, $x, $y, $z) = @_; | |
my $t = $template; | |
$t =~ s/\[x\]/$x/ig; | |
$t =~ s/\[y\]/$y/ig; | |
$t =~ s/\[z\]/$z/ig; | |
$t =~ s/\[w\]/$w/ig; | |
return $t; | |
} | |
sub build | |
{ | |
my ($jump, $size, $offsetx, $offsetz) = @_; | |
$offsetx = 0 unless ($offsetx); | |
$offsetz = 0 unless ($offsetz); | |
my $wait = (($jump * 100) > 20000) ? 20000 : $jump * 100; | |
my ($max, $min) = mksize($jump, $size); | |
my $time = 0; | |
my $jumps = 0; | |
my @code; | |
for (my $x = $max; $x >= $min; $x -= $jump) | |
{ | |
for (my $z = $max; $z >= $min; $z -= $jump) | |
{ | |
push(@code, mkcode($wait, ($x + $offsetx), $y, ($z + $offsetz))); | |
$time += ($wait + 1000); | |
$jumps += 1; | |
} | |
} | |
print "time : " . mktime($time) . "\n"; | |
print "wait : " . ($wait/1000) . "\n"; | |
print "jumps : $jumps\n"; | |
print "size : $max/$min\n\n"; | |
return join("", @code); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment