Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minecraft How are Chunk Sections stored

I am currently making a Minecraft chunk manipulation program, and I would like to know how Minecraft chunk sections are stored.

From the Minecraft Wiki Article on how Minecraft Stores its chunks.

Sections: List of Compound tags, each tag is a sub-chunk of sorts.

An individual Section.

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

Blocks: 4096 bytes of block IDs defining the terrain. 8 bits per block, plus ? the bits from the below Add tag.

Add: May not exist. 2048 bytes of additional block ID data. The value to add to (combine with) the above block ID to form the true block ID in the range 0 to 4095. 4 bits per block. Combining is done by shifting this value to the left 8 bits and then adding it to the block ID from above.

Data: 2048 bytes of block data additionally defining parts of the terrain. 4 bits per block.

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

SkyLight: 2048 bytes recording the amount of sunlight or moonlight hitting each block. 4 bits per block.

But I do not understand how Blocks is read. Every Section in a Chunk is 16 x 16 x 16 blocks. But instead Minecraft stores the blocks in a section in a 1-d array.

like image 504
frogocomics Avatar asked Oct 14 '25 18:10

frogocomics


1 Answers

A 3D array is also stored linear in RAM. You need to convert coordinates to an index. For the "Blocks" Tag its this formula:

Index = Ycoord * 256 + Zcoord * 16 + Xcoord

This is called YZX-order. The tags "HeightMap" or "Biomes" use ZX-order (Index = Zcoord * 16 + X)

like image 146
Mystery Avatar answered Oct 18 '25 03:10

Mystery



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!