Java Edition Alpha level format

Minecraft infdev introduced a new data storage challenge while under development: Terrain generated in infdev has the potential to be almost 235 petabytes, which is 240,640 terabytes, in size when stored in memory, due to the sheer size of the map (several times the surface area of the Earth). Therefore, to reduce file size and memory usage, Notch decided to split the terrain into 16 x 16 x 128 chunks and store them on disk when not visible. In addition, terrain is only generated when it is within the drawing distance of the player's camera, significantly reducing save size, since most players will only be able to search a tiny fraction of the map in a reasonable time frame.

= World folder structure =

An infdev level is actually a single folder containing at least one file named level.dat. The folder may also contain level.dat_old, a backup of level.dat. There is also a session.lock file to make sure only one Minecraft opens the world at once.

The world folder may have up to 64 subfolders, each with up to 64 additional subfolders each. These folders contain the chunk files that hold the world's terrain and entities. Each chunk file is identified by its chunk position xPos and zPos. The varying parts of the chunk file's name are obtained by taking the base36 representation of the xPos and zPos. The names of the folders that the chunk file is placed in are found by taking xPos and zPos, modulo 64 (or bitwise ANDing with 63), and converting to base36. Negative coordinates must be interpreted as positive numbers, bitwise, via two's complement. So, -13 is treated as 243 (if its size is a byte).

As an example, to find the chunk at position (-13, 44):

* The first folder name is base36(-13 % 64). This is base36(243 % 64 = 51) which is "1f". * The second folder name is base36(44 % 64). This is base36(44) which is "18". * The chunk file's name is "c." + base36(-13) + "." + base36(44) + ".dat". This evaluates to "c.-d.18.dat" * Thus, the chunk at (-13, 44) is stored in "1f/18/c.-d.18.dat"

Each chunk remembers its position independently of the file and folder names. See Chunk File Format to find out how to read a chunk's position from the file data.

As of Beta 1.3, this scheme has been replaced by chunks grouped in region files.

The Nether
Since the Halloween Update, as soon as the player first enters The Nether, chunks belonging to this dimension are stored in an additional subfolder DIM-1. Here the Nether chunks are saved as described above, for example DIM-1/1f/1e/c.-d.-e.dat.

session.lock Format
session.lock contains the timestamp of when the world was last touched. The file is eight bytes long, and contains a single 64-bit signed integer in big endian format. The value of this integer is the timestamp, stored as the number of milliseconds elapsed since 1970, in UTC.

Unlike typical lock files, session.lock ensures that the LAST program to open a world is that one that owns it. The process goes something like this:


 * 1) program opens session.lock
 * 2) program writes timestamp to session.lock
 * 3) program monitors session.lock for changes
 * 4) if the contents of session.lock change, program aborts and gives up its lock on the world.

level.dat Format
level.dat is a GZipped NBT file that stores environmental data (time of day, for example) and player health, inventory, velocity, and position within the map. Most importantly, it stores the Random Seed that the terrain generator uses to seamlessly generate more terrain on the fly.

The world folder may also contain a second file, level.dat_old, a backup of level.dat.

NBT Structure
The structure of the file is as follows:


 * TAG_Compound("Data"): World data.
 * TAG_Long("Time"): Stores the current "time of day" in ticks. There are 20 ticks per real-life second, and 24000 ticks per Minecraft day, making the day length 20 minutes. 0 appears to be sunrise, 12000 sunset and 24000 sunrise again. The value stored in level.dat is always increasing and can be larger than 24000, but the "time of day" is always modulo 24000 of the "Time" field value.
 * TAG_Long("LastPlayed"): Stores the Unix time stamp (in milliseconds) when the player saved the game.
 * TAG_Compound("Player"): Player entity information. See Entity Format and Mob Entity Format for details. Has additional elements:
 * TAG_List("Inventory"): Each TAG_Compound in this list defines an item the player is carrying, holding, or wearing as armor.
 * TAG_Compound: Inventory item data
 * TAG_Short("id"): Item or Block ID.
 * TAG_Short("Damage"): The amount of wear each item has suffered. 0 means undamaged. When the Damage exceeds the item's durability, it breaks and disappears. Only tools and armor accumulate damage normally.
 * TAG_Byte("Count"): Number of items stacked in this inventory slot. Any item can be stacked, including tools, armor, and vehicles. Range is 1-255. Values above 127 are not displayed in-game.
 * TAG_Byte("Slot"): Indicates which inventory slot this item is in.
 * TAG_Int("Score"): Current score, doesn't appear to be implemented yet. Always 0.
 * TAG_Int("Dimension"): Which dimension the player is in. 0 is the overworld, and -1 is the Nether.
 * TAG_Int("SpawnX"): X coordinate of the player's spawn position. Default is 0.
 * TAG_Int("SpawnY"): Y coordinate of the player's spawn position. Default is 64.
 * TAG_Int("SpawnZ"): Z coordinate of the player's spawn position. Default is 0.
 * TAG_Long("SizeOnDisk"): Estimated size of the entire world in bytes.
 * TAG_Long("RandomSeed"): Random number providing the Random Seed for the terrain.
 * TAG_Int("version"): Current version of NBT. When announced: 19132
 * TAG_String("LevelName"): Specifies the name of the level.
 * TAG_Byte("raining"): 1 or 0(true/false). Raining.
 * TAG_Byte("thundering"): 1 or 0(true/false). Thundering. Can be set to 1 while "raining" is 0, in which case it appears to have no effect on the game.
 * TAG_Int("rainTime"): Countdown timer (in ticks) until the next true/false change of the "raining" field. When the timer reaches 0, the "raining" field toggles, and the "rainTime" countdown is reset to a new (presumably random) value.
 * TAG_Int("thunderTime"): Similar countdown timer for the next true/false "thundering" field change.

Chunk File Format
See Alpha Level Format/Chunk File Format.

= See Also =
 * Beta Level Format
 * Map Format (NBT)
 * Infdev