Move Minecraft Spawn with Python

Published on:

The setup for this post is that in a vanilla Minecraft server there isn’t a way to set the protection size to 0 (yes, I know bukkit can do this but, meh).  This makes having the spawn in the middle of a nice area with shared chests, smelting, etc. a pain.  So I wanted to move the spawn but I didn’t want to have to download the whole world, open it with a map editor, and then re-upload the whole thing again.  Especially since I know the values are just stored inside the level.dat.  So, below is how I used twoolie’s python NBT interface to move the spawn on our server.

To install NBT, grab it from either github or pypi

spawn-move.py
1
2
3
4
5
6
7
8
from nbt import *
level = nbt.NBTFile('/<insert.path.here>/world/level.dat','rb')
level["Data"]["SpawnX"].value = newx
level["Data"]["SpawnY"].value = newy
level["Data"]["SpawnZ"].value = newz
print(level.pretty_tree())  # show changes
level.write_file('/<insert.path.here>/world/level.dat')
exit()

Comments