master
Raw Download raw file

layout: post title: “Move Minecraft Spawn with Python” date: 2012-04-29 21:54 categories: Python Minecraft keywords: “Python, Minecraft, NBT, Spawn” comments: true

{% img right http://i.imgur.com/uubl0.png 150 150 Minecraft %}

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

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()