Region file format

Minecraft Beta 1.3 introduces a new variation on chunk storage: as of Beta 1.3, each 32x32 group of chunks will be stored in a region file, rather than individually. It could be called that a region is a part of a file system where the header is positions for each file and sector is the allocation size. The system is based on McRegion made by Scaevolus whom also made Optimine. There were slight edits where the only significant one where the extra timestamps header.

= Region Files =

Location
Region files are located in a subfolder of the world directory called "region", and have names in the form r.x.z.mcr, where x and z are the region's coordinates.

The coordinates for the region a chunk belongs to can be found by dividing the chunk coordinates by 32 and rounding downwards. For example, the chunk at chunk coordinates x=35, z=-3 can be found in the file region/r.2.-1.mcr

Structure
Region files begin with a 4kb header containing information about which chunks are present in the region file, and where they can be found. The header entry for a chunk at (x, z) (in chunk coordinates) can be found at byte offset 4 * ((x mod 32) + (z mod 32) * 32) in its region file, and there are 1024 entries in the header. Next is a sector of an another 4kb consisting timestamps for each chunk, that can be reached same way as the header. The remainder of the file consists of data for up to 1024 chunks, interspersed with an arbitrary amount of unused space.

Header Entries
Header entries consist of four bytes split into two fields: the first three bytes are a (big-endian) offset in 4KiB sectors from the start of the file, and a remaining byte which gives the length of the chunk (also in 4KiB sectors, rounded up). Chunks will always be less than 1MiB in size. If a chunk isn't present in the region file (e.g. because it hasn't been generated or migrated yet), both fields will be zero.

Timestamps header entries consist of four bytes integer (probably big-endian) telling last modification of sector.

A chunk with an offset of 1 will begin right after the header.

Chunk Data
Chunk data begins with a (big-endian) four-byte length field which indicates the exact length of the remaining chunk data in bytes. The following byte indicates the compression scheme used for chunk data, and the remaining (length-1) bytes are the compressed chunk data.

There are currently two defined compression schemes:

The uncompressed data is in NBT format with the same structure as in alpha; if compressed with compression scheme 1, the compressed data would be the same as the on-disk content of an Alpha chunk file, except that compression scheme 1 is not used in practice.

= Migration and level.dat =

Beta 1.3 will migrate chunks into region files incrementally as they are loaded during play. When all standalone chunk files have been migrated into regions, level.dat will be updated with TAG_Int("version") (note case) set to 19132. Beta 1.3 also introduces a new level name field, TAG_String("LevelName").

The format of level.dat is otherwise unchanged from alpha.

= See Also =


 * Alpha Level Format
 * Alpha Level Format/Chunk File Format
 * Mojang announcement of new region format
 * JahKob writing about the speed
 * Jeb announcing McRegion being used with minor modifications
 * McRegion
 * Scaevolus according McRegion
 * Jeb helping tool-makers
 * RegionFile in Java
 * RegionFileCache in Java