Classic level format
The Classic level format is used by all varieties of Minecraft Classic. It is compressed with gzip and contains a short header followed by serialized Java objects. Single-player levels have the extension ".mine". Levels used by the Classic Creative server are named "server_level.dat". The file can be backed up to save content which helps to protect constructions against griefers or to use the file for map editing.
Because the format of this level depends on the way Java serializes objects, the easiest way to work with it is through the Classic server itself, Sample code is provided to show how to build an editor on top of minecraft-server.jar..
File Format[edit | edit source]
When uncompressed, the format of the file is as follows:
|0||4||Magic ID||A magic ID is a constant number used to identify the Minecraft file format. The current value is 0x271bb788.|
|4||1||Version Number||The version number represents the current format used to save the level. The current value is 2.|
|5||Variable||Serialized Java com.mojang.minecraft.level.Level Class||More information about the serialization format used by Java is available in the manual, however, the easiest way to edit the file is to use the classes provided here with the official .|
Accessing the array of bytes[edit | edit source]
The most interesting part of a level is the block array. Each byte in this array defines a block type at a corresponding location in the world. One generally has two options for accessing the byte array of blocks:
You could deserialize the compressed .dat file directly back into an instance of a Level object inside of Java, thus having access to the instance of the Level object in exactly the same way the Minecraft Server does. This would allow you to set the blocks, dimensions, spawn point and other aspects of the map directly by calling the methods on the instantiated Level object. Manual decompression is not needed before loading, because Java can compress and decompress gzipped files on the fly. To load the datafile back into an instance of the Level class, you would need the class definition for the Level class. This is included with the minecraft-server.jar file. An example of this can be seen in the creation and saving class.
Others have read and modified the map's data by simply accessing the raw byte array in the datafile file. To do this, you would decompress it, make changes to the bytes where the byte array is stored, and then compress it again. Since you are editing it raw, you must keep the first 344 (14E in HEX) bytes intact. The next 256x256x64 bytes are where the byte array is stored. Additionally, it is also possible to alter the spawn location coordinates this way if you know where to look: there are 3 integer values starting at byte 284 and thus overwriting the next 12 bytes (3 integers) will allow you to change the spawn location.
(Disclaimer: This is liable to change as Java changes)