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 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.

Dimensions
Dimensions are saved in the same way normal worlds are, but instead of mixing the world files inside the save folder, the files are stored in an additional sub-folders with their own region and chunk data. Their names start with, followed by the dimension ID.

These dimension IDs are known so far:

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/night cycle, making the full cycle length 20 minutes. 0 is the start of daytime, 12000 is the start of sunset, 13800 is the start of nighttime, 22200 is the start of sunrise, and 24000 is daytime 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. The maximum durability of the tool (for example, 33 for golden tools) means undamaged. When the Damage reaches 0, 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_Compound("tag")
 * TAG_List("ench"): Contains enchantments for this item.
 * Tag_Compound: One of these for each enchantment.
 * TAG_Short("id"): Id of the Enchantment.
 * TAG_Short("lvl"): Level of the Enchantment
 * TAG_Compound("abilities"): Determines the player's capabilities. Added in Beta 1.9-Pre5
 * TAG_Byte("flying"): Supposed to be set when the player is flying. Appears to be ignored by the game upon loading anyway. Set to 1 on creative mode, 0 on survival.  Added in Beta 1.9-Pre5
 * TAG_Byte("instabuild"): No effect? Set to 1 on creative mode, 0 on survival.  Added in Beta 1.9-Pre5
 * TAG_Byte("mayfly"): Determines whether the player can fly. Set to 1 on creative mode, 0 on survival.  Added in Beta 1.9-Pre5
 * TAG_Byte("invulnerable"): Whether the player is invulnerable. Set to 1 on creative mode, 0 on survival.  Added in Beta 1.9-Pre5
 * TAG_Int("Score"): Current score, doesn't appear to be implemented yet. Always 0. This tag exists only in SSP.
 * TAG_Int("Dimension"): Which dimension the player is in. 0 is the Overworld, -1 is the Nether, and 1 is the End.
 * 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. Added in version Beta 1.3.
 * TAG_String("LevelName"): Specifies the name of the level. Added in version Beta 1.3.
 * TAG_Byte("raining"): 1 or 0(true/false). Raining. Added in version Beta 1.5.
 * 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. Added in version Beta 1.5.
 * 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. Added in version Beta 1.5.
 * TAG_Int("thunderTime"): Similar countdown timer for the next true/false "thundering" field change. Added in version Beta 1.5.
 * TAG_Int("GameType"): Whether in survival (0) or in creative (1) mode. Added in version Beta 1.8 pre-release 1.
 * TAG_Byte("MapFeatures"): Whether structures (dungeons, mob villages, etc.) will be generated. Added in version Beta 1.8 pre-release 1.
 * TAG_Byte("hardcore"): Whether the map should be locked in hardcore mode. This can be set to 0 or 1 to toggle the state of a map, even after it is created.
 * TAG_String("generatorName"): Name of the level generator to use. Currently, "FLAT" and "DEFAULT" are supported.

= See Also =
 * Chunk format
 * Region file format

Format de carte Alpha