Chunk format

Chunks store the terrain and entities within a 16×256×16 area. They also store precomputed lighting, heightmap data for Minecraft's performance, and other meta information.

NBT structure
Chunks are stored as tags in regional Minecraft Anvil files, which are named in the form r.x.z.mca. They are stored in NBT format, with the following structure (see Block Format for the ordering of the blocks within each array):
 * The root tag.
 * Version of the chunk NBT structure.
 * : Chunk data.
 * X position of the chunk.
 * : Z position of the chunk.
 * : Tick when the chunk was last saved.
 * : The cumulative number of ticks players have been in this chunk. Note that this value increases faster when more players are in the chunk. Used for regional difficulty: increases the chances of mobs spawning with equipment, the chances of that equipment having enchantments, the chances of spiders having potion effects, the chances of mobs having the ability to pick up dropped items, and the chances of zombies having the ability to spawn other zombies when attacked. Note that at values 3600000 and above, regional difficulty is effectively maxed for this chunk. At values 0 and below, the difficulty is capped to a minimum (thus, if this is set to a negative number, it behaves identically to being set to 0, apart from taking time to build back up to the positives). See Regional Difficulty for more specifics.
 * : May not exist. 1024 entries of biome data. Each number in the array is the biome for a 4x4x4 volume in the chunk. These 4×4×4 volumes are arranged by X, then Z, then Y. That is, the first 4×4 values in the array are for the 16×16 chunk, at Y levels 0–3, the next 4×4 is for Y levels 4–7, etc. See for biome IDs. If this tag does not exist, it gets created and filled by Minecraft when the chunk is loaded and saved. If any values in this array correspond to an unknown biome, Minecraft also sets them to the biome that would normally generate in that location
 * : Several different heightmaps corresponding to 256 values compacted at 9 bits per value (lowest being 0, highest being 256, both values inclusive). The 9 bit values are stored in an array of 37 longs, each containing 7 values (long = 64 bits, 7 * 9 = 63; the last bit is unused). In versions prior to 1.16 the heightmaps were stored in 36 long values, where the bits were arranged in an uninterrupted "stream" across all values, resulting in all 2304 bits being used.
 * : The highest block that blocks motion or contains a fluid.
 * : The highest block that blocks motion or contains a fluid or is in the  tag.
 * : The highest non-air block, solid block.
 * : The highest block that is neither air nor contains a fluid, for worldgen.
 * : The highest non-air block.
 * : The highest non-air block, for worldgen.
 * A series of bits indicating whether a cave has been dug at a specific position, stored in a byte array.
 * : A series of bits indicating whether an underwater cave has been dug at a specific position, stored in a byte array.
 * : List of Compound tags, each tag is a sub-chunk of sorts.
 * An individual Section.
 * The Y index (not coordinate) of this section. Range 0 to 15 (bottom to top), with no duplicates but some sections may be missing if empty.
 * : Set of different block states used in the chunk.
 * A Block
 * : Namespaced block ID
 * : List of block state properties, with [name] being the name of the block state property
 * : The block state name and it's value.
 * : 2048 bytes recording the amount of block-emitted light in each block. Makes load times faster compared to recomputing at load time. 4 bits per block.
 * : A variable amount of 64-bit longs, enough to fit 4096 indices. The indices correspond to the ordering of elements in the section's Palette. All indices are the same size in a section, which is the size required to represent the largest index (minimum of 4 bits). If the size of each index is not a factor of 64, the highest bits where no block index fits anymore are unused. Since Java Edition uses big-endian, indices inside one long are in reverse order, but the longs themselves are normally ordered. In versions prior to 1.16, the full range of bits is used, where the remaining bits of a block index continue on the next long value. (See Chunk format#Block_format)
 * : 2048 bytes recording the amount of sunlight or moonlight hitting each block. 4 bits per block.
 * : Each TAG_Compound in this list defines an entity in the chunk. See Entity Format below. If this list is empty, it becomes a list of End tags (before 1.10, list of Byte tags).
 * : Each TAG_Compound in this list defines a block entity in the chunk. See Block Entity Format below. If this list is empty, it becomes a list of End tags (before 1.10, list of Byte tags).
 * : Each TAG_Compound in this list is an "active" block in this chunk waiting to be updated. These are used to save the state of redstone machines or falling sand, and other activity. See Tile Tick Format below.
 * : Each TAG_Compound in this list is an "active" liquid in this chunk waiting to be updated.
 * : A List of 16 lists that store positions of light sources per chunk section during world generation as shorts.
 * : A List of 16 TAG_Lists that store positions of "active" liquids that need to be ticked, packed in TAG_Shorts.
 * : A List of 16 TAG_Lists that store positions of "active" blocks that need to be ticked, packed in TAG_Shorts.
 * : A List of 16 TAG_Lists that store positions of blocks that need to receive an update when a proto-chunk turns into a full chunk., packed in TAG_Shorts.
 * Defines the world generation status of this chunk. It is always one of the following: empty, structure_starts, structure_references, biomes, noise, surface, carvers, liquid_carvers, features, light, spawn, heightmaps or full.
 * : Structure data in this chunk.
 * : Coordinates of chunks that contain Starts.
 * : Each 64-bit number of this array represents a chunk coordinate (i.e. block coordinate / 16), with its X packed into the low (least significant) 32 bits and Z packed into the high (most significant) 32 bits.
 * : Structures that are yet to be generated, stored by general type. Some parts of the structures may have already been generated. Completely generated structures are removed by setting their id to "INVALID" and removing all other tags.
 * : Only the structures that can spawn in this dimension are stored, for example, EndCity is stored only in the end chunks.
 * : Chunk X coordinate of the start of the structure. Absent if id is INVALID.
 * : Chunk Z coordinate of the start of the structure. Absent if id is INVALID.
 * : If there's no structure of this kind in this chunk, this value is "INVALID", else it's the structure name.
 * : The biome id this structure is in. Absent if id is INVALID.
 * : Bounding box of the entire structure (remaining Children). Value is 6 ints: the minimum X, Y, and Z coordinates followed by the maximum X, Y, and Z coordinates. Absent if id is INVALID.
 * : 1 or 0 (true/false) - (Village only) Whether the village generated at least 3 non-roads. Absent if id is INVALID.
 * : (Monument only) List of chunks that have had their piece of the structure created. Absent if id is INVALID.
 * : A chunk.
 * : The chunk's X position (chunk coordinates, not block coordinates).
 * : The chunk's Z position.
 * : List of structure pieces making up this structure, that were not generated yet. Absent if id is INVALID.
 * Structure piece data.
 * : Identifier for the structure piece. Typically a heavily abbreviated code rather than something human-readable.
 * : Rotation of ocean ruins and shipwrecks. Valid values are COUNTERCLOCKWISE_90, NONE, CLOCKWISE_90, and CLOCKWISE_180.
 * : The ocean temperature this ocean ruins is in. Valid values are WARM and COLD.
 * : The template of the ocean ruin or shipwreck that was used.
 * : The integrity of this structure (only used by ocean ruins).
 * : The X coordinate origin of this ocean ruin or shipwreck.
 * : The Y coordinate origin of this ocean ruin or shipwreck.
 * : The Z coordinate origin of this ocean ruin or shipwreck.
 * : The X coordinate origin of this village part.
 * : The Y coordinate origin of this village part.
 * : The Z coordinate origin of this village part.
 * : 1 or 0 (true/false) - If this ocean ruin is big.
 * : Appears to be some sort of measure of how far this piece is from the start.
 * : Likely orientation of the structure piece.
 * : Bounding box of the structure piece. (Does not include the part of a village roof that can overhang the road.) Value is 6 ints: the minimum X, Y, and Z coordinates followed by the maximum X, Y, and Z coordinates.
 * : (Temples and huts) Width of the structure (X/Z).
 * : (Temples and huts) Height of the structure (Y).
 * : (Temples and huts) Depth of the structure (X/Z).
 * : (Temples and huts) Y level the structure was moved to in order to place it on the surface, or -1 if it hasn't been moved yet.
 * : 1 or 0 (true/false) - (Jungle temple) Whether the hallway arrow trap dispenser was placed.
 * : 1 or 0 (true/false) - (Jungle temple) Whether the chest arrow trap dispenser was placed.
 * : 1 or 0 (true/false) - (Jungle temple) Whether the main chest was placed.
 * : 1 or 0 (true/false) - (Jungle temple) Whether the hidden chest was placed.
 * : 1 or 0 (true/false) - (Desert temple) Whether chest was placed.
 * : 1 or 0 (true/false) - (Desert temple) Whether chest was placed.
 * : 1 or 0 (true/false) - (Desert temple) Whether chest was placed.
 * : 1 or 0 (true/false) - (Desert temple) Whether chest was placed.
 * : 1 or 0 (true/false) - (Witch hut) Whether the initial witch has been spawned for the hut.
 * : 1 or 0 (true/false) - (Mineshaft "MSCorridor") Whether the corridor has rails.
 * : 1 or 0 (true/false) - (Mineshaft "MSCorridor") Whether the corridor has cobwebs.
 * : 1 or 0 (true/false) - (Mineshaft "MSCorridor") Whether the corridor has a cave spider spawner.
 * : (Mineshaft "MSCorridor") Corridor length.
 * : 1 or 0 (true/false) - (Mineshaft "MSCrossing") Whether the crossing is two floors tall.
 * : (Mineshaft "MSCrossing") Indicates the "incoming" direction for the crossing.
 * : (Mineshaft "MSRoom") List of exits from the room.
 * : Bounding box of the exit.
 * : 1 or 0 (true/false) - (Fortress "NeSCLT" and "NeSCRT") Whether this fortress piece should contain a chest but hasn't had one generated yet. (Stronghold "SHCC") Whether this chest in this stronghold piece was placed. (Village "ViS") Whether the blacksmith chest has been generated.
 * : 1 or 0 (true/false) - (Fortress "NeMT") Whether this fortress piece should contain a Blaze spawner but hasn't had one generated yet. (Stronghold "SHPR") Whether the Silverfish spawner has been placed in this piece.
 * : (Fortress "NeBEF") Random seed for the broken-bridge fortress piece.
 * : (Stronghold) The type of door at the entry to this piece.
 * : (Stronghold "SHFC") Length of the corridor
 * : 1 or 0 (true/false) - (Stronghold "SH5C") Whether the 5-way crossing has an exit on the lower level on the side with the upward staircase.
 * : 1 or 0 (true/false) - (Stronghold "SH5C") Whether the 5-way crossing has an exit on the lower level on the side with the downward staircase.
 * : 1 or 0 (true/false) - (Stronghold "SH5C") Whether the 5-way crossing has an exit on the upper level on the side with the upward staircase.
 * : 1 or 0 (true/false) - (Stronghold "SH5C") Whether the 5-way crossing has an exit on the upper level on the side with the downward staircase.
 * : 1 or 0 (true/false) - (Stronghold "SHLi") Whether the library has an upper level.
 * : (Stronghold "SHRC") Indicates whether the room contains a pillar with torches, a fountain, an upper level with a chest, or is just empty room.
 * : 1 or 0 (true/false) - (Stronghold "SHSD") Whether the spiral staircase is the source of the Stronghold or was randomly generated.
 * : 1 or 0 (true/false) - (Stronghold "SHS") Whether the corridor has an opening on the left.
 * : 1 or 0 (true/false) - (Stronghold "SHS") Whether the corridor has an opening on the right.
 * : (Village) Village type: 0=plains, 1=desert, 2=savanna, 3=taiga.
 * : 1 or 0 (true/false) - (Village) Whether this village generated as a zombie village.
 * : (Village) Count of villagers spawned along with this piece.
 * : (Village) Y level the piece was moved to in order to place it on the surface, or -1 if it hasn't been moved yet.
 * : (Village "ViF" and "ViDF") Crop in the farm plot.
 * : Namespaced block ID
 * : List of block state properties, with [name] being the name of the block state property
 * : The block state name and its value.
 * : (Village "ViF" and "ViDF") Crop in the farm plot.
 * : Namespaced block ID
 * : List of block state properties, with [name] being the name of the block state property
 * : The block state name and its value.
 * : (Village "ViDF") Crop in the farm plot.
 * : Namespaced block ID
 * : List of block state properties, with [name] being the name of the block state property
 * : The block state name and its value.
 * : (Village "ViDF") Crop in the farm plot.
 * : Namespaced block ID
 * : List of block state properties, with [name] being the name of the block state property
 * : The block state name and its value.
 * : 1 or 0 (true/false) - (Village "ViSH") Whether the house has a ladder to the roof and fencing.
 * : (Village "ViSmH") Table: 0 is no table, 1 and 2 place it on either side of the hut.
 * : (Village "ViSmH") Hut roof type.
 * : (Village "ViSR") Length of the road piece.
 * : (Village) List of junction points.
 * : Block coordinate.
 * : Block coordinate.
 * : Block coordinate.
 * : One of  or.
 * : Block coordinate.
 * : One of  or.
 * : One of  or.

