Question
With all of the recent biome generation changes, I've found myself generating a lot of new worlds lately, and once 1.9 hits I'll do it again.
When I restart the world on my server I would the inventories of all my players to be migrated over to the new world. This way people who have already been playing for quite some time on my server won't lose everything, and can bring their gold, diamonds, cookies, etc. to ease the transition. I'm wary of simply copying player data over because if it includes player position there's a high chance of players appearing in places they shouldn't. (Like in solid ground.)
So I'm looking for an automated tool that I can run once before the players sign in to the new world that copies over all player inventory and nothing else. Note that I'm just running a vanilla server, and would like to continue doing so. If this tool doesn't exist, is there a manual way to do so?
Edit: If I get a good enough response and someone knows how to migrate inventory manually, I just might code the tool myself and put it somewhere for everyone.
Answer
player.dat
is a gzipped file. If you unzip it, you can find the Pos
field (string "Pos" and then 32 bytes of coordinates). So, you need to change those bytes.
I used Perl for this purpose:
process_file.sh
#!/bin/bash
FILE_NAME_BASE="${1%.dat}"
echo "Processing ${FILE_NAME_BASE}..."
mv "${FILE_NAME_BASE}.dat" "${FILE_NAME_BASE}.gz"
gunzip "${FILE_NAME_BASE}.gz"
perl -pe 's/Pos[\x{00}-\x{ff}]{32}/Pos\x{06}\x{00}\x{00}\x{00}\x{03}\x{c0}\x{88}\x{c4}\x{00}\x{00}\x{00}\x{00}\x{00}\x{40}\x{51}\x{67}\x{ae}\x{14}\x{80}\x{00}\x{00}\x{c0}\x{b3}\x{e4}\x{80}\x{00}\x{00}\x{00}\x{00}\x{02}\x{00}\x{0a}/' < "${FILE_NAME_BASE}" > "${FILE_NAME_BASE}.out"
mv "${FILE_NAME_BASE}.out" "${FILE_NAME_BASE}"
gzip "${FILE_NAME_BASE}"
mv "${FILE_NAME_BASE}.gz" "${FILE_NAME_BASE}.dat"
process_all.sh
#!/bin/bash
find . -name "*.dat" -exec ./process_file.sh \{\} \;
echo "Done."
If you run process_all.sh
in folder world/players
, it changes the Pos
field of all players to 06 00 00 00 03 c0 88 c4 00 00 00 00 00 40 51 67 ae 14 80 00 00 c0 b3 e4 80 00 00 00 00 02 00 0a
(hexadecimal). Of course, you can change these values to move players to another point.
Check more discussion of this question.
No comments:
Post a Comment