Server level.dat

server_level.dat is the name of the file used by the Minecraft Classic server for loading and saving the in-game map. The file can be backed up to save content which helps to protect constructions against griefers or to use the file for map editing.

General information
The file is compressed using gzip to save space (as the files can end up being reasonably large due to everything, even air being considered a block).

(Note: in this example, a default server_level.dat is being used, with the size of 256×256×64. Level files with bigger dimensions may differ in the amount of bytes.)

The server level.dat file is where the Minecraft Server dumps the level information for permanent storage. As this file is primarily raw level data, it can be quite large: a regular 256×256×64 sized level is 4 megabytes in size. The file is compressed using gzip, however. Most of the block values are 0 (empty space), so, therefore, the size is reduced considerably by the compression, usually down to a few hundred kilobytes.

After un-gzipping the datafile (the player may simply decompress the file itself using a tool, which can decompress gzipped files), sequentially the datafile consists of the number 656127880 as 32-bit integer (0x27 0x1B 0xB7 0x88 in HEX), followed by the number 2 as a byte (0x02 in HEX), then followed by serialized Level Java classfile instance. The level's block values (material type, such as stone) are stored inside of a byte array inside of this class.

The first 65536 sequential bytes of the array make up the top-most 256×256 "sliver" of the level, with the north-most row of bytes, from left to right, being at locations 0 ... 255, the row below that at, from left to right, locations 256 ... 511, and so on. The default maps are 64 "slivers" deep.

File format
When uncompressed, the format of the file is as follows:

Accessing the array of bytes
One generally has two options for accessing the byte array of blocks:

The player 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 the player 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, the player 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, the player would decompress it, make changes to the bytes where the byte array is stored, and then compress it again. Since the player is editing it raw, the player must keep the first 344 (14E in HEX) bytes intact. The next 256×256×64 bytes are where the byte array is stored. Additionally, it is also possible to alter the spawn location coordinates this way if the player knows where to look: there are 3 integer values starting at byte 284 and thus overwriting the next 12 bytes (3 integers) allow the player to change the spawn location.

server level.dat