Block format
In the Anvil format, block positions are ordered YZX for compression purposes.

The coordinate system is as follows:
 * X increases East, decreases West
 * Y increases upward, decreases downward
 * Z increases South, decreases North

This means indices are ordered like in a book, with its top to the North, read from beneath and with words written backward: each letter is a different X-index, each line a Z-index, and each page a Y-index. In case of a flat 2D array, the Y-index is omitted, and the array reads like a single page.

Each section is a 16×16×16-block area, with up to 16 sections in a chunk : from 0 at the bottom, to 15 on top. Empty sections are not saved. Each section has a "Y" byte for its Y-index (0 to 15), a "Palette" list linking IDs to block states, and a "BlockStates" long array storing the IDs per block location, compressed by fitting multiple IDs inside each entry. There is a 17th section with unknown purpose at index 0 with only a "Y" tag of value 255.

The "BlockLight" byte array is for block light levels. The "SkyLight" byte array stores the maximum sky light that reaches each block, regardless of current time. Each of them are 2048 bytes long, and both are omitted if no light reaches this section of the chunk. Light level is stored as 4 bits per block, 2 blocks sharing a byte : starting at 0, even blocks take the first nibble, and odd blocks the second one. This is the only known instance of small-endian data storage in Java Edition.

The pseudo-code below shows how to access individual block information from a single section. Hover over text to see additional information or comments.

 byte Nibble4( byte [] arr, int index) { return index%2 == 0 ? arr[index/2]&0x0F : (arr[index/2]>>4)&0x0F ; } int BlockPos  = y *16 *16 + z*16 + x; compound Block = Palette[change_array_element_size (BlockStates,Log2(length (Palette)))[BlockPos]] string BlockName = Block.Name; compound BlockState = Block.Properties; byte Blocklight = Nibble4(BlockLight, BlockPos); byte <abbr title="The sky light for the block">Skylight = Nibble4(<abbr title="The SkyLight byte array, 4 bits per block">SkyLight, BlockPos);

