Python Script to migrate minecraft players to a new server so that they maintain inventory and spawn at a chosen location.
py -m pip install "nbtlib==1.12.1"
- issues with latest nbtlib 2.0.4
python 3.10.0
migrate.py [-h] -l LOADPATH -s SAVEPATH -x XCORD -y YCORD -z ZCORD
-
Example cmd:
py migrate.py -l "C:\Minecraft\world\playerdata" -s "C:\Minecraft\backup\playerdata" -x -100 -y 200 -z 300
-
Help:
py migrate.py -h
MC Player Migration
options:
-h, --help show this help message and exit
-l LOADPATH, --loadpath LOADPATH
Path to load Old PlayerData
-s SAVEPATH, --savepath SAVEPATH
Path to Save Updated PlayerData
-x XCORD, --xcord XCORD
X Coordinate for spawn overwrite
-y YCORD, --ycord YCORD
Y Coordinate for spawn overwrite
-z ZCORD, --zcord ZCORD
Z Coordinate for spawn overwrite
- Copies all .dat files from old server (LoadPath), updates a few key tags, and saves the updated user to your Save Path.
- .dat_old files are ignored.
- Checks if LoadPath and SavePath exists before continuing, if either dir doesn't exist program will not attempt to create them and exit 1 with message
Error occurred while confirming Path Dir: {err}
- Can be run from any directory, it will produce a log
player-migration.log
in the dir program was run from. - Best to not have other NBT editor tools open when running, though I haven't had direct conflicts with NBTExplorer.
Refer to player.dat fromat documentation.
The goal here is for players to come on to a new minecraft server without concern that they were famished or dying when they were on the last server and keep what ever is on them. In addition we want to make it safe and avoid unexpected spawn locations into deathly traps.
- LastDeathLocation: Remove, some plugins use this tag to allow easy
/back
. This could be deadlier after a migration... - Pos: Where player will spawn on join. This is where flags -x -y -z are injected.
- Dimension: Set to minecraft:overworld
- foodExhaustionLevel: Set to 0. See hunger for more details. We want our players to be fed and ready to explore on a new map!
- foodLevel: Set to 20
- foodStaturationLevel: Set to 5
- Health: Set to 20
- HurtByTimestamp: Set to 0
- HurTime: Set to 0
- OnGround: Set to 1, True
- PlayerGameType: Set to 0, Survival
- SpawnForced: Remove. If player should spawn to their last bed location, even if it doesn't exist. Don't want an unintended death on our hands on a new map!
- SpawnX: Remove. X Coordinates for bed location.
- SpawnY: Remove. Y Coordinates for bed location.
- SpawnZ: Remove. Z Coordinates for bed location.