Map Format

From wiki.vg
Revision as of 20:55, 27 March 2012 by SirCmpwn (talk | contribs)
Jump to navigation Jump to search

This page covers the world information as of 1.2.4. See Alpha Map Format for Alpha information.

General Information

Worlds are represented as a series of regions, within which are a number of columns, and chunks. Each region is 32x1x32 columns, each column is 1x16x1 chunks, and each chunk is 16x16x16 blocks. The overall block height of a column is 256. Each chunk stores four (or five) things - block IDs (8-bit), block metadata (4-bit), block light (4-bit), and sky light (4-bit). The optional fifth value is "add" data, which is four bits to be added to block IDs for additional block ID support (not used in vanilla Minecraft). Block light is light cast by things like torches and glowstone, and is calculated with a 3D Flood Fill algorithm. Sky light is the light cast by the sky, and is calculated by starting at the top and working your way down. As you pass through semi-transparent blocks, you decrease the lighting value until you hit an opaque block. The opaque block is the last block whose skylight has a nonzero value. Lighting starts at 0xF (brightest) and works down to 0x0 (dimmest). Columns store biome information. Each 1x256x1 cuboid of blocks has the same biome value, for a total of 256 possible biome values per chunk (16x16). Biome values are stored as bytes.

Biome Values

Name Value
Ocean 0
Plains 1
Desert 2
Extreme Hills 3
Forest 4
Taiga 5
Swampland 6
River 7
Hell 8
Sky 9
Frozen Ocean 10
Frozen River 11
Ice Plains 12
Ice Mountains 13
Mushroom Island 14
Mushroom Island Shore 15
Beach 16
Desert Hills 17
Forest Hills 18
Taiga Hills 19
Extreme Hills Edge 20
Jungle 21
Jungle Hills 22

Protocol

Here is a dump of 1.2.4 world-related packets.

Here and here is the relevant documentation.

For sending map packets to a client, all of the above information is required. Even though lighting is sent to the client, the vanilla client will calculate lighting itself. For distant areas, the client's value is used. For the immediate surroundings, the value provided by the server is used. If a custom server has not properly implemented lighting yet, setting all block light and sky light values to 0xF will not cause client lag, where other values are likely to cause significant lag.

The map is sent a column at a time. Initialize each column with a map column allocation packet (0x32) The entire column need not be sent; only the chunks that are not completely air are actually sent. If your column is representative of all chunks from Y=0 to Y=255, you should set "ground-up continuous" to true. This holds true even if you omit several packets because they are completely air. If you omit chunks that are not completely air, set this value to false.

The chunks that you do choose to send are specified via the primay bit-map. You specify chunks from the bottom up, starting at Y=0. The primary bit-map's first bit (representing the lowermost chunk) is the least significant bit. This assumes that you use little-endian and reverse the endianness when sending the value to a client. The add bit-map is the same, but you should only include it for chunks whose block IDs require the additional information.

What follows the bit-maps is compressed data. First, an integer representing the total size of the compressed data, followed by an unused int. The compressed data is a concatenated array of raw chunk data, followed by biome data. For each chunk included in the primary bit-map, concat the following information into a byte array:

  • Block type array (1 byte per block, 4096 bytes per chunk)
  • Block metadata array (half byte per block, 2048 bytes per chunk)
  • Block light array (half byte per block, 2048 bytes per chunk)
  • Sky light array (half byte per block, 2048 bytes per chunk)
  • Add array (half byte per block, 2048 bytes per chunk)

Only include the add array if that particular chunk is represented in the add bit-map. After all the chunks have been concatenated in this manner, and if ground-up continuous is set to true, concat the biome array.

Storage