Entity format
Every entity is an unnamed contained in the Entities list of a chunk file. The sole exception is the Player entity, stored in level.dat, or in .dat files on servers. All entities share this base:
 * Entity data

Mobs
Mobs are a subclass of Entity with additional tags to store their health, attacking/damaged state, potion effects, and more depending on the mob. Players are a subclass of Mob.

Projectiles
Projectiles are a subclass of Entity.

Items and XP Orbs
Items and XPOrbs are a subclass of Entity.

Vehicles
Vehicles are subclasses of Entity.

Dynamic tiles
Dynamic tiles are a subclass of Entity and are used to simulate realistically moving blocks.

Other
Other entity types that are a subclass of Entity but do not fit into any of the above categories.

Block entity format
A block entity (not related to entity) is used by Minecraft to store information about a block that can't be stored in the block's block states. Block entities were called "tile entities" until the 1.8 snapshots and that term is still used in some command usage.

Tile tick format
Tile Ticks represent block updates that need to happen because they could not happen before the chunk was saved. Examples reasons for tile ticks include redstone circuits needing to continue updating, water and lava that should continue flowing, recently placed sand or gravel that should fall, etc. Tile ticks are not used for purposes such as leaf decay, where the decay information is stored in the leaf block data values and handled by Minecraft when the chunk loads. For map makers, tile ticks can be used to update blocks after a period of time has passed with the chunk loaded into memory.


 * A Tile Tick

History
Chunks were first introduced in Java Edition Infdev. Before the addition of the MCRegion format in Beta 1.3, chunks were stored as individual chunk files ".dat" where the file names contained the chunk's position encoded in Base36 - this is known as the Java Edition Alpha level format. MCRegion changed this by storing groups of 32×32 chunks in individual ".mcr" files with the coordinates in Base10, with the goal being to reduce disk usage by cutting down on the number of file handles Minecraft had open at once. MCRegion's successor is the current format, Anvil, which made changes only to the chunk format. The region file technique is still used, but the region file extensions are ".mca" instead.

The major change from MCRegion to Anvil was the division of Chunks into Sections; each chunk has up to 16 individual 16×16×16 block Sections so that completely empty sections are not saved at all. Preparation has also been made to support blocks with IDs in the range 0 to 4095, as compared to the previous 0 to 255 limitation. However, Minecraft is not fully prepared for such blocks to exist as items; many item IDs are already taken in the range 256 to 4095.

The Blocks, Data, BlockLight, and SkyLight arrays are now housed in individual chunk Sections. The Data, SkyLight, and BlockLight are arrays of 4-bit values, and the BlockLight and SkyLight arrays no longer house part of the block ID. The Blocks array is 8 bits per block, and the 4096-blocks support exists in the form of an optional Add byte array of 4-bits per block for additional block ID information. With the Anvil format, the NBT Format was changed from Notch's original specification to include an integer array tag similar to the existing byte array tag. It is currently used only for HeightMap information in chunks.