Last active
January 22, 2023 02:45
-
-
Save Kas-tle/c9b425521d6ec180cf53e6e1688252bd to your computer and use it in GitHub Desktop.
Extract tile heads from a minecraft world
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
# Depends on: | |
# sudo apt install libjson-perl | |
# sudo apt install libcompress-raw-zlib-perl | |
if [[ ! -d world ]]; then | |
tar -xf ${1} world | |
fi | |
if [[ ! -d run ]]; then | |
git clone https://github.com/MirrgieRiana/nbt_to_json_perl.git run | |
fi | |
if [[ ! -f run/mca.jar ]]; then | |
wget https://github.com/Querz/mcaselector/releases/download/2.1/mcaselector-2.1.jar -O run/mca.jar | |
fi | |
mkdir -p scratch/json | |
mkdir -p scratch/csv | |
mkdir -p target | |
java -jar run/mca.jar --mode select --world world --query 'Palette contains "player_head"' --output scratch/csv/mca.tiles.csv | |
java -jar run/mca.jar --mode select --world world --query 'Entities contains "armor_stand"' --output scratch/csv/mca.entities.csv | |
jq -R -r '[. | split(";")] | map((.[0]|tonumber), (.[1]|tonumber), (fmod(.[2]|tonumber; 32)|length), (fmod(.[3]|tonumber; 32)|length)) | @csv' scratch/csv/mca.tiles.csv > scratch/csv/tiles.csv | |
jq -R -r '[. | split(";")] | map((.[0]|tonumber), (.[1]|tonumber), (fmod(.[2]|tonumber; 32)|length), (fmod(.[3]|tonumber; 32)|length)) | @csv' scratch/csv/mca.entities.csv > scratch/csv/entities.csv | |
wait_for_jobs () { | |
while test $(jobs -p | wc -w) -ge "$((2*$(nproc)))"; do wait -n; done | |
} | |
get_tile_heads() { | |
./run/region ${1} ${2} ${3} | ./run/inflate-zlib | ./run/nbt2json | jaq -r '[.. | select(.key? == "textures") | .value.values[][].value]' > scratch/json/${1##*/}.${2}.${3}.tile.json | |
} | |
get_entity_heads() { | |
./run/region ${1} ${2} ${3} | ./run/inflate-zlib | ./run/nbt2json | jaq -r '[.. | select(.key? == "textures") | .value.values[][].value]' > scratch/json/${1##*/}.${2}.${3}.entity.json | |
} | |
while IFS="," read -r rx rz x z; do | |
wait_for_jobs | |
get_tile_heads "world/region/r.${rx}.${rz}.mca" ${x} ${z} & | |
done < scratch/csv/tiles.csv | |
while IFS="," read -r rx rz x z; do | |
wait_for_jobs | |
get_entity_heads "world/entities/r.${rx}.${rz}.mca" ${x} ${z} & | |
done < scratch/csv/entities.csv | |
yq -y -s '. | add | unique' scratch/json/*.json > target/heads.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment