Skip to content

Instantly share code, notes, and snippets.

@JCThePants
Last active April 18, 2018 16:05
Show Gist options
  • Save JCThePants/a614dddfb82bb1f51b60 to your computer and use it in GitHub Desktop.
Save JCThePants/a614dddfb82bb1f51b60 to your computer and use it in GitHub Desktop.
Minecraft 1.8.1 chunk packet data format notes from looking at Minecraft 1.8 source. (net.minecraft.server.PacketPlayOutMapChunk)
16 chunk sections in a chunk. A chunk is 16x256x16 (x y z) blocks. A chunk section is 16x16x16 blocks.
--------------------------------------------------
Chunk:
Section:
Block Data: 2 bytes per block. 8192 bytes. format: blockId << 4 | meta
Emitted Light: 4 bits per block (1/2 byte). 2048 bytes
Skylight: 4 bits per block (1/2 byte). 2048 bytes (only included in overworld)
Biome: 1 byte per block column. 256 bytes. (only included if all sections are in chunk)
--------------------------------------------------
A section mask is used to determine which sections are included in the data. Sections of the chunk that have no blocks (all air blocks) do not get sent with the packet.
--------------------------------------------------
Illustration of data layout with only 3 chunk sections included:
-------
- Block Data section 1 (8192 bytes)
- Block Data section 2 (8192 bytes)
- Block Data section 3 (8192 bytes)
-------
- Emitted Light section 1 (2048 bytes)
- Emitted Light section 2 (2048 bytes)
- Emitted Light section 3 (2048 bytes)
-------
- Skylight Light section 1 (2048 bytes) (Excluded from nether chunks)
- Skylight Light section 2 (2048 bytes) (Excluded from nether chunks)
- Skylight Light section 3 (2048 bytes) (Excluded from nether chunks)
-------
- Biome (256 bytes) (Included for illustration, would not be in data unless all 16 sections are in data)
-------
@wingerse
Copy link

wingerse commented Apr 18, 2018

This is confusing. Shouldn't the data layout be:

--------
- Block Data section 1
- Emitted light section 1
- Skylight light section 1
--------
repeat for each chunk section
--------
- Biome
--------

?

EDIT: Nvm, you are right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment