Minecraft Wiki
Advertisement

server_level.dat

(Note: in this example, a default server_level.dat is being used, with the size of 256x256x64. Level files with bigger dimensions may differ in 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 256x256x64 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 (you 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 x 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.

Accessing the array of bytes

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 the exact 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. Addtionally, 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)

Blocks and Values

This is a list of all the blocks and values used.

dec hex Block type
0 00 Air
1 01 Stone
2 02 Grass
3 03 Dirt
4 04 Cobblestone
5 05 Wood
6 06 Plant (Decorations)
7 07 Bedrock (Adminium)
8 08 Water
9 09 Still water
dec hex Block type
10 0A Lava
11 0B Still lava
12 0C Sand
13 0D Gravel
14 0E Gold (Ore)
15 0F Iron (Ore)
16 10 Coal
17 11 Tree
18 12 Leaves
19 13 Sponge
dec hex Block type
20 14 Glass
21 15 Red (Cloth)
22 16 Orange (Cloth)
23 17 Yellow (Cloth)
24 18 Light green (Cloth)
25 19 Green (Cloth)
26 1A Aqua green (Cloth)
27 1B Cyan (Cloth)
28 1C Blue (Cloth)
29 1D Purple (Cloth)
dec hex Block type
30 1E Indigo (Cloth)
31 1F Violet (Cloth)
32 20 Magenta (Cloth)
33 21 Pink (Cloth)
34 22 Black (Cloth)
35 23 Gray (Cloth)
36 24 White (Cloth)
37 25 Yellow flower (Decorations)
38 26 Red Flower (Decorations)
39 27 Brown Mushroom
dec hex Block type
40 28 Red Mushroom
41 29 Gold (Block)
42 2A Iron (Block)
43 2B Double Stair
44 2C Stair
45 2D Brick
46 2E TNT
47 2F Bookcase
48 30 Mossy Cobblestone
49 31 Obsidian
dec hex Block type
50 32 Torch
51 33 Fire
Advertisement