Minecraft Scripts

A note from the future!

For historical context the scripts below are from 2010 and 2011. They are really no longer relevant to a current release of Minecraft, or maintained, and I'm sure all the links are broken. I did write them, I'm proud of them, and no I won't stop talking about them. EVER!

Q1. How do I run minecraft_file_wdw_v2.py for the first time?

Answer:

You are going to need Python 2.7, Numpy, PIL, NBT, and WxPython installed for minecraft_file_wdw_v2.py to run. This script is written to open files from the folder Python runs in, in my case that was c:\python27. Copy minecraft_file_wdw_v2.py, a copy of the region file you want to update, and the NBT compiled library to the python27 folder.

For example, to work with “r.-1.1.mcr” open the minecraft_file_wdw_v2.py script using IDLE and edit the filetoread global variable under global inits:

#######################

# Global Inits

#######################

filetoread = "r.-1.1.mcr"

From the operating system rename the “r.-1.1.mcr” file in the python folder to "r.-1.1 - Copy.mcr".

Important: Writing new content to a region file with minecraft_file_wdw_v2.py corrupts the file, and will only work once. You need to always start with an original region file each time you run the script.

For this reason, the run() function has a quick copyfile call that will make a new working file from this convenient copy of the original .mcr file:

def run(dialog):

shutil.copyfile("r.-1.1 - Copy.mcr","r.-1.1.mcr") #<-

It is bad design on my part, but to get the program to work repeatedly for a region file you need to move the file to the python folder, rename it, and change the reference to it in the global inits, and run() functions as described above.

Review the savemoddedchunk() function, for a first time run you want it to look like this:

def savemoddedchunk(dialog):

global filetoread

print ("Opening file " + filetoread + "...")

volume_factory = VolumeFactory()

region_volume = volume_factory.load_region(filetoread)

#This is where you put need things in the map.

#This creates an image overview of the map.

imagevolume_factory(region_volume,dialog)

return region_volume

Once these changes are made simply press F5 in IDLE to run the script and wait for the progress bar to complete. Under the python folder you will find one.png which will give you an overview of the region file:

In this case you can see a mine cart track running across the top of the map with the outline of a sphere in the center of the map. That sphere was made out of dynamite, and was a horrible idea. See “How do I run minecraft_file_wdw_v2.py and actually update something?” for more details.

Q2. Will this corrupt my region files?

Answer:

Absolutely, this hodge-podge of other people’s well intentioned code represents the leading edge of Minecraft region file corruption. I guarantee that every file updated will contain the following dimensions of corruption in glorious 3D:

    • The squirrel monkeys that coded the geometry functions did not think much about lighting. Some places will be really dark when they should not be; some places will be really bright when they should not be. Actual lighting conditions will vary broadly from expected lighting conditions, so bring a torch when you go exploring.
    • The tufted capuchins that coded the file update realized that they were restricted to the original file stream size for a given region chunk file. Rather then figuring out how to increase the chunk allocation the “right” way, they opted to convert layers of the chunk to stone starting at Y-1 until compression would allow the update to work.
    • The spider monkeys that mapped out the overall process did not expect it to work, but then it did, but only once. To their immense surprise they could create a file that Minecraft would forgive and read. However, if they tried to update the same file a second time there was only failure, and poo flinging. Eventually they discovered if they backed up their original files, they could live with it.

Q3. How do I run minecraft_file_wdw_v2.py and actually update something?

Answer:

First you will need to review the one.png generated from your first run through. Does the overview of the map appear to be missing sections?

Minecraft generates geography when your character moves through the world. If the map you generated in your first run through has blank spots you should open Minecraft and go on a walkabout, and visit those areas of the map that are still blank to fill them in. Then copy the new region file into your python folder, and generate a new image file to make sure the region is complete.

Warning!: If the region file you work with is not complete and you perform an update minecraft_file_wdw_v2.py will die horribly. You will be fine.

Once your region file is complete it is time to make your first update! Review the savemoddedchunk() function:

def savemoddedchunk(dialog):

global filetoread

print ("Opening file " + filetoread + "...")

volume_factory = VolumeFactory()

region_volume = volume_factory.load_region(filetoread)

#This is where you put need things in the map.

#This creates an image overview of the map.

imagevolume_factory(region_volume,dialog)

return region_volume

To add content to your region files use the dirty functions, here is an example of adding a sphere of dynamite to the approximate center of the map, with a radius of 50:

def savemoddedchunk(dialog):

global filetoread

print ("Opening file " + filetoread + "...")

volume_factory = VolumeFactory()

region_volume = volume_factory.load_region(filetoread)

#This is where you put need things in the map.

dirtysphere(region_volume,255,255,60,50,46)

#This creates an image overview of the map.

#imagevolume_factory(region_volume,dialog)

return region_volume

See the dirtysphere() function for a complete list of parameters. Once these changes are made simply press F5 in IDLE to run the script and wait for the progress bar to complete. Under the python folder you will find one.png which will give you an overview of the region file:

The outline of the dynamite sphere is in the center of the map. By the way, this was a horrible idea since the center of the sphere was at 60 with a radius of 50. This sphere runs from Y – 10 to Y – 110 and will intersect with lava at some lower elevation. Kaboom!

If you would like to see a truly large hole in the ground move this file back to your Minecraft region folder and go exploring. You should hear some explosions in the distance as you approach the center of the map.

Warning!: Make a stupid backup of your files before you use this buggy code to corrupt them. You will not regret it!

Q4. def dirtysphere(region_volume,x1,z1,y1,r1,newvalue):

Answer:

def dirtysphere(region_volume,x1,z1,y1,r1,newvalue):

Parameters Description

region_volume The region_volume represents the region file information in memory as an easy to use structure. Region_volume was implemented as part of Weeble’s VolumeFactory class; you can find more information at his blog: http://clockworkcodex.blogspot.com/2011/06/minecraft-mapping-reading-minecraft.html

x1 Integer x coordinate, value from 0 – 511

z1 Integer z coordinate, value from 0 – 511

y1 Integer y coordinate, value from 0 – 127

r1 Integer radius of the sphere

newvalue Integer representing the block type.

Dirtysphere () is used to create a hollow sphere shape of block type newvalue. The sphere will be centered at (x1,z1,y1) with a radius of r1. The function has no boundary detection, or error checking. To work properly the radius of the circle must not exceed the dimensions of the region file. For example, y1 + r1 must be less than 127 and y1 - r1 must be greater then 0.

Q5. def dirtyspans(region_volume,x1,x2,z1,z2,y1,y2,newvalue):

Answer:

def dirtyspans(region_volume,x1,x2,z1,z2,y1,y2,newvalue):

Parameters Description

region_volume The region_volume represents the region file information in memory as an easy to use structure. Region_volume was implemented as part of Weeble’s VolumeFactory class; you can find more information at his blog: http://clockworkcodex.blogspot.com/2011/06/minecraft-mapping-reading-minecraft.html

x1 Integer x coordinate, value from 0 – 511

x2 Integer x coordinate, value from 0 – 511

z1 Integer z coordinate, value from 0 – 511

z2 Integer z coordinate, value from 0 – 511

y1 Integer y coordinate, value from 0 – 127

y2 Integer y coordinate, value from 0 – 127

newvalue Integer representing the block type.

Dirtyspans() is used to create a solid, 3D rectangular area of block type newvalue. The rectangular area will start at (x1,z1,y1) and end at (x2,z2,y2). It is important to note that the first set of coordinates must be less than the second set for an update to work properly.

Q6. def dirtypyramid(region_volume,x1,z1,y1,h1,newvalue):

Answer:

def dirtypyramid(region_volume,x1,z1,y1,h1,newvalue):

Parameters Description

region_volume The region_volume represents the region file information in memory as an easy to use structure. Region_volume was implemented as part of Weeble’s VolumeFactory class; you can find more information at his blog: http://clockworkcodex.blogspot.com/2011/06/minecraft-mapping-reading-minecraft.html

x1 Integer x coordinate, value from 0 – 511

z1 Integer z coordinate, value from 0 – 511

y1 Integer y coordinate, value from 0 – 127

h1 Integer height coordinate, value from 0 – y1

newvalue Integer representing the area’s block type.

Dirtypyramid () is used to create a solid, pyramid shaped area of block type newvalue. The area will start at (x1,z1,y1) with a 4 x 4 slab, increasing by 1 block in size down to layer y1-h1.

Q7. def dirtychunks(region_volume,x,z,y,newvalue):

Answer:

def dirtychunks(region_volume,x,z,y,newvalue):

Parameters Description

region_volume The region_volume represents the region file information in memory as an easy to use structure which dirtychunks() references to update a single block to a new value. Region_volume was implemented as part of Weeble’s VolumeFactory class; you can find more information at his blog: http://clockworkcodex.blogspot.com/2011/06/minecraft-mapping-reading-minecraft.html

x Integer x coordinate, value from 0 – 511

z Integer z coordinate, value from 0 – 511

y Integer y coordinate, value from 0 – 127

newvalue Integer representing the block value

Dirtychuncks() is used to set a single block in the region_volume to a new value. This function is unique in that all other functions call dirtychunks() to make updates to the region_volume.