Difference between revisions of "Pre-release protocol"
m (→Tags: id change) |
(→Data types: Position changed) |
||
Line 9: | Line 9: | ||
=== Data types === | === Data types === | ||
− | + | ==== Position ==== | |
+ | |||
+ | 64-bit value split in to three parts | ||
+ | |||
+ | * x: 26 MSBs | ||
+ | * z: 26 {{change|LSBs|middle bits}} | ||
+ | * y: 12 {{change|bits between them|LSBs}} | ||
+ | |||
+ | Encoded as followed: | ||
+ | |||
+ | ((x & 0x3FFFFFF) << 38) | {{change|((y & 0xFFF) << 26) {{!}} (z & 0x3FFFFFF)|((z & 0x3FFFFFF) << 12) {{!}} (y & 0xFFF)}} | ||
+ | |||
+ | And decoded as: | ||
+ | |||
+ | val = read_unsigned_long(); | ||
+ | x = val >> 38; | ||
+ | y = {{change|(val >> 26) & 0xFFF|val & 0xFFF}}; | ||
+ | z = {{change|val << 38 >> 38|(val >> 12) & 0x3FFFFFF}}; | ||
+ | |||
+ | Note: The details of bit shifting are rather language dependent; the above may work in Java but probably won't in other languages without some tweaking. In particular, you will usually receive positive numbers even if the actual coordinates are negative. This can be fixed by adding something like the following: | ||
+ | |||
+ | if x >= 2^25 { x -= 2^26 } | ||
+ | if y >= 2^11 { y -= 2^12 } | ||
+ | if z >= 2^25 { z -= 2^26 } | ||
=== Packets === | === Packets === |
Revision as of 16:31, 26 October 2018
This page documents the changes from the last stable Minecraft release (currently 1.13.2, protocol 404) to the current pre-release (currently 18w43c, protocol 442). Note that this page contains bleeding-edge information that may not be completely or correctly documented.
One who wishes to commandeer the merging of this into Protocol when an update is made must be sure to respect any changes that may have occurred to the respective packets there.
Contents
Data types
Position
64-bit value split in to three parts
- x: 26 MSBs
- z: 26
LSBsmiddle bits - y: 12
bits between themLSBs
Encoded as followed:
((x & 0x3FFFFFF) << 38) |((y & 0xFFF) << 26) | (z & 0x3FFFFFF)((z & 0x3FFFFFF) << 12) | (y & 0xFFF)
And decoded as:
val = read_unsigned_long(); x = val >> 38; y =(val >> 26) & 0xFFFval & 0xFFF; z =val << 38 >> 38(val >> 12) & 0x3FFFFFF;
Note: The details of bit shifting are rather language dependent; the above may work in Java but probably won't in other languages without some tweaking. In particular, you will usually receive positive numbers even if the actual coordinates are negative. This can be fixed by adding something like the following:
if x >= 2^25 { x -= 2^26 } if y >= 2^11 { y -= 2^12 } if z >= 2^25 { z -= 2^26 }
Packets
ID | Packet name | Documentation | |
---|---|---|---|
Handshaking serverbound | |||
0x00 | Handshake | Current | Pre |
Play clientbound | |||
0x22 | Chunk Data | Current | Pre |
0x4E | Entity Sound Effect | Pre | |
Player List Header And Footer | Current | (unchanged) | |
Collect Item | Current | (unchanged) | |
Entity Teleport | Current | (unchanged) | |
Advancements | Current | (unchanged) | |
Entity Properties | Current | (unchanged) | |
Entity Effect | Current | (unchanged) | |
Declare Recipes | Current | (unchanged) | |
Tags | Current | Pre | |
0x57 | Update Light | Pre |
New/modified data types
No changes so far.
Entity Metadata
Mobs
Entity IDs have shifted with the addition of some new mobs.
Block Actions
No changes so far.
Play
Clientbound
Chunk Data
- Main article: Chunk Format
- See also: #Unload Chunk
The server only sends skylight information for chunk pillars in the Overworld, it's up to the client to know in which dimenison the player is currently located. You can also infer this information from the primary bitmask and the amount of uncompressed bytes sent. This packet also sends all block entities in the chunk (though sending them is not required; it is still legal to send them with Update Block Entity later).
Packet ID | State | Bound To | Field Name | Field Type | Notes |
---|---|---|---|---|---|
0x22 | Play | Client | Chunk X | Int | Chunk coordinate (block coordinate divided by 16, rounded down) |
Chunk Z | Int | Chunk coordinate (block coordinate divided by 16, rounded down) | |||
Ground-Up Continuous | Boolean | See Chunk Format | |||
Primary Bit Mask | VarInt | Bitmask with bits set to 1 for every 16×16×16 chunk section whose data is included in Data. The least significant bit represents the chunk section at the bottom of the chunk column (from y=0 to y=15). | |||
Size | VarInt | Size of Data in bytes | |||
Data | Byte array | See data structure in Chunk Format | |||
Number of block entities | VarInt | Number of elements in the following array | |||
Block entities | Array of NBT Tag | All block entities in the chunk. Use the x, y, and z tags in the NBT to determine their positions. |
Data structure
The data section of the packet contains most of the useful data for the chunk.
Field Name | Field Type | Notes |
---|---|---|
Data | Array of Chunk Section | The number of elements in the array is equal to the number of bits set in Primary Bit Mask. Sections are sent bottom-to-top, i.e. the first section, if sent, extends from Y=0 to Y=15. |
Biomes | Optional Int Array | Only sent if Ground-Up Continuous is true; 256 entries if present |
Chunk Section structure
A Chunk Section is defined in terms of other data types. A Chunk Section consists of the following fields:
Field Name | Field Type | Notes |
---|---|---|
Block count | Short | Number of non-air blocks present in the chunk section, for lighting purposes. "Non-air" is defined as any block other than air, cave air, and void air (in particular, note that fluids such as water are still counted). |
Bits Per Block | Unsigned Byte | Determines how many bits are used to encode a block. Note that not all numbers are valid here. |
Palette | Varies | See below for the format. |
Data Array Length | VarInt | Number of longs in the following array |
Data Array | Array of Long | Compacted list of 4096 indices pointing to state IDs in the Palette |
Block Light | Byte Array | Half byte per block |
Sky Light | Optional Byte Array | Only if in the Overworld; half byte per block |
Data Array, Block Light, and Sky Light are is given for each block with increasing x coordinates, within rows of increasing z coordinates, within layers of increasing y coordinates. For the half-byte light arrays, even-indexed items (those with an even x coordinate, starting at 0) are packed into the low bits, odd-indexed into the high bits.
Entity Sound Effect
Plays a sound effect from an entity.
Packet ID | State | Bound To | Field Name | Field Type | Notes |
---|---|---|---|---|---|
0x4E | Play | Client | Sound ID | VarInt | ID of hardcoded sound event (events as of 1.13.2) |
Sound Category | VarInt Enum | The category that this sound will be played from (current categories) | |||
Entity ID | VarInt | ||||
Volume | Float | 1.0 is 100%, capped between 0.0 and 1.0 by Notchian clients | |||
Pitch | Float | Float between 0.5 and 2.0 by Notchian clients |
Tags
Packet ID | State | Bound To | Field Name | Field Type | Notes |
---|---|---|---|---|---|
Play | Client | Block Tags | (See below) | IDs are block IDs | |
Item Tags | (See below) | IDs are item IDs | |||
Fluid Tags | (See below) | IDs are fluid IDs | |||
Entity Tags | (See below) | IDs are entity type IDs |
Update Light
Updates light levels for a chunk.
Packet ID | State | Bound To | Field Name | Field Type | Notes |
---|---|---|---|---|---|
0x57 | Play | Client | Chunk X | VarInt | Chunk coordinate (block coordinate divided by 16, rounded down) |
Chunk Z | VarInt | Chunk coordinate (block coordinate divided by 16, rounded down) | |||
Sky Light Mask | VarInt | Mask containing 18 bits, with the lowest bit corresponding to chunk section -1 (in the void, y=-16 to y=-1) and the highest bit for chunk section 16 (above the world, y=256 to y=271) | |||
Block Light Mask | VarInt | Mask containing 18 bits, with the same order as sky light | |||
Sky Light arrays | Array of arrays of 2048 bytes | There is 1 array for each bit set to true in the sky light mask, starting with the lowest value. Half a byte per light value. | |||
Block Light arrays | Array of arrays of 2048 bytes | There is 1 array for each bit set to true in the block light mask, starting with the lowest value. Half a byte per light value. |
Individual block or sky light arrays are is given for each block with increasing x coordinates, within rows of increasing z coordinates, within layers of increasing y coordinates. Even-indexed items (those with an even x coordinate, starting at 0) are packed into the low bits, odd-indexed into the high bits.
Serverbound
No changes so far.
Handshaking
Clientbound
There are no clientbound packets in the Handshaking state, since the protocol immediately switches to a different state after the client sends the first packet.
Serverbound
Handshake
This causes the server to switch into the target state.
Packet ID | State | Bound To | Field Name | Field Type | Notes |
---|---|---|---|---|---|
0x00 | Handshaking | Server | Protocol Version | VarInt | See protocol version numbers (currently |
Server Address | String | Hostname or IP, e.g. localhost or 127.0.0.1, that was used to connect. The Notchian server does not use this information. | |||
Server Port | Unsigned Short | Default is 25565. The Notchian server does not use this information. | |||
Next State | VarInt Enum | 1 for status, 2 for login |
Status
Clientbound
No changes so far.
Serverbound
No changes so far.
Login
Clientbound
No changes so far.
Serverbound
No changes so far.