Protocol

From wiki.vg
Revision as of 23:27, 22 July 2012 by Shoghicp (talk | contribs) (Undo revision 2512 by Shoghicp (talk) ups!!!!)
Jump to navigation Jump to search

This page presents a dissection of the current stable Minecraft protocol. The current pre-release protocol is documented elsewhere.

Credit goes to the Great Old Ones, and the citizens of #mcdevs who helped by providing packet dumps and insight. If you're having trouble, check out the FAQ. Make sure you check the Data Types page.

Note: While you may use the contents of this page without restriction to create servers, clients, bots, etc… you still need to provide the attribution above if you copy any of the contents of this page for publication elsewhere.

The protocol for Pocket Minecraft is substantially different, and is documented at Pocket Minecraft Protocol.

Additionally, the minecraft server supports two other protocols since beta 1.9pre4, Rcon (for remote administration) and Query (to query server properties). With the default settings, they listen on TCP 25575 and UDP 25565 respectively.

This is a fairly lengthy page, and to make it more readable certain terminology must be understood. Terms used on this page and their definition are provided below.

Definition
Player When used in the singular, Player always refers to the client connected to the server
Entity Entity refers to any item, player, mob, minecart or boat in the world. This definition is subject to change as Notch extends the protocol
EID An EID - or Entity ID - is a unique 4-byte integer used to identify a specific entity
XYZ In this document, the axis names are the same as those used by Notch. Y points upwards, X points South, and Z points West.

Contents

Packets

All packets begin with a single "Packet ID" byte. Listed packet size includes this byte. Packets are either "server to client", "client to server", or both. If not specified, assume that the packet can be sent both ways. There is no "length" field; for variable length packets, you must parse to the end to determine the length.


Keep Alive (0x00)

Two-Way

The server will frequently send out a keep-alive, each containing a random ID. The client must respond with the same packet. The Beta server will disconnect a client if it doesn't receive at least one packet before 1200 in-game ticks, and the Beta client will time out the connection under the same conditions. The client may send packets with Keep-alive ID=0.

Packet ID Field Name Field Type Example Notes
0x00 Keep-alive ID int 957759560 Server-generated random id
Total Size: 5 bytes


Login Request (0x01)

Two-Way

Client to Server

Sent by the client after the handshake to finish logging in. If the version is outdated or any field is invalid, the server will disconnect the client with a kick. If the client is started in offline mode, the player's username will default to Player, making LAN play with more than one player impossible (without authenticating) as the server will prevent multiple users with the same name.

Packet ID Field Name Field Type Example Notes
0x01 Protocol Version int 20 1.2.5's protocol version is 29
Username string TkTech The name of the user attempting to login, max length of 16
Not used string (empty string)
Not used int 0
Not used int 0
Not used byte 0
Not used unsigned byte 0
Not used unsigned byte 0
Total Size: 20 bytes + length of strings

Server to Client

Sent by the server if it accepts the clients login request. If it didn't, it'll send a kick instead.

Max players is used by the client to draw the player list. Setting this value lower than the actual max players, or indeed the number of players online, will only affect the size and number of users displayed. Values above 127 will cause the player list not to be drawn. Values above 60 will cause usernames to overlap and not fit in their bounding boxes.

Packet ID Field Name Field Type Example Notes
0x01 Entity ID int 1298 The Players Entity ID
Not used string (empty string) Not used
Level Type string default default or FLAT; level-type in server.properties
Server mode int 0 0 for survival, 1 for creative
Dimension int 0 -1: The Nether, 0: The Overworld, 1: The End
Difficulty byte 1 0 thru 3 for Peaceful, Easy, Normal, Hard
Not used unsigned byte 0 Only 0 observed from vanilla server, was previously world height
Max players unsigned byte 8 Used by the client to draw the player list
Total Size: 20 bytes + length of strings


Handshake (0x02)

Two-Way

Client to Server

This is the first packet sent by the client and is used for Authentication.

Contains the username of the connecting player, and the server host/port they're connecting to, most likely to allow virtual hosting. (sample python implementation, sample C# implementation)

Packet ID Field Name Field Type Example Notes
0x02 Username and Host string TkTech;localhost:25565 The username of the player attempting to connect, and the host they're connecting to, seperated by a semicolon.
Total Size: 3 bytes + length of string

Server to Client

This is the first packet sent by the server, in response to the client, and is used for Authentication

Packet ID Field Name Field Type Example Notes
0x02 Connection Hash string 2e66f1dc032ab5f0 A unique, per-connection hash, or '-'
Total Size: 3 bytes + length of strings

If connect hash is '-', the server is in offline mode and no name authentication needs to take place. The client will just send a 0x01 straight back, and the server won't perform the similar authentication step.

Otherwise, it contains a randomly generated long as a series of hex digits. For details on what to do with it, see Authentication


Chat Message (0x03)

Two-Way

The default server will check the message to see if it begins with a '/'. If it doesn't, the username of the sender is prepended and sent to all other clients (including the original sender). If it does, the server assumes it to be a command and attempts to process it. A message longer than 100 characters will cause the server to kick the client. This limits the chat message packet length to 103 bytes. Note that this limit does not apply to incoming chat messages as the server may have prepended other information, not limited to, but usually including, a username.

A message longer than 119 characters will cause the server and client to print the message "Received string length longer than maximum allowed (X > 119)", with no side effects.

For more information, see Chat.

Packet ID Field Name Field Type Example Notes
0x03 Message string <Bob> Hello World! User input must be sanitized server-side
Total Size: 3 bytes + length of strings


Time Update (0x04)

Server to Client

Time is based on ticks, where 20 ticks happen every second. There are 24000 ticks in a day, making Minecraft days exactly 20 minutes long.

The time of day is based on the timestamp modulo 24000. 0 is sunrise, 6000 is noon, 12000 is sunset, and 18000 is midnight.

The default SMP server increments the time by 20 every second.

Packet ID Field Name Field Type Example Notes
0x04 Time long 23718728 The world (or region) time, in ticks
Total Size: 9 bytes


Entity Equipment (0x05)

Server to Client

After each "Named Entity Spawn", there will be five of these packets for the equipped item and armor. If there are changes in visible equipment, another one of these is sent.

Packet ID Field Name Field Type Example Notes
0x05 Entity ID int 0x00010643 Named Entity ID
Slot short 4 Equipment slot: 0=held, 1-4=armor slot
Item ID short -1 Equipped item (-1 for empty slot)
Damage short
Total Size: 11 bytes


Spawn Position (0x06)

Server to Client

Sent by the server after login to specify the coordinates of the spawn point (the point at which players spawn at, and which the compass points to). It can be sent at any time to update the point compasses point at.

Packet ID Field Name Field Type Example Notes
0x06 X int 117 Spawn X in block coordinates
Y int 70 Spawn Y in block coordinates
Z int -46 Spawn Z in block coordinates
Total Size: 13 bytes


Use Entity (0x07)

Client to Server

This packet is sent from the client to the server when the client attacks or right-clicks another entity (a player, minecart, etc).

A Notchian server only accepts this packet if the entity being attacked/used is visible without obstruction and within a 4-unit radius of the player's position.

Packet ID Field Name Field Type Example Notes
0x07 User int 1298 The entity of the player (ignored by the server)
Target int 1805 The entity the player is interacting with
Mouse button bool true true when the player is left-clicking and false when right-clicking.
Total Size: 10 bytes


Update Health (0x08)

Server to Client

Sent by the server to update/set the health of the player it is sent to. Added in protocol version 5.

Food saturation acts as a food "overcharge". Food values will not decrease while the saturation is over zero. Players logging in automatically get a saturation of 5.0. Eating food increases the saturation as well as the food bar.

Packet ID Field Name Field Type Example Notes
0x08 Health short 20 0 or less = dead, 20 = full HP
Food short 20 0 - 20
Food Saturation float 5.0 Seems to vary from 0.0 to 5.0 in integer increments
Total Size: 9 bytes


Respawn (0x09)

Two-Way

Sent by the client when the player presses the "Respawn" button after dying. The server then teleports the user to the spawn point, and sends a respawn packet in response. The client will not leave the respawn screen until it receives a respawn packet.

To change the player's dimension (overworld/nether/end), send them a respawn packet with the appropriate dimension, followed by prechunks/chunks for the new dimension, and finally a position and look packet. You do not need to unload chunks, the client will do it automatically.

Packet ID Field Name Field Type Example Notes
0x09 Dimension int 1 -1: The Nether, 0: The Overworld, 1: The End
Difficulty byte 1 0 thru 3 for Peaceful, Easy, Normal, Hard. 1 is always sent c->s
Creative mode byte 1 0 for survival, 1 for creative.
World height short 256 Defaults to 256
Level Type string default See 0x01 login
Total Size: 11 bytes + length of string


Player (0x0A)

Client to Server

This packet is used to indicate whether the player is on ground (walking/swimming), or airborne (jumping/falling).

When dropping from sufficient height, fall damage is applied when this state goes from False to True. The amount of damage applied is based on the point where it last changed from True to False. Note that there are several movement related packets containing this state.

This packet was previously referred to as Flying

Packet ID Field Name Field Type Example Notes
0x0A On Ground bool 1 True if the client is on the ground, False otherwise
Total Size: 2 bytes


Player Position (0x0B)

Client to Server

Updates the players XYZ position on the server. If Stance - Y is less than 0.1 or greater than 1.65, the stance is illegal and the client will be kicked with the message “Illegal Stance”. If the distance between the last known position of the player on the server and the new position set by this packet is greater than 100 units will result in the client being kicked for "You moved too quickly :( (Hacking?)" Also if the absolute number of X or Z is set greater than 3.2E7D the client will be kicked for "Illegal position"


Packet ID Field Name Field Type Example Notes
0x0B X double 102.809 Absolute position
Y double 70.00 Absolute position
Stance double 71.62 Used to modify the players bounding box when going up stairs, crouching, etc…
Z double 68.30 Absolute position
On Ground bool 1

Derived from packet 0x0A

Total Size: 34 bytes


Player Look (0x0C)

Client to Server

The unit circle for yaw

Updates the direction the player is looking in.

Yaw is measured in degrees, and does not follow classical trigonometry rules. The unit circle of yaw on the xz-plane starts at (0, 1) and turns backwards towards (-1, 0), or in other words, it turns clockwise instead of counterclockwise. Additionally, yaw is not clamped to between 0 and 360 degrees; any number is valid, including negative numbers and numbers greater than 360.

Pitch is measured in degrees, where 0 is looking straight ahead, -90 is looking straight up, and 90 is looking straight down.

You can get a unit vector from a given yaw/pitch via:

 x = -cos(pitch) * sin(yaw)
 y = -sin(pitch)
 z =  cos(pitch) * cos(yaw)
Packet ID Field Name Field Type Example Notes
0x0C Yaw float 0.00 Absolute rotation on the X Axis, in degrees
Pitch float 0.00 Absolute rotation on the Y Axis, in degrees
On Ground bool 1

Derived from packet 0x0A

Total Size: 10 bytes


Player Position & Look (0x0D)

Two-Way

A combination of Player Look and Player position.

Client to Server

Packet ID Field Name Field Type Example Notes
0x0D X double 6.5 Absolute position
Y double 65.620000004768372 Absolute position
Stance double 67.240000009536743 Used to modify the players bounding box when going up stairs, crouching, etc…
Z double 7.5 Absolute position
Yaw float 0.0 Absolute rotation on the X Axis
Pitch float 0.0 Absolute rotation on the Y Axis
On Ground bool 0

Derived from packet 0x0A

Total Size: 42 bytes

Server to Client

Packet ID Field Name Field Type Example Notes
0x0D X double 6.5 Absolute position
Stance double 67.240000009536743 Used to modify the players bounding box when going up stairs, crouching, etc…
Y double 65.620000004768372 Absolute position
Z double 7.5 Absolute position
Yaw float 0.0 Absolute rotation on the X Axis
Pitch float 0.0 Absolute rotation on the Y Axis
On Ground bool 0

Derived from packet 0x0A

Total Size: 42 bytes

:!: Note that this packet differs from client Player & Position Look packet - the Stance and Y are sent in a different order.

:!: Stance and Y seems to be the opposite as in the table (from Client to Server = X, Y, Stance, Z, from Server to client = X, Stance, Y, Z) please confirm ! [BackBone`:] The opposite stance<->y confirmed, however the given structs had the server and client struct reversed, which I fixed.

:!: When you connect to the official server, it will push a 0x0D packet. If you do not immediately respond with a 0x0D (or maybe 0x0A-0x0C) packet with similar and valid information, it will have unexpected results, such as map chunks not loading and future 0x0A-0x0D packets being ignored.


Player Digging (0x0E)

Client to Server

Sent when the player mines a block. A Notchian server only accepts digging packets with coordinates within a 6-unit radius of the player's position.

Packet ID Field Name Field Type Example Notes
0x0E Status byte 1 The action the player is taking against the block (see below)
X int 32 Block position
Y byte 64 Block position
Z int 32 Block position
Face byte 3 The face being hit (see below)
Total Size: 12 bytes

Status can (currently) be one of four values:

Meaning Value
Started digging 0
Finished digging 2
Drop item 4
Shoot arrow / finish eating 5

Notchian clients send a 0 (started digging) when they start digging and a 2 (finished digging) once they think they are finished. If digging is aborted, no notice is sent to the server; the client simply does not send a 2 (finished digging).

Status code 4 (drop item) is a special case. In-game, when you use the Drop Item command (keypress 'q'), a dig packet with a status of 4, and all other values set to 0, is sent from client to server.

Status code 5 (shoot arrow / finish eating) is also a special case. The x, y and z fields are all set to 0 like above, with the exception of the face field, which is set to 255.

The face can be one of six values, representing the face being hit:

Value 0 1 2 3 4 5
Offset -Y +Y -Z +Z -X +X

In 1.7.3, when a player opens a door with left click the server receives Packet 0xE+start digging and opens the door.


Player Block Placement (0x0F)

Client to Server

Sent when the player places a block or an item. The coordinates sent in this packet are actually the block being built against, which combined with the direction offset tell you where the block should be placed. This is required to correctly position furnaces, torches, etc…

In 1.7.3, when a player opens a door with right click, the server receives Packet 0xF (block placement, but opens door).

Packet ID Field Name Field Type Example Notes
0x0F X int 32 Block position
Y unsigned byte 64 Block position
Z int 32 Block position
Direction byte 3 The offset to use for block/item placement (see below)
Held item slot
Total Size: 11 bytes + slot data

If the Block/ItemID field is greater than or equal to 0, then the last 2 fields (amount and damage) are read. Otherwise, they are not read. When 'placing' (Or more accurately, using) your empty hand, the client sends -1 as the Block/ItemID

The direction can be one of six values, representing the face the block/item is being placed against:

Value 0 1 2 3 4 5
Offset -Y +Y -Z +Z -X +X

In normal operation (ie placing a block), this packet is sent once, with the values set normally.

This packet has a special case where X, Y, Z, and Direction are all -1. This special packet indicates that the currently held item for the player should have its state updated such as eating food, shooting bows, using buckets, etc.

In a Notchian Beta client, the block or item ID corresponds to whatever the client is currently holding, and the client sends one of these packets any time a right-click is issued on a surface, so no assumptions can be made about the safety of the ID. However, with the implementation of server-side inventory, a Notchian server seems to ignore the item ID, instead operating on server-side inventory information and holding selection.

Special note on using buckets: When using buckets, the Notchian client might send two packets: first a normal and then a special case. The first normal packet is sent when you're looking at a block (e.g. the water you want to scoop up). This normal packet does not appear to do anything with a Notchian server. The second, special case packet appears to perform the action - based on current position/orientation and with a distance check - it appears that buckets can only be used within a radius of 6 units.


Held Item Change (0x10)

Client to Server

Sent when the player changes the slot selection

Packet ID Field Name Field Type Example Notes
0x10 Slot ID short 1 The slot which the player has selected (0-8)
Total Size: 3 bytes


Use Bed (0x11)

Server to Client

This packet tells that a player goes to bed.

The client with the matching Entity ID will go into bed mode.

This Packet is sent to all nearby players including the one sent to bed.

Packet ID Field Name Field Type Example Notes
0x11 Entity ID int 89 Player ID
Unknown byte 0 Only 0 has been observed
X coordinate int -247 Bed headboard X as block coordinate
Y coordinate byte 78 Bed headboard Y as block coordinate
Z coordinate int 128 Bed headboard Z as block coordinate
Total Size: 15 bytes



Animation (0x12)

Two-Way

Sent whenever an entity should change animation.

Packet ID Field Name Field Type Example Notes
0x12 EID int 55534 Player ID
Animation byte 1 Animation ID
Total Size: 6 bytes

Animation can be one of the following values:

ID Animation
0 No animation
1 Swing arm
2 Damage animation
3 Leave bed
5 Eat food
102 (unknown)
104 Crouch
105 Uncrouch

Only 1 (swing arm) is sent by notchian clients. Crouching is sent via 0x13. Damage is server-side, and so is not sent by notchian clients. See also 0x26.


Entity Action (0x13)

Client to Server

Sent at least when crouching, leaving a bed, or sprinting. To send action animation to client use 0x28. The client will send this with Action ID = 3 when "Leave Bed" is clicked.

Packet ID Field Name Field Type Example Notes
0x13 EID int 55534 Player ID
Action ID byte 1 The ID of the action, see below.
Total Size: 6 bytes

Action ID can be one of the following values:

ID Action
1 Crouch
2 Uncrouch
3 Leave bed
4 Start sprinting
5 Stop sprinting


Spawn Named Entity (0x14)

Server to Client

The only named entities (at the moment) are players (either real or NPC/Bot). This packet is sent by the server when a player comes into visible range, not when a player joins.

Servers can, however, safely spawn player entities for players not in visible range. The client appears to handle it correctly.

At one point, the Notchian client was not okay with receiving player entity packets, including 0x14, that refer to its own username or EID; and would teleport to the absolute origin of the map and fall through the Void any time it received them. However, in more recent versions, it appears to handle them correctly, by spawning a new entity as directed (though future packets referring to the entity ID may be handled incorrectly).

Packet ID Field Name Field Type Example Notes
0x14 EID int 94453 Player ID
Player Name string Twdtwd Max length of 16
X int 784 Player X as Absolute Integer
Y int 2131 Player Y as Absolute Integer
Z int -752 Player Z as Absolute Integer
Yaw byte 0 Player rotation as a packed byte
Pitch byte 0 Player rotation as a packed byte
Current Item short 0 The item the player is currently holding. Note that this should be 0 for "no item", unlike -1 used in other packets. A negative value crashes clients.
Total Size: 23 bytes + length of strings


Spawn Dropped Item (0x15)

Server to Client

An 0x15 packet is sent by the server whenever an item on the ground (say a pickaxe thrown on the ground) comes into range of the player. (note: this means range for item vision, not range for pickup!) It used to be sent by the client when an item is dropped from a tile (chest or furnace) or from inventory, but that is now done with the new packets for server-side inventory (see Window click (0x66)).

It is completely acceptable for servers to ignore the EID issued by the client in this packet and instead create a new packet with a server-controlled EID when sending this packet out to clients.

Packet ID Field Name Field Type Example Notes
0x15 EID int 157617 Unique entity ID
Item short 4 The item ID
Count byte 1 The number of items
Damage/Data short New field in beta 1.2 update (see below)
X int 133 Item X as Absolute Integer
Y int 913 Item Y as Absolute Integer
Z int 63552 Item Z as Absolute Integer
Rotation byte 252 Item rotation as a packed byte
Pitch byte 25 Item pitch as a packed byte
Roll byte 12 Item roll as a packed byte
Total Size: 25 bytes

"Damage" field This field is also used to store item metadata. E.g. you mined birch wood(its id is the same as normal wood) so you must set damage to the metadata of birch wood(2). The same case is wool. Id is the same but data is different.For example: you mined blue wool so your damage field should send value 0xB.


Collect Item (0x16)

Server to Client

Sent by the server when someone picks up an item lying on the ground - its sole purpose appears to be the animation of the item flying towards you. It doesn't destroy the entity in the client memory (0x1D does that), and it doesn't add it to your inventory (0x68 does that). The server only checks for items to be picked up after each Player Position and Player Position & Look packet sent by the client.

Packet ID Field Name Field Type Example Notes
0x16 Collected EID int 38
Collector EID int 20
Total Size: 9 bytes


Spawn Object/Vehicle (0x17)

Server to Client

Sent by the server when an Object/Vehicle is created.

Packet ID Field Name Field Type Example Notes
0x17 EID int 62 Entity ID of the Object
Type byte 11 The type of object (see Entities#Objects)
X int 16080 The Absolute Integer X Position of the object
Y int 2299 The Absolute Integer Y Position of the object
Z int 592 The Absolute Integer Z Position of the object
Additional Data Object Data 0 Additional data with details on the object


Spawn Mob (0x18)

Server to Client

Sent by the server when a Mob Entity is Spawned

Packet ID Field Name Field Type Example Notes
0x18 EID int 446 Entity ID
Type byte 91 The type of mob. See Entities#Mobs
X int 13366 The Absolute Integer X Position of the object
Y int 2176 The Absolute Integer Y Position of the object
Z int 1680 The Absolute Integer Z Position of the object
Yaw byte -27 The yaw in steps of 2p/256
Pitch byte 0 The pitch in steps of 2p/256
Head Yaw byte Head yaw in steps of 2p/256
Metadata Metadata 127 Varies by mob, see Entities
Total Size: 21 bytes + Metadata (at least 1)


Spawn Painting (0x19)

Server to Client

This packet shows location, name, and type of painting.

Packet ID Field Name Field Type Example Notes
0x19 Entity ID int 0x00000326 Unique entity ID
Title string Creepers Name of the painting; max length 13 (length of "SkullAndRoses")
X int 50 Center X coordinate
Y int 66 Center Y coordinate
Z int -50 Center Z coordinate
Direction int 0 Direction the painting faces (0 -z, 1 -x, 2 +z, 3 +x)
Total Size: 23 bytes + length of string

Calculating the center of an image: given a (width x height) grid of cells, with (0, 0) being the top left corner, the center is (max(0, width / 2 - 1), height / 2). E.g.

2x1 (1, 0) 4x4 (1, 2)


Spawn Experience Orb (0x1A)

Server to Client

Spawns one or more experience orbs. Coordinates are in absolute units.

Packet ID Field Name Field Type Example Notes
0x1A Entity ID int 105668
x int -1143
y int 1952
z int 1166
count short 7
Total Size: 19 bytes


Entity Velocity (0x1C)

Server to Client

This packet is new to version 4 of the protocol, and is believed to be Entity Velocity/Motion.

Velocity is believed to be in units of 1/32000 of a block per server tick (200ms); for example, -1343 would move (-1343 / 32000) = -0.04196875 blocks per tick (or -0.20984375 blocks per second).

Each axis' velocity is capped between -0.9 and 0.9 blocks per tick (packet values -28800 to 28800).

(This packet data values are not fully verified)

Packet ID Field Name Field Type Example Notes
0x1C Entity ID int 1805

The entity ID

Velocity X short -1343

Velocity on the X axis

Velocity Y short 0

Velocity on the Y axis

Velocity Z short 0

Velocity on the Z axis

Total Size: 11 bytes


Destroy Entity (0x1D)

Server to Client

Sent by the server when an Entity is to be destroyed on the client.

Packet ID Field Name Field Type Example Notes
0x1D EID int 446 Entity ID
Total Size: 5 bytes


Entity (0x1E)

Server to Client

Most entity-related packets are subclasses of this packet. When sent from the server to the client, it may initialize the entry.

For player entities, either this packet or any move/look packet is sent every game tick. So the meaning of this packet is basically that the entity did not move/look since the last such packet.

Packet ID Field Name Field Type Example Notes
0x1E EID int 446 Entity ID
Total Size: 5 bytes


Entity Relative Move (0x1F)

Server to Client

This packet is sent by the server when an entity moves less then 4 blocks; if an entity moves more than 4 blocks Entity Teleport should be sent instead.

This packet allows at most four blocks movement in any direction, because byte range is from -128 to 127. Movement is an offset of Absolute Int; to convert relative move to block coordinate offset, divide by 32.

Packet ID Field Name Field Type Example Notes
0x1F EID int 459 Entity ID
dX byte 1 X axis Relative movement as an Absolute Integer
dY byte -7 Y axis Relative movement as an Absolute Integer
dZ byte 5 Z axis Relative movement as an Absolute Integer
Total Size: 8 bytes


Entity Look (0x20)

Server to Client

This packet is sent by the server when an entity rotates. Example: "Yaw" field 64 means a 90 degree turn.

Packet ID Field Name Field Type Example Notes
0x20 EID int 459 Entity ID
Yaw byte 126 The X Axis rotation as a fraction of 360
Pitch byte 0 The Y Axis rotation as a fraction of 360
Total Size: 7 bytes


Entity Look and Relative Move (0x21)

Server to Client

This packet is sent by the server when an entity rotates and moves. Since a byte range is limited from -128 to 127, and movement is offset of Absolute Int, this packet allows at most four blocks movement in any direction. (-128/32 == -4)

Packet ID Field Name Field Type Example Notes
0x21 EID int 459 Entity ID
dX byte 1 X axis Relative movement as an Absolute Integer
dY byte -7 Y axis Relative movement as an Absolute Integer
dZ byte 5 Z axis Relative movement as an Absolute Integer
Yaw byte 126 The X Axis rotation as a fraction of 360
Pitch byte 0 The Y Axis rotation as a fraction of 360
Total Size: 10 bytes


Entity Teleport (0x22)

Server to Client

This packet is sent by the server when an entity moves more than 4 blocks.

Packet ID Field Name Field Type Example Notes
0x22 EID int 459 Entity ID
X int 14162 X axis position as an Absolute Integer
Y int 2176 Y axis position as an Absolute Integer
Z int 1111 Z axis position as an Absolute Integer
Yaw byte 126 The X Axis rotation as a fraction of 360
Pitch byte 0 The Y Axis rotation as a fraction of 360
Total Size: 19 bytes


Entity Head Look (0x23)

Server to Client

Changes the direction an entity's head is facing.

Packet ID Field Name Field Type Example Notes
0x23 Entity ID int
Head Yaw byte Head yaw in steps of 2p/256
Total Size: 6 bytes


Entity Status (0x26)

Server to Client

Packet ID Field Name Field Type Example Notes
0x26 Entity ID Int 34353
Entity Status Byte 0x03 See below
Total Size: 6 bytes
Entity Status Meaning
2 Entity hurt
3 Entity dead
6 Wolf taming
7 Wolf tamed
8 Wolf shaking water off itself
9 (of self) Eating accepted by server
10 Sheep eating grass


Attach Entity (0x27)

Server to Client

This packet is new to version 4 of the protocol, and is believed to be Attach Entity.

This packet is sent when a player has been attached to an entity (e.g. Minecart)

(This packet data values are not fully verified)

Packet ID Field Name Field Type Example Notes
0x27 Entity ID int 1298

The player entity ID being attached

Vehicle ID int 1805

The vehicle entity ID attached to (-1 for unattaching)

Total Size: 9 bytes


Entity Metadata (0x28)

Server to Client

Packet ID Field Name Field Type Example Notes
0x28 Entity ID int 0x00000326 Unique entity ID to update.
Entity Metadata Metadata 0x00 0x01 0x7F Metadata varies by entity. See Entities
Total Size: 5 bytes + Metadata


Entity Effect (0x29)

Server to Client

Packet ID Field Name Field Type Example Notes
0x29 Entity ID int 14 Entity ID of a player
Effect ID byte 17 See here
Amplifier byte 0
Duration short 64
Total Size: 9 bytes


Remove Entity Effect (0x2A)

Server to Client

Packet ID Field Name Field Type Example Notes
0x2a Entity ID int Entity ID of a player
Effect ID byte 17 See table above
Total Size: 6 bytes


Set Experience (0x2B)

Server to Client

Sent by the server when the client should change experience levels.

Packet ID Field Name Field Type Example Notes
0x2B Experience bar float 0.5960060358047485 Used for drawing the experience bar - value is between 0 and 1.
Level short 8
Total experience short 130
Total Size: 9 bytes


Chunk Allocation (0x32)

Server to Client

See also: Map Format

This packet is sent by the server to notify the client to initialize (Mode=1) or unload (Mode=0) a chunk. The client is expected to allocate space for a full chunk (currently 16 x 256 x 16 blocks). One or more 0x33 packets will follow, specifying actual data to fill the chunk with.

:!: Whenever you send this packet the client will clear any previous chunk at that spot if one has previously been sent. Clients don't like being in or next to an unloaded chunk, so try not to unload it if players are nearby. If the player appears to be twitching and stuck in place after joining the world, there is probably an unloaded chunk too close to them.

Packet ID Field Name Field Type Example Notes
0x32 X int -9 Chunk X Coordinate
Z int 12 Chunk Z Coordinate
Mode bool 1 If mode is 0 the client will unload the chunk, otherwise the client will initialize the chunk
Total Size: 10 bytes


When unloading a chunk from a client, the official server will send one of these packets with "Mode" set to false, and will follow it with an 0x33 packet whose contents are empty for the same coordinates.

Chunk Data (0x33)

Server to Client

See also: Map Format

Chunks are sent a column at a time, with some sections optionally missing from each packet (those consisting only of air).

Packet ID Field Name Field Type Example Notes
0x33 X int Chunk X Coordinate (*16 to get true X)
Z int Chunk Z Coordinate (*16 to get true Z)
Ground-up continuous boolean This is True if the packet represents all sections in this vertical column, where the primary bit map specifies exactly which sections are included, and which are air.
Primary bit map unsigned short 15 Bitmask with 1 for every 16x16x16 section which data follows in the compressed data.
Add bit map unsigned short 0 Same as above, but this is used exclusively for the 'add' portion of the payload
Compressed size int Size of compressed chunk data.
Unused int int 0 Doesn't seem to be used by the client. Always 0. I expect this is Mod API stuff.
Compressed data unsigned byte array The chunk data is compressed using ZLib Deflate function.
Total Size: 22 bytes + Compressed chunk size

The payload is a set of 16x16x16 sections, sharing the same X and Z coordinates. What is and isn't sent is provided by the two bitmask fields. The least significant bit is '1' if the section spanning from Y=0 to Y=15 is not completely air, and so forth. For block IDs, metadata, and lighting, the primary bitmask is used. A secondary bitmask is used for 'add' data, which is Mojang's means of provided Block IDs past 256. In vanilla minecraft, you can expect this to always be zero. The sections included in this packet progress from bottom to top, where Y=0 is the bottom.

The data is compressed using the deflate() function in zlib. After uncompressing, the data consists of five (or six) sequential sections, in order:

  • Block type array (1 byte per block, 4096 bytes per section)
  • Block metadata array (half byte per block, 2048 bytes per section)
  • Block light array (half byte per block, 2048 bytes per section)
  • Sky light array (half byte per block, 2048 bytes per section)
  • Add array (half byte per block, 2048 bytes per section, uses second bitmask)
  • Biome array (1 byte per XZ coordinate, 256 bytes total, only sent if 'ground up continuous' is true)

Each section is the concatenated data of all included sections (i.e. the block type array contains the block types of all included sections).

In each section except biome data, your decoder loop should look something like this:

 //Loop over 16x16x16 sections in the 16x256x16 chunk
 for (i=0;i<16;i++) {
   //If the bitmask indicates this chunk has been sent...
   if (bitmask & 1 << i) {
     //Read data...
     cubic_chunk_data = io.read(4096); //2048 for the other arrays, where you'll need to split the data
     
     for(int j=0; j<len(cubic_chunk_data); j++) {
       //Retrieve x,y,z and data from each element in cubic_chunk_array
       
       //Byte arrays
       x = chunk_x*16 + j & 0x0F;
       y = i*16 + j >> 8;
       z = chunk_z*16 + (j & 0xF0) >> 4;
       data = cubic_chunk_data[j]
       
       //Nibble arrays
       data1 = cubic_chunk_data[j] & 0x0F;
       data2 = cubic_chunk_data[j] >> 4;
       
       k = 2*j;
       x1 = chunk_x*16 + k & 0x0F;
       y1 = i*16       + k >> 8;
       z1 = chunk_z*16 + (k & 0xF0) >> 4;
       
       k++;
       x2 = chunk_x*16 + k & 0x0F;
       y2 = i*16       + k >> 8;
       z2 = chunk_z*16 + (k & 0xF0) >> 4;
      }
   }
 }

Each biome byte can have the values from 0 to 22, higher will cause the client to crash.

The 'add' array uses the second bitmask. Block IDs are presumed to be block_id | add << 8

Here's an example of how this packet could be encoded.


Multi Block Change (0x34)

Server to Client

Packet ID Field Name Field Type Example Notes
0x34 Chunk X int -9 Chunk X Coordinate
Chunk Z int 12 Chunk Z Coordinate
Record count short The number of blocks affected
Data size int The total size of the data, in bytes. Should always be 4*record count - please confirm.
Data Coordinates, type, and metadata of blocks to change.
Total Size: 15 bytes + Arrays

Each record is four bytes.

Bit mask Width Meaning
00 00 00 0F 4 bits Block metadata
00 00 FF F0 12 bits Block ID
00 FF 00 00 8 bits Y co-ordinate
0F 00 00 00 4 bits Z co-ordinate, relative to chunk
F0 00 00 00 4 bits X co-ordinate, relative to chunk


Block Change (0x35)

Server to Client

Packet ID Field Name Field Type Example Notes
0x35 X int 502 Block X Coordinate
Y byte 71 Block Y Coordinate
Z int 18 Block Z Coordinate
Block Type byte 78 The new block type for the block
Block Metadata byte 0 The new Metadata for the block
Total Size: 12 bytes


Block Action (0x36)

Server to Client

This packet is used for a number of things:

  • Chests opening and closing
  • Pistons pushing and pulling
  • Note blocks playing
Packet ID Field Name Field Type Example Notes
0x36 X int 502 Block X Coordinate
Y short 71 Block Y Coordinate
Z int 18 Block Z Coordinate
Byte 1 byte 3 Varies depending on block - see below
Byte 2 byte 17 Varies depending on block - see below
Total Size: 13 bytes

See Also: Block Actions

Explosion (0x3C)

Server to Client

Sent when an explosion occurs (creepers, TNT, and ghast fireballs).

Packet ID Field Name Field Type Example Notes
0x3C X double
Y double
Z double
Radius float 3.0 Currently unused in the client
Record count int This is the count, not the size. The size is 3 times this value.
Records (byte, byte, byte) × count Each record is 3 bytes, which seem to be XYZ offsets of affected blocks.
Total Size: 33 bytes + 3*(Record count) bytes


Sound/Particle Effect (0x3D)

Server to Client

Sent when a client is to play a sound or particle effect.

Packet ID Field Name Field Type Example Notes
0x3D Effect ID int 1003 The ID of the effect, see below.
X int The X location of the effect.
Y byte The Y location of the effect.
Z int The Z location of the effect.
Data int 0 Extra data for certain effects, see below.
Total Size: 18 bytes

Effects

Sound:

  • 1000: random.click
  • 1001: random.click
  • 1002: random.bow
  • 1003: random.door_open or random.door_close (50/50 chance)
  • 1004: random.fizz
  • 1005: Play a music disc. Data: Record ID
  • (1006 not assigned)
  • 1007: mob.ghast.charge
  • 1008: mob.ghast.fireball
  • (1009 not assigned)
  • 1010: mob.zombie.wood
  • 1011: mob.zombie.metal
  • 1012: mob.zombie.woodbreak

Particle:

  • 2000: Spawns 10 smoke particles, e.g. from a fire. Data: direction, see below
  • 2001: Block break. Data: Block ID
  • 2002: Splash potion. Particle effect + glass break sound. Data: Potion ID
  • 2003: Eye of ender. Actual client effect to be determined.
  • 2004: Mob spawn particle effect: smoke + flames

Smoke directions:

ID Direction
0 South - East
1 South
2 South - West
3 East
4 (Up or middle ?)
5 West
6 North - East
7 North
8 North - West


Change Game State (0x46)

Server to Client

This packet appeared with protocol version 10. Currently, it appears when a bed can't be used as a spawn point and when the rain state changes. it could have additional uses in the future.

The class has an array of strings linked to reason codes 0, 1, 2, and 3 but only the codes for 1 and 2 are null.

Packet ID Field Name Field Type Example Notes
0x46 Reason byte 0
Game mode byte 0 Used only when reason = 3. 0 is survival, 1 is creative.
Total Size: 3 bytes

Reason codes

Code Effect Text
0 Invalid Bed "tile.bed.notValid"
1 Begin raining null
2 End raining null
3 Change game mode gameMode.changed
4 Enter credits


Thunderbolt (0x47)

Server to Client

With this packet, the server notifies the client of thunderbolts striking somewhere (near the player?). The coordinates specify where exactly the thunderbolt strikes.

Packet ID Field Name Field Type Example Notes
0x47 Entity ID int 4 The entity ID of the thunderbolt
Unknown boolean true Always true. Might have a meaning in the future...
X int 133 Thunderbolt X as Absolute Integer
Y int 913 Thunderbolt Y as Absolute Integer
Z int 63552 Thunderbolt Z as Absolute Integer
Total Size: 18 bytes


Open Window (0x64)

Server to Client

This is sent to the client when it should open an inventory, such as a chest, workbench, or furnace. This message is not sent anywhere for clients opening their own inventory.

Packet ID Field Name Field Type Example Notes
0x64 Window id byte 123 A unique id number for the window to be displayed. Notchian server implementation is a counter, starting at 1.
Inventory Type byte 2 The window type to use for display. Check below
Window title string Chest The title of the window.
Number of Slots byte 3 Number of slots in the window (excluding the number of slots in the player inventory).
Total Size: 6 bytes + length of string

The window titles sent by the Notchian server are "Chest", "Large chest", "Crafting", "Furnace", and "Trap". Notchian clients force window titles for some windows, like dispensers and furnaces, but other titles are customizable. However, the window title sent by the server is always used for chests. See inventory windows for further information.


Close Window (0x65)

Two-Way

This packet is sent by the client when closing a window. This packet is sent from the server to the client when a window is forcibly closed, such as when a chest is destroyed while it's open.

Note, notchian clients send a close window message with window id 0 to close their inventory even though there is never an Open Window message for inventory.

Packet ID Field Name Field Type Example Notes
0x65 Window id byte 0 This is the id of the window that was closed. 0 for inventory.
Total Size: 2 bytes


Click Window (0x66)

Client to Server

This packet is sent by the player when it clicks on a slot in a window.

Packet ID Field Name Field Type Example Notes
0x66 Window id byte 0 The id of the window which was clicked. 0 for player inventory.
Slot short 36 The clicked slot. See below.
Right-click byte 1 1 when right-clicking and otherwise 0.
Action number short 12 A unique number for the action, used for transaction handling (See the Transaction packet).
Shift bool 0 This is true if the user was holding keyboard shift when they clicked.
Clicked item slot
Total Size: 8 bytes + slot data

See inventory windows for further information about how slots are indexed.

When right-clicking on a stack of items, half the stack will be picked up and half left in the slot. If the stack is an odd number, the half left in the slot will be smaller of the amounts.

The Action number is actually a counter, starting at 1. This number is used by the server as a transaction ID to send back a Transaction packet.


Set Slot (0x67)

Server to Client

Sent by the server when an item in a slot (in a window) is added/removed.

Packet ID Field Name Field Type Example Notes
0x67 Window id byte 0 The window which is being updated. 0 for player inventory. Note that all known window types include the player inventory. This packet will only be sent for the currently opened window while the player is performing actions, even if it affects the player inventory. After the window is closed, a number of these packets are sent to update the player's inventory window (0).
Slot short 36 The slot that should be updated
Slot data slot
Total Size: 4 bytes + slot data

Note that if window ID and slot are both -1, it means the item currently attached to the cursor.

See inventory windows for further information about how slots are indexed.

Slots: [1]


Set Window Items (0x68)

Server to Client

The inventory slots

Sent by the server when an item in a slot (in a window) is added/removed. This includes the main inventory, equipped armour and crafting slots.

Packet ID Field Name Field Type Example Notes
0x68 Window id byte 1 The id of window which items are being sent for. 0 for player inventory.
Count short 4 The number of slots (see below)
Slot data array of slots
Total Size: 4 bytes + size of slot data array

See inventory windows for further information about how slots are indexed.


Update Window Property (0x69)

Server to Client

Packet ID Field Name Field Type Example Notes
0x69 Window id byte 2 The id of the window.
Property short 1 Which property should be updated.
Value short 650 The new value for the property.
Total Size: 6 bytes

Furnace

Properties:

  • 0: Progress arrow
  • 1: Fire icon (fuel)

Values:

  • 0-180 for progress arrow
  • 0-250 for fuel indicator

Ranges are presumably in in-game ticks

Enchantment Table

Properties: 0, 1 or 2 depending on the "enchantment slot" being given.

Values: The enchantment's level.


Confirm Transaction (0x6A)

Two-Way

A packet from the server indicating whether a request from the client was accepted, or whether there was a conflict (due to lag). This packet is also sent from the client to the server in response to a server transaction rejection packet.

Packet ID Field Name Field Type Example Notes
0x6A Window id byte 0 The id of the window that the action occurred in.
Action number short 12 Every action that is to be accepted has a unique number. This field corresponds to that number.
Accepted? boolean true Whether the action was accepted.
Total Size: 5 bytes


Creative Inventory Action (0x6B)

Two-Way

While the user is in the standard inventory (i.e., not a crafting bench) on a creative-mode server then the server will send this packet:

  • If an item is dropped into the quick bar
  • If an item is picked up from the quick bar (item id is -1)
Packet ID Field Name Field Type Example Notes
0x6B Slot short 36 Inventory slot
Clicked item slot
Total Size: 3 bytes + slot data


Enchant Item (0x6C)

Client to Server

Packet ID Field Name Field Type Example Notes
0x6C Window ID byte 1 The ID sent by Open Window
Enchantment byte 0 The position of the enchantment on the enchantment table window, starting with 0 as the topmost one.
Total Size: 3 bytes


Update Sign (0x82)

Two-Way

Packet ID Field Name Field Type Example Notes
0x82 X int 128 Block X Coordinate
Y short 0 Block Y Coordinate
Z int -128 Block Z Coordinate
Text1 string First line First line of text in the sign
Text2 string Second line Second line of text in the sign
Text3 string Third line Third line of text in the sign
Text4 string Fourth line Fourth line of text in the sign
Total Size: 11 bytes + 4 strings

This message is sent from the server to the client whenever a sign is discovered or created. This message is sent from the client to the server when the "Done" button is pushed after placing a sign. This message is NOT sent when a sign is destroyed or unloaded.


Item Data (0x83)

Server to Client

Sent to specify complex data on an item; currently used only for maps.

Packet ID Field Name Field Type Example Notes
0x83 Item Type short 358 Type of item being modified
Item ID short 0 The ID (damage value) of the item being modified
Text length unsigned byte 35 Length of following byte array
Text byte array {0,0,0,20,20,20,20,20} ASCII text.
Total Size: 6 bytes + Text length

Maps If the first byte of the text is 0, the next two bytes are X start and Y start and the rest of the bytes are the colors in that column.

If the first byte of the text is 1, the rest of the bytes are in groups of three: (data, x, y). The lower half of the data is the type (always 0 under vanilla) and the upper half is the direction.


Update Tile Entity (0x84)

Server to Client

Essentially a block update on a tile entity.

Packet ID Field Name Field Type Example Notes
0x84 X int
Y short
Z int
Action byte The type of update to perform
Custom 1 int Varies
Custom 2 int Varies
Custom 3 int Varies
Total Size: 24 bytes

Actions

  • 1: Set mob displayed inside a mob spawner. Custom 1 contains the mob type


Increment Statistic (0xC8)

Server to Client

Packet ID Field Name Field Type Example Notes
0xC8 Statistic ID int 1003 The ID of the statistic. See List of statistics.
Amount byte 1 The amount to increment the statistic.
Total Size: 6 bytes


Player List Item (0xC9)

Server to Client

Sent by the notchian server to update the user list (<tab> in the client). The server sends one packet per user per tick, amounting to 20 packets/s for 1 online user, 40 for 2, and so forth.

Packet ID Field Name Field Type Example Notes
0xC9 Player name string barneygale Supports chat colouring, limited to 16 characters.
Online bool true If false, the client will remove the user from the list.
Ping short 193 Ping, presumably in ms.
Total Size: 6 bytes + length of string


Player Abilities (0xCA)

Two-Way

The packet is said to contain the players ability to fly, invulnerability and to destroy blocks instantly. In survival, all booleans are set to false, in creative all parameters except the second are set to true. The first and the last parameter seem to be not parsed by the client yet and to be derived from the player's gamemode.

The vanilla client sends this packet when the player starts/stops flying with the second parameter changed accordingly. All other parameters are ignored by the vanilla server.

Test: [2]

Packet ID Field Name Field Type Example Notes
0xCA Invulnerability? bool true True if the player cannot take damage
Is flying bool false Player is currently flying
Can fly bool true True if the player is able to fly
Instant Destroy bool true True if the player can destroy blocks instantly
Total Size: 5 bytes

The first and fourth booleans are speculation.


Plugin Message (0xFA)

Two-Way

Mods and plugins can use this to send their data.

Packet ID Field Name Field Type Example Notes
0xFA Channel string MyMod:testchannel Name of the "channel" used to send the data.
length short Length of the following byte array
data byte array Any data.
Total Size: 5 bytes + length of string + length of byte array

More documentation on this: http://dinnerbone.com/blog/2012/01/13/minecraft-plugin-channels-messaging/


Server List Ping (0xFE)

Client to Server

To load server info in the multiplayer menu, the notchian client connects to each known server and sends an 0xFE.

In return, the server sends a kick (0xFF), with its string containing data (server description, number of users, number of slots), delimited by a UCS-2 '§' (0xA7).

Note that as this is the last packet you'll see, you can get away with just chopping off the first three bytes (the ident and the string length) and decoding the remainder as a UCS-2 string.

If the number of available slots sent is equal to or less than 0, the client should display it as "???".

Example server pinger:

https://gist.github.com/1209061 (Python)

https://gist.github.com/1235274 (PHP)

http://pastebin.com/q5zFPcXV (Ruby)

Packet ID
0xFE


Disconnect/Kick (0xFF)

Two-Way

Sent by the server before it disconnects a client, or by the client before it disconnects from the server. The receiver of this packet assumes that the sender has already closed the connection by the time the packet arrives.

Due to race conditions in the client, a local server may need to pause for a short period after sending this packet before closing the connection. An alternative is simply not to close the connection, and wait for the client to do so on receipt of this packet.

Packet ID Field Name Field Type Example Notes
0xFF Reason string The server is full! Displayed to the client when the connection terminates
Total Size: 3 bytes + length of strings

See Also