Created
March 28, 2012 08:58
-
-
Save idiosync/2224914 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
#set -e | |
USAGE="Usage: ${0} [options] | |
Uses mcexplore.py to explore a seed, and c10t to make a number of maps of that seed. | |
Requires: | |
mcexplore.py (https://gist.github.com/854679) | |
c10t (https://github.com/udoprog/c10t) | |
advdef (http://advancemame.sourceforge.net/comp-readme.html) | |
imagemagick (http://www.imagemagick.org/script/index.php) | |
Notes: | |
All of the required tools are assumed to be in your path | |
Advdef and imagemagick are generally packaged for your distro. | |
Advdef is only there to squeeze some large PNG files down, and | |
you can just comment out the one line that uses it if you want | |
to avoid the requirement. | |
Options: | |
-h Display this usage information | |
-r SERVER_ROOT Specify the folder that contains your Minecraft server (default: ~/minecraft/) | |
-p SERVER_PORT Set the port your server will run on while exploring (default: 25501) | |
-f SEED_FILE Specify a file containing one seed per line to explore sequentially | |
-s SEED Specify a seed (mutually exclusive with -f) (default: randomized) | |
-l LENGTH Set the length in regions of a side of the square map that's explored (default: 4) | |
-o OUTPUT_PATH Specify the path to store map images (creates subfolder per seed) (default: ~/mcmaps) | |
" | |
SERVER=~/minecraft | |
PORT="25501" | |
SEED="" | |
SEEDFILE="" | |
LENGTH=4 | |
OUTPUTPATH=~/minecraft/mcmaps/1.2.4 | |
while getopts “hr:p:f:s:l:o:†OPTION | |
do | |
case $OPTION in | |
h) echo "$USAGE" ; exit 1 ;; | |
r) SERVER=$OPTARG ;; | |
p) PORT=$OPTARG ;; | |
f) SEEDFILE=$OPTARG ;; | |
s) SEED=$OPTARG ;; | |
l) LENGTH=$OPTARG ;; | |
o) OUTPUTPATH=$OPTARG ;; | |
esac | |
done | |
randomseed() { | |
dd if=/dev/urandom 2>&1 bs=32 count=1 | md5sum | cut -d " " -f 1 | |
} | |
[ "${SEED}" != "" ] && [ "${SEEDFILE}" != "" ] && echo "Please only specify either the seed, or the seed file." && exit 1 | |
[ "${SEEDFILE}" != "" ] && [ ! -f "${SEEDFILE}" ] && echo "${SEEDFILE} not found." && exit 1 | |
[ "${SEEDFILE}" == "-" ] && SEEDFILE="/dev/stdin" | |
[ "${SEED}" == "" ] && [ "${SEEDFILE}" == "" ] && SEED=$(randomseed) | |
PROPERTIES="level-name=world | |
allow-nether=false | |
view-distance=10 | |
spawn-monsters=false | |
online-mode=false | |
difficulty=1 | |
gamemode=0 | |
spawn-animals=false | |
max-players=20 | |
server-ip= | |
pvp=true | |
level-seed=SEED | |
server-port=PORT | |
allow-flight=false | |
white-list=false | |
motd=A Minecraft Server" | |
genmap() { | |
SEED=${1} | |
OUTPUT="${OUTPUTPATH}/${SEED}" | |
pushd "${SERVER}" | |
[ -d world ] && rm -rf world | |
echo "${PROPERTIES}" | sed "s|SEED|${SEED}|;s|PORT|${PORT}|" > server.properties | |
echo "Initializing server [${SEED}]" | |
echo 'stop' | java -jar minecraft_server.jar nogui | |
echo "Exploring world [${SEED}]" | |
#~/minecraft/mcexplore.py -x 0 -z 0 -r "${LENGTH}" "${LENGTH}" | |
~/minecraft/mcexplore.py -r "${LENGTH}" "${LENGTH}" | |
popd | |
mkdir -p ${OUTPUT} | |
cp ${SERVER}/world/level.dat ${OUTPUT} | |
echo "Rendering maps [${SEED}]" | |
#~/minecraft/c10t/c10t -w ${SERVER}/world -o "${OUTPUT}"/flat.png | |
#~/minecraft/c10t/c10t -w ${SERVER}/world -o "${OUTPUT}"/cave.png -c | |
#~/minecraft/c10t/c10t -w ${SERVER}/world -o "${OUTPUT}"/cheat.png -a -i 98 -i 48 | |
#~/minecraft/c10t/c10t -w ${SERVER}/world -o "${OUTPUT}"/height.png -H | |
#~/minecraft/c10t/c10t -w ${SERVER}/world -o "${OUTPUT}"/iso.png -z | |
echo "mcmap "${SERVER}"/world "${OUTPUT}"/iso.png" | |
mcmap ${SERVER}/world | |
cp ${SERVER}/output.png ${OUTPUT}/iso.png | |
advdef -z -4 ${SERVER}/output.png | |
mv ${SERVER}/output.png ${OUTPUTPATH}/${SEED}.png | |
#pushd "${OUTPUT}" | |
# echo "Compositing maps [${SEED}]" | |
# composite -dissolve 15% flat.png height.png height-cmp.png | |
# composite -dissolve 25% flat.png cheat.png cheat-cmp.png | |
# composite -dissolve 25% flat.png cave.png cave-cmp.png | |
# #montage -geometry +2+2 flat.png height-cmp.png cheat-cmp.png cave-cmp.png montage.png | |
# convert flat.png -resize 10% thumb.png | |
# echo "Converting maps [${SEED}]" | |
# for f in *.png ; do | |
# convert "${f}" "${f%.*}.jpg" | |
# done | |
# echo "Recompressing maps [${SEED}]" | |
# advdef -z -4 *.png | |
#popd | |
} | |
if [ "${SEEDFILE}" != "" ] ; then | |
for SEED in $(cat "${SEEDFILE}") ; do | |
genmap "${SEED}" | |
done | |
else | |
genmap "${SEED}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment