Pocket Minecraft Map Format

This article describes the Chunk format used in the Full Chunk Data (0xbf, clientbound).

Concepts

 * Chunk: a 16×128×16 area, sometimes also called chunk section

Format
A chunk consists of the following fields (fixed size of 83200 bytes):

Blocks
The following definitions are provided to clarify the mapping between the location of a block within a LevelDB entry containing a chunk of 32,768 blocks and the corresponding location of the block within the entire world:


 * Let  and   be the values contained within the LevelDB key.
 * Let  be a three dimensional array of the chunk of 32,768 blocks contained within the LevelDB entry. The first two indices i and j range from 0 to 15, and the third index y ranges from 0 to 127.
 * Let  be a three dimensional array of the blocks contained within the entire world.

For infinite worlds, the first two indices  and   both range over the values of a four byte integer and may be negative as well as positive.

The third index  ranges from 0 to 127 for both old style and infinite worlds.

Assuming the definitions above, the location of a block with a LevelDB entry with key values  and   maps to the corresponding location of the block within the entire world as follows:

let x = 16 * X + i let z = 16 * Z + j C[i, j, y] &lt;-&gt; W[x, z, y]

Skylight/Blocklight/Metadata
Block light and skylight are very similar to the 1.8 implementation used in the Minecraft: PC edition of the game. All chunks always have the same value and have a fixed size of 83200, you can index the skylight/blocklight/metadata by block by using  where x, y, z are the coordinates of the block you are trying to retrieve the skylight/blocklight/metadata for.

Heightmap
The heightmap is the mapping between the height of each block in a chunk for retrieveing by x and z you can simply  to get the value or set it.

Biome colors
Each block in a single column has a biome id and (unlike the PC version of the game) an r, g, b value associated with it that is used for the client to render the color (more like hue) of the block. For finding/setting the biome id for a column of blocks the key for each column is  and the integer that you pack inside the value is   where   and   for getting the id, it is the same but you just reverse it   where. For setting the r, g, b color of each chunk you can do a similar key  and unpack the r, g, b by   and pack it again by getting the correct color.

LevelDB
In the Minecraft: PE application, all chunks are stored in Mojang’s fork of LevelDB (a ZLib compressed LevelDB database) each key follows the same format unless you are using a special key, or a nether key

For an overworld key, it is quite trivial (always 9 bytes long):

For a nether key it is similar, but with an extra byte after Z Coordinate (always 13 bytes long):

The corresponding byte specifier for the type of chunk are:

Tile Entity Data and Entity Data are encoded as NBT, the format of Terrain Data is specified above.

Implementations

 * Mojang’s LevelDB: https://github.com/Mojang/leveldb-mcpe