Difference between revisions of "Pre-release protocol"

From wiki.vg
Jump to navigation Jump to search
(→‎Map Chunk (0x33): Biome data is after the add array, unless I'm mistaken)
 
Line 386: Line 386:
 
=== Multi Block Change (0x34) ===
 
=== Multi Block Change (0x34) ===
  
Further investigation shows that this is a multiple-block-change command; if you take the three arrays, and put together elements with the same index, and then decompose the short into coordinates (top 4 bits is X, next 4 bits is Z, bottom 8 bits is Y), you get things like [((8, 7, 4), 11, 0), ((7, 13, 6), 11, 0), ((13, 1, 8), 11, 0), ((7, 6, 6), 11, 0)].
+
Like 0x33, this follows a new format. Arrays are now interlaced rather than sequential!
 
 
See the Block Change command for description of the general format of a block change.
 
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 398: Line 396:
 
! class="col4" | Notes
 
! class="col4" | Notes
 
|- class="row1"
 
|- class="row1"
| class="col0 centeralign" rowspan="6" | 0x34
+
| class="col0 centeralign" rowspan="5" | 0x34
 
| class="col1 centeralign" | Chunk X
 
| class="col1 centeralign" | Chunk X
 
| class="col2 centeralign" | int
 
| class="col2 centeralign" | int
Line 409: Line 407:
 
| class="col3" | Chunk Z Coordinate
 
| class="col3" | Chunk Z Coordinate
 
|- class="row3"
 
|- class="row3"
| class="col0 centeralign" | Array size
+
| class="col0 centeralign" | Record count
 
| class="col1 centeralign" | short
 
| class="col1 centeralign" | short
| class="col2 centeralign" | <code>2</code>
+
| class="col2 centeralign" |  
| class="col3" | The total number of elements per array
+
| class="col3" | The number of blocks affected
 
|- class="row2"
 
|- class="row2"
| class="col0 centeralign" | Unknown
+
| class="col0 centeralign" | Data size
 
| class="col1 centeralign" | int
 
| class="col1 centeralign" | int
| class="col2 centeralign" | <code>40</code>
+
| class="col2 centeralign" |  
| class="col3" | Unknown
+
| class="col3" | The total size of the data, in bytes. Should always be 4*record count - please confirm.
 
|- class="row4"
 
|- class="row4"
| class="col0 centeralign" | Coordinate array
+
| class="col0 centeralign" | Data
| class="col1 centeralign" | short array
+
| class="col1 centeralign" |  
 
| class="col2 centeralign" | <code>…</code>
 
| class="col2 centeralign" | <code>…</code>
| class="col3" | The coordinates of the blocks to change
+
| class="col3" | Coordinates, type, and metadata of blocks to change.
 
|- class="row5"
 
|- class="row5"
| class="col0 centeralign" | Type array
 
| class="col1 centeralign" | byte array
 
| class="col2 centeralign" | <code>…</code>
 
| class="col3" | The type for each block change
 
|- class="row6"
 
| class="col0 centeralign" | Metadata array
 
| class="col1 centeralign" | byte array
 
| class="col2 centeralign" | <code>…</code>
 
| class="col3 leftalign" | The Metadata for each block changed
 
|- class="row7"
 
 
! class="col0" | Total Size:
 
! class="col0" | Total Size:
| class="col1 rightalign" colspan="4" | 11 bytes + Arrays
+
| class="col1 rightalign" colspan="4" | 15 bytes + Arrays
 +
|}
 +
 
 +
Each record is four bytes.
 +
 
 +
{| class="wikitable"
 +
|- class="row0"
 +
! class="col0" | Bit mask
 +
! class="col1" | Width
 +
! class="col2" | Meaning
 +
|- class="row1"
 +
| class="col0" | 00 00 00 0F
 +
| class="col1" | 4 bits
 +
| class="col2" | Block metadata
 +
|- class="row2"
 +
| class="col0" | 00 00 FF F0
 +
| class="col1" | 12 bits
 +
| class="col2" | Block ID
 +
|- class="row3"
 +
| class="col0" | 00 FF 00 00
 +
| class="col1" | 8 bits
 +
| class="col2" | Y co-ordinate
 +
|- class="row4"
 +
| class="col0" | 0F 00 00 00
 +
| class="col1" | 4 bits
 +
| class="col2" | Z co-ordinate, relative to chunk
 +
|- class="row5"
 +
| class="col0" | F0 00 00 00
 +
| class="col1" | 4 bits
 +
| class="col2" | X co-ordinate, relative to chunk
 
|}
 
|}
  

Revision as of 23:29, 23 February 2012

This page documents the changes from the last stable Minecraft release (currently 1.1) to the current pre-release

New packets

Entity Head Look (0x23)

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 2π/256
Total Size: 6 bytes

Update Tile Entity (0x84)

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

Changed packets

Login Request (0x01)

World height field is no longer used, always 0.

Map seed field removed

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 SUPERFLAT; 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
World height byte 0 Probably not used anymore since Map Chunk is hardcoded to 256 blocks.
Max players unsigned byte 8 Used by the client to draw the player list
Total Size: 19 bytes + length of strings

Handshake (0x02)

Client to Server

The hostname and port were added to this packet, most likely to allow virtual hosting .(sample implementation)

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

Respawn (0x09)

Dimension is now an int, slightly bizarrely. I wonder if they intended to make world_height an int, in line with 0x01 login?

Map seed field removed

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 128 Defaults to 128
Level Type string DEFAULT See 0x01 login
Total Size: 11 bytes + length of string

Mob Spawn (0x18)

New byte field: head yaw

This needs confirmation!

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 2π/256
Pitch byte 0 The pitch in steps of 2π/256
Head Yaw byte Head yaw in steps of 2π/256
Metadata Metadata 127 Varies by mob, see Entities
Total Size: 21 bytes + Metadata (at least 1)

Map Chunk (0x33)

This is currently a best guess

Here's a packet capture: https://gist.github.com/1835702

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 contiguous boolean This is True if the chunks consists of a contiguous column of non-air (i.e., indicated with a '1' in the bitmask) chunks starting at Y=0, followed by any number of unsent chunks containing only air.
Primary bit map short 15 Bitmask with 1 for every 16x16x16 chunk which data follows in the compressed data.
Add bit map short 0 Same as above, but this is used exclusively for the 'add' portion of the payload
Compressed size int Size of compressed region 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 region data is compressed using ZLib Deflate function.
Total Size: 22 bytes + Compressed chunk size

The payload is a set of 16x16x16 chunks, sharing the same X and Z chunk coordinates. What is and isn't sent is provided by the two bitmask fields. The least significant bit is '1' if the chunk 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 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 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, uses second bitmask)
  • Biome array (1 byte per XZ column, 256 bytes total, only sent if 'ground up contiguous' is true)

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

 for (i=0;i<16;i++) {
   if (bitmask & 1 << i) {
     data = io.read(4096); //2048 for the other arrays, where you'll need to split the data
     
     for(int j=0; j<len(data); j++) {
       
       //Block data
       x = (j & 0xF0) >> 4;
       y = j & 0x0F;
       z = j >> 8;
       
       //Nibble arrays
       d1 = data[j] & 0x0F;
       d2 = data[j] >> 4;
       
       k = 2*j;
       x1 = (k & 0xF0) >> 4;
       y1 = k & 0x0F;
       z1 = k >> 8;
       
       k++;
       x2 = (k & 0xF0) >> 4;
       y2 = k & 0x0F;
       z2 = k >> 8;
      }
   }
 }

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

Multi Block Change (0x34)

Like 0x33, this follows a new format. Arrays are now interlaced rather than sequential!

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

Protocol History

2012-02-23

  • 12w08a
  • Protocol version is now 28
  • Updated packets: 0x01, 0x09, 0x34

2012-02-15

  • 12w07a
  • Protocol version is now 27
  • Updated packets: 0x01, 0x09, 0x33

2012-02-09

  • 12w06a
  • Protocol version is now 25
  • New packet: 0x84

2012-01-26

  • 12w04a
  • Protocol version has not been changed
  • Handshake Packet by client (0x02) now contains the server host and port
  • Window Open Packet (0x64): WindowTitle is now longer than accepted by older clients. Contains a keyword such as "container.furnace"

2012-01-19

  • 12w03a
  • Protocol version is now 24
  • New packet: 0x23
  • MobSpawn: new field, 1 byte inserted before metadata.