Difference between revisions of "Zh:Protocol"

From wiki.vg
Jump to navigation Jump to search
Line 1,027: Line 1,027:
 
==== 方块破坏动画 ====
 
==== 方块破坏动画 ====
  
0–9 are the displayable destroy stages and each other number means that there is no animation on this coordinate.
+
0–9时可以显示的破坏阶段,而其他的数字代表在该坐标上没有动画。
  
Block break animations can still be applied on air; the animation will remain visible although there is no block being broken.  However, if this is applied to a transparent block, odd graphical effects may happen, including water losing its transparency.  (An effect similar to this can be seen in normal gameplay when breaking ice blocks)
+
方块破坏动画也用应用于空气上,尽管没有方块正在被破坏,但动画仍然是可见的。然而,如果将其应用于透明的方块上时,会发生古怪的图像效果,包括水会丢失它的透明。(类似于正常游玩过程中破坏冰块的效果)
  
If you need to display several break animations at the same time you have to give each of them a unique Entity ID. The entity ID does not need to correspond to an actual entity on the client. It is valid to use a randomly generated number.
+
如果你需要在同一时间显示多个破坏动画,那么你需要给它们每个一个唯一的实体ID。该实体ID不需要与客户端中的实际实体对应,就算使用随机生成的数字也是有效的。
  
 
{| class="wikitable"
 
{| class="wikitable"
  ! Packet ID
+
  ! 数据包ID
  ! State
+
  ! 状态
  ! Bound To
+
  ! 绑定至
  ! Field Name
+
  ! 字段名称
  ! Field Type
+
  ! 字段类型
  ! Notes
+
  ! 注释
 
  |-
 
  |-
 
  |rowspan="3"| 0x08
 
  |rowspan="3"| 0x08
  |rowspan="3"| Play
+
  |rowspan="3"| 游玩(Play)
  |rowspan="3"| Client
+
  |rowspan="3"| 客户端
 
  | Entity ID
 
  | Entity ID
 
  | VarInt
 
  | VarInt
  | Entity ID of the entity breaking the block
+
  | 破坏方块的实体ID
 
  |-
 
  |-
 
  | Location
 
  | Location
 
  | Position
 
  | Position
  | Block Position
+
  | 方块位置
 
  |-
 
  |-
 
  | Destroy Stage
 
  | Destroy Stage
 
  | Byte
 
  | Byte
  | 0–9 to set it, any other value to remove it
+
  | 0–9来设置它,而其他值移除它
 
  |}
 
  |}
  

Revision as of 08:07, 6 December 2019

注意了!

这篇文章是有关最新稳定发布的Minecraft电脑版(1.14.4,协议498)。对于电脑版的预发布版,参阅预发布版协议。对于携带版,参阅携带版协议文档

本页面提供了对当前Minecraft协议的剖析。

如果你还有疑问,参考FAQ或在#mcdevs chat.freenode.net上的IRC频道寻求帮助(更多信息)。

注意:你可以不受限制地使用此页面内容来创建服务端、客户端、机器人等,但是如果你如果复制此页面的任何内容并在其他地方发布,那么仍需要提供#mcdevs的属性。

版本间的更改可以在协议历史中查看。

Contents

定义

Minecraft服务端接受来自TCP客户端的连接并通过数据包'进行交流。数据包是通过TCP连接发送的字节序列。数据包的含义取决于它的数据包ID和连接的当前状态。每个连接的初始状态都是握手中,状态通过数据包握手登入成功来更改。

数据类型

所有在网络上发送的数据(除VarInt和VarLong外)都是大字节序的,也就是说,字节是从最高有效字节到最低有效字节发送。大多数日常遇到的电脑都是小字节序的,所以也许有必要在网络上发送数据前更改字节序。


名称 大小(字节) 编码 注释
Boolean 1 false或true True被编码为0x01,false为0x00
Byte 1 -128到127之间的整数 有符号8位整数,补码
Unsigned Byte 1 0和255之间的整数 无符号8位整数
Short 2 -32768和32767之间的整数 有符号16位整数,补码
Unsigned Short 2 0和65535之间的整数 无符号16位整数
Int 4 -2147483648和2147483647之间的整数 有符号32位整数,补码
Long 8 -9223372036854775808和9223372036854775807之间的整数 有符号64位整数,补码
Float 4 单精度32位IEEE 754浮点数
Double 8 双精度64位IEEE 754浮点数
String(n) ≥ 1
≤ (n×4) + 3
Unicode标量序列 以它的大小用字节为单位表示对VarInt为前缀的UTF-8字符串。n字符的最大长度随上下文而变化,最多可以使用n × 4字节来编码n个字符,并同时检查这些限制。最大的n值为32767。+ 3是因为有效长度VarInt的最大大小。
Chat ≥ 1
≤ (32767×4) + 3
Chat 编码为最大长度为32767的字符串。
Identifier ≥ 1
≤ (32767×4) + 3
见下方标识符 编码为最大长度为32767的字符串。
VarInt ≥ 1
≤ 5
-2147483648和2147483647之间的整数 编码补码32位整型的可变长度数据,更多信息参阅它们的部分
VarLong ≥ 1
≤ 10
-9223372036854775808和9223372036854775807之间的整数 编码补码64位整型的可变长度数据,更多信息参阅它们的部分
Entity Metadata 可变 有关实体的杂项信息 实体#实体元数据格式
Slot 可变 在物品栏或容器中的一组物品 槽数据
NBT Tag 可变 取决于上下文 NBT
Position 8 一个整型/方块位置: x(-33554432至33554431)、y(-2048至2047)、z(-33554432至33554431) x为26位整数,后面跟着12位整数的y,以及26位整数的z(都是有符号的,补码)。另见下面的部分
Angle 1 一圈的1/256为步长的旋转角度 这是否是有符号的都无所谓,因为结果角度是相同的。
UUID 16 UUID 编码为无符号128整数(或两个无符号64位整数:高64位和低64位)
Optional X 0或X的大小 类型X的字段,或什么都没有 该字段是否出现必须从上下文得知。
Array of X 数量乘上X的大小 类型X的零或更多的字段 数量必须必须从上下文得知。
X Enum X的大小 给定列表中特定的值 可能的值的列表和每个该如何编码为X都必须从上下文中得知。无论哪一边发送的无效值通常都会导致客户端断开连接并产生一个错误甚至崩溃。
Byte Array 可变 取决于上下文 这通常是一个零或更多字节的序列,它的含义会在别的地方解释,例如数据包描述中。长度必须从上下文中得知。

标识符

标识符是一个以minecraft:thing为形式的带命名空间的位置。如果没有提供命名空间,那么它默认为minecraft(即,thing变为minecraft:thing。自定义内容应该总是在它自己的命名空间中,而不是默认的中。命名空间应该只使用这些字符:01​​234​5​6​78​9abcdefghijklmnopqrstuvwxyz-_,实际的名称可能会包含更多符号。命名约定是lower_case_with_underscores(蛇形命名法)。更多信息

VarInt和VarLong

可变长度格式,就像较小的数会使用较少的字节。于Protocol Buffer Varints非常相似:7个最底位用于编码值而最高位用于指示在之后还有多少用于数字下一部分的字节。最低位的组写在最前面,后面跟着更高位的组;因此,VarInts实际上是小字节序的(然而,组是7位而不是8位的)。

VarInts永远不会多余5字节,VarLongs永远不会多于10字节。

读取并写入VarInts和VarLongs的伪代码:

public static int readVarInt() {
    int numRead = 0;
    int result = 0;
    byte read;
    do {
        read = readByte();
        int value = (read & 0b01111111);
        result |= (value << (7 * numRead));

        numRead++;
        if (numRead > 5) {
            throw new RuntimeException("VarInt is too big");
        }
    } while ((read & 0b10000000) != 0);

    return result;
}
public static long readVarLong() {
    int numRead = 0;
    long result = 0;
    byte read;
    do {
        read = readByte();
        int value = (read & 0b01111111);
        result |= (value << (7 * numRead));

        numRead++;
        if (numRead > 10) {
            throw new RuntimeException("VarLong is too big");
        }
    } while ((read & 0b10000000) != 0);

    return result;
}
public static void writeVarInt(int value) {
    do {
        byte temp = (byte)(value & 0b01111111);
        // Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone
        value >>>= 7;
        if (value != 0) {
            temp |= 0b10000000;
        }
        writeByte(temp);
    } while (value != 0);
}
public static void writeVarLong(long value) {
    do {
        byte temp = (byte)(value & 0b01111111);
        // Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone
        value >>>= 7;
        if (value != 0) {
            temp |= 0b10000000;
        }
        writeByte(temp);
    } while (value != 0);
}

Warning.png 注意Minecraft的VarInts不是使用Protocol Buffers编码的,它们只是相似罢了。如果你尝试将Protocol Buffers Varints用于Minecraft的VarInts,你会在某些情况下得到不正确的结果。主要的区别有:

  • Minecraft的VarInts都是有符号的,但不使用ZigZag编码。Protocol buffers有三种类型Varints:uint32(普通编码、无符号)、sint32(ZigZag编码、无符号)和int32(普通编码、有符号)。 Minecraft的是int32种类。因为Minecraft使用正常的编码而不是ZigZag编码,负值总是会使用字节的最大数字。
  • Minecraft的VarInts永远不会多于5字节,VarLongs永不多于10字节,而Protocol Buffer Varints会总是使用10字节来编码负数,即使它是int32

示例VarInts:

十六进制字节 十进制字节
0 0x00 0
1 0x01 1
2 0x02 2
127 0x7f 127
128 0x80 0x01 128 1
255 0xff 0x01 255 1
2147483647 0xff 0xff 0xff 0xff 0x07 255 255 255 255 7
-1 0xff 0xff 0xff 0xff 0x0f 255 255 255 255 15
-2147483648 0x80 0x80 0x80 0x80 0x08 128 128 128 128 8

示例VarLongs:

十六进制字节 十进制字节
0 0x00 0
1 0x01 1
2 0x02 2
127 0x7f 127
128 0x80 0x01 128 1
255 0xff 0x01 255 1
2147483647 0xff 0xff 0xff 0xff 0x07 255 255 255 255 7
9223372036854775807 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0x7f 255 255 255 255 255 255 255 255 127
-1 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0x01 255 255 255 255 255 255 255 255 255 1
-2147483648 0x80 0x80 0x80 0x80 0xf8 0xff 0xff 0xff 0xff 0x01 128 128 128 128 248 255 255 255 255 1
-9223372036854775808 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x01 128 128 128 128 128 128 128 128 128 1

位置

分隔位三个部分的64位值

  • x:26个最高位
  • z:26个中间位
  • y:12个最低位

如下编码:

((x & 0x3FFFFFF) << 38) | ((z & 0x3FFFFFF) << 12) | (y & 0xFFF)

并如下解码:

val = read_unsigned_long();
x = val >> 38;
y = val & 0xFFF;
z = (val << 26 >> 38);

注意:位移的细节由语言决定,上述内容可能在Java中可以工作但可能不会不经修改就能在其他语言中工作。实际上,你通常会接受到正数,即使实际的坐标是负的。这可以通过加入如下内容修复:

if x >= 2^25 { x -= 2^26 }
if y >= 2^11 { y -= 2^12 }
if z >= 2^25 { z -= 2^26 }

定点数

一些字段被存储为定点数,其中一定数量的为用于表示有符号整数部分(小数点左侧的数字),其余表示小数部分(小数点右侧)。浮点数(float和double),相反,将数字本身(尾数)存储在内存块中,而小数点(指数)的位置存储在其一边。

本质上,虽然定点数有着比浮点数更小的范围,但是对于较大值来说它们的小数精度要更胜一筹。这使得它们用于表示Minecraft实体的全局坐标非常理想,因为比起将它们精确地定位在一个方块(或米)中,准确地保存它的整数部分要重要得多。

坐标经常被表示为32位整数,其中5个最低位用于小数部分,其余存储整数部分。

Java缺乏对分数整数的直接支持,但是你可以使用整数来表示它们。要将double转换成这种整数表示方法,使用以下公式:

 abs_int = (int) (double * 32.0D);

以及反过来:

 double = (double) (abs_int / 32.0D);

粒子

字段名称 字段类型 含义
ID VarInt 粒子类型的ID,见下。
Data 可变 根据粒子类型可变,见下。
粒子名称 粒子ID 数据
minecraft:ambient_entity_effect 0
minecraft:angry_villager 1
minecraft:barrier 2
minecraft:block 3
字段名称 字段类型 含义
BlockState VarInt 方块状态的ID。
minecraft:bubble 4
minecraft:cloud 5
minecraft:crit 6
minecraft:damage_indicator 7
minecraft:dragon_breath 8
minecraft:dripping_lava 9
minecraft:falling_lava 10
minecraft:landing_lava 11
minecraft:dripping_water 12
minecraft:falling_water 13
minecraft:dust 14
字段名称 字段类型 含义
Red Float 红色值,0-1
Green Float 绿色值,0-1
Blue Float 蓝色值,0-1
Scale Float 缩放,会夹在0.01和4之间。
minecraft:effect 15
minecraft:elder_guardian 16
minecraft:enchanted_hit 17
minecraft:enchant 18
minecraft:end_rod 19
minecraft:entity_effect 20
minecraft:explosion_emitter 21
minecraft:explosion 22
minecraft:falling_dust 23
字段名称 字段类型 含义
BlockState VarInt 方块状态的ID。
minecraft:firework 24
minecraft:fishing 25
minecraft:flame 26
minecraft:flash 27
minecraft:happy_villager 28
minecraft:composter 29
minecraft:heart 30
minecraft:instant_effect 31
minecraft:item 32
字段名称 字段类型 含义
Item Slot 将要使用的物品。
minecraft:item_slime 33
minecraft:item_snowball 34
minecraft:large_smoke 35
minecraft:lava 36
minecraft:mycelium 37
minecraft:note 38
minecraft:poof 39
minecraft:portal 40
minecraft:rain 41
minecraft:smoke 42
minecraft:sneeze 43
minecraft:spit 44
minecraft:squid_ink 45
minecraft:sweep_attack 46
minecraft:totem_of_undying 47
minecraft:underwater 48
minecraft:splash 49
minecraft:witch 50
minecraft:bubble_pop 51
minecraft:current_down 52
minecraft:bubble_column_up 53
minecraft:nautilus 54
minecraft:dolphin 55
minecraft:campfire_cosy_smoke 56
minecraft:campfire_signal_smoke 57


其他定义

术语 定义
Player 当以单数使用时,玩家(Player)总是指代连接至服务端的客户端。
Entity 实体(Entity)指代任何物品、玩家、生物、矿车或船等,见Minecraft Wiki文章来获取完整列表。
EID EID — 或实体ID — 是一个用于区分特定实体的4字节序列。实体的EID在整个服务端中是唯一的。
XYZ 在本文档中,轴的名称于调试屏幕(F3)中显示的是一样的。Y指向上方,X指向东方,而Z指向南方。
Meter 米(Meter)是Minecraft中长度的基本单位,等于一个实心方块的棱长。术语“方块(block)”可能用来指“米”或“立方米”。
Global palette 映射非负整数为方块状态的表/字典/调色板。方块状态是根据分配顺序以线性方式创建的。一个方块状态ID分配给方块的每一个唯一方块状态,如果一个方块由多种属性,那么分配状态的数量是每一个状态的值数量之积。属性和状态ID范围的当前列表可以在此处找到:burger

或者,原版服务端现在包含一个到处当前方块状态ID映射的选项,通过运行java -cp minecraft_server.jar net.minecraft.data.Main --reports。更多信息见数据生成器

Notchian 由Mojang开发并发布的原版Minecraft的官方实现。

数据包格式

未经压缩

字段名称 字段类型 注释
Length VarInt 数据包数据的长度 + 数据包ID的长度
Packet ID VarInt
Data Byte Array 取决于连接状态和和数据包ID,见下面的部分

经压缩

一旦发送了设置压缩数据包(带有非负阈值),将为接下来的所有数据包启用zlib压缩。数据包的格式会略有变化,来包含未压缩数据包的大小。

压缩? 字段名称 字段类型 注释
Packet Length VarInt Data Length的长度 + (Packet ID + Data)的压缩长度
Data Length VarInt (Packet ID + Data)的未压缩长度或0
Packet ID VarInt zlib压缩的数据包ID(见下面的部分)
Data Byte Array zlib压缩的数据包数据(见下面的部分)

由Packet Length字段提供的长度是数据包中剩余的字节数,包括Data Length字段。

如果Data Length设置为0,那么该数据包是未压缩的,否则这就是未压缩数据包的大小。

如果压缩,(Packet ID + Data)的未压缩长度必须等于或大于数据包设置压缩数据包中的阈值,否则接收方将会断开连接。

压缩可以通过发送一个负阈值的设置压缩数据包来禁用,或从开始就不发送设置压缩数据包。

握手中

客户端方

在握手中(Handshaking)状态中没有客户端方的数据包,因为协议会在客户端发送第一个数据包的瞬间切换为别的状态。

服务端方

握手

这将会导致服务端切换为目标状态。

数据包ID 状态 绑定至 字段名称 字段类型 注释
0x00 握手中(Handshaking) 客户端 Protocol Version VarInt 数据包版本号(当前在1.14.4中为498)
Server Address String (255) 主机名或IP,如,localhost或127.0.0.1,用于连接。Notchian服务端不使用该信息,注意SRV记录是一个重定向,例如,如果_minecraft._tcp.example.com指向mc.example.org,用户连接至example.com会提供mc.example.org作为服务器地址并连接到它。
Server Port Unsigned Short 默认为25565。Notchian服务端不使用该信息。
Next State VarInt Enum 1表示状态,2表示登入

旧版服务端列表Ping

Warning.png 该数据包使用非标准的格式。它从不会是有长度前缀的,数据包ID是Unsigned Byte而不是VarInt。

虽然从技术上来说不是当前协议的一部分,旧版客户端还是可能会发送该数据包来初始化服务端列表Ping,所以现代服务端还是应该能正确地处理它。

数据包ID 状态 绑定至 字段名称 字段类型 注释
0xFE 握手中(Handshaking) 服务端 Payload Unsigned Byte 总是为1(0x01

有关跟随该数据包的细节见服务端列表Ping#1.6

游玩

客户端方

生成物体

当载具或其他物体创建时由服务端发送。

数据包ID 状态 绑定至 字段名称 字段类型 注释
0x00 游玩(Play) 客户端 Entity ID VarInt 物体的EID
Object UUID UUID
Type VarInt 物体的类型(与生成生物中的相同)
X Double
Y Double
Z Double
Pitch Angle
Yaw Angle
Data Int 意味着Type字段的值时独立的,详见物体数据
Velocity X Short 实体速度中相同的单位。总是发送,但只用在Data大于0时(除了一些总是会忽略它的实体,详见物体数据)。
Velocity Y Short
Velocity Z Short

生成经验球

生成一或多个经验球。

数据包ID 状态 绑定至 字段名称 字段类型 注释
0x01 游玩(Play) 客户端 Entity ID VarInt
X Double
Y Double
Z Double
Count Short 该经验球收集后会奖励的经验量。

生成全局实体

使用这个数据包,服务端会在玩家周围512格半径内发生雷击时通知客户端。坐标指定了雷击的确切位置。

数据包ID 状态 绑定至 字段名称 字段类型 注释
0x02 游玩(Play) 客户端 Entity ID VarInt 闪电的EID
Type Byte Enum 全局实体类型,当前对于闪电来说总是为1
X Double
Y Double
Z Double

生成生物

当生物实体生成时由服务端发送。

数据包ID 状态 绑定至 字段名称 字段类型 注释
0x03 游玩(Play) 客户端 Entity ID VarInt
Entity UUID UUID
Type VarInt 生物的类型。见实体#实体
X Double
Y Double
Z Double
Yaw Angle
Pitch Angle
Head Pitch Angle
Velocity X Short 实体速度相同的单位
Velocity Y Short 实体速度相同的单位
Velocity Z Short 实体速度相同的单位
Metadata 实体元数据

生成画

该数据包显示画的位置、名称和类型。

数据包ID 状态 绑定至 字段名称 字段类型 注释
0x04 游玩(Play) 客户端 Entity ID VarInt
Entity UUID UUID
Motive VarInt 画的ID,见下
Location Position 中心坐标(见下)
Direction Byte Enum 画面向的方向(North = 2,South = 0,West = 1,East = 3)

计算图像的中心:给定一个(width × height)的网格,(0, 0)为左上角,中心就是(max(0, width / 2 - 1), height / 2)。例如(1, 0)是2×1的画,或(1, 2)是4×4的画。

paintings_kristoffer_zetterstrand.png中按坐标排列的画列表(其中x和y是从左上角开始数的像素,而宽度和高度是一像素为单位或1/16格):

名称 ID x y 宽度 高度
minecraft:kebab 0 0 0 16 16
minecraft:aztec 1 16 0 16 16
minecraft:alban 2 32 0 16 16
minecraft:aztec2 3 48 0 16 16
minecraft:bomb 4 64 0 16 16
minecraft:plant 5 80 0 16 16
minecraft:wasteland 6 96 0 16 16
minecraft:pool 7 0 32 32 16
minecraft:courbet 8 32 32 32 16
minecraft:sea 9 64 32 32 16
minecraft:sunset 10 96 32 32 16
minecraft:creebet 11 128 32 32 16
minecraft:wanderer 12 0 64 16 32
minecraft:graham 13 16 64 16 32
minecraft:match 14 0 128 32 32
minecraft:bust 15 32 128 32 32
minecraft:stage 16 64 128 32 32
minecraft:void 17 96 128 32 32
skull_and_roses 18 128 128 32 32
minecraft:wither 19 160 128 32 32
minecraft:fighters 20 0 96 64 32
minecraft:pointer 21 0 192 64 64
minecraft:pigscene 22 64 192 64 64
minecraft:burning_skull 23 128 192 64 64
minecraft:skeleton 24 192 64 64 48
minecraft:donkey_kong 25 192 112 64 48

Minecraft Wiki上这篇有关画的文章也提供了画名称到实际图像的列表。

生成玩家

当玩家进入可见范围时,而不是玩家加入时,由服务端发送。

该数据包必须在生成玩家时用于服务端添加玩家数据的玩家信息数据包之后发送。如果当该数据包到达时还不存在由该数据包生成的玩家信息,那么Notchian客户端将不会生成该玩家实体。玩家信息数据包包含皮肤/披风数据。

虽然服务器可以为不在可见范围内的玩家安全地生成玩家实体,客户端看起来也能正确地处理它。

数据包ID 状态 绑定至 字段名称 字段类型 注释
0x05 游玩(Play) 客户端 Entity ID VarInt 玩家的EID
Player UUID UUID 见下方有关离线模式和NPC的注释
X Double
Y Double
Z Double
Yaw Angle
Pitch Angle
Metadata 实体元数据

当处于在线模式时,UUID必须有效且拥有有效的皮肤信息。

当处于离线模式时,UUID v3会与以UTF-8编码(大小写敏感)的字符串OfflinePlayer:<player name>一起使用。

而对于NPC会使用UUID v2。注释:

<+Grum> i will never confirm this as a feature you know that :)
<+Grum> 我觉得这是你绝对不会知道的特性:)

在一个示例UUID(xxxxxxxx-xxxx-Yxxx-xxxx-xxxxxxxxxxxx)中,UUID版本由Y指定。所以,对于UUID v3,Y总是为3,而对于UUID v2,Y将总是为2

动画(客户端方)

子啊无论何时实体应改变动画时发送。

数据包ID 状态 绑定至 字段名称 字段类型 注释
0x06 游玩(Play) 客户端 Entity ID VarInt 玩家ID
Animation Unsigned Byte 动画ID(见下)

动画可以时下列值中的一个:

ID 动画
0 摇摆主手
1 受到伤害
2 离开床
3 摇摆副手
4 暴击
5 魔法暴击效果

统计数据

作为对客户端状态0x04(id 1)的响应发送。

数据包ID 状态 绑定至 字段名称 字段类型 注释
0x07 游玩(Play) 客户端 Count VarInt 后续数组的元素数
Statistic Category ID Array VarInt 见下
Statistic ID VarInt 见下
Value VarInt 将它设置为的量

类别(这些是带命名空间的,但是将其中的:替换成了.):

名称 ID 注册项
minecraft.mined 0 Blocks
minecraft.crafted 1 Items
minecraft.used 2 Items
minecraft.broken 3 Items
minecraft.picked_up 4 Items
minecraft.dropped 5 Items
minecraft.killed 6 Entities
minecraft.killed_by 7 Entities
minecraft.custom 8 Custom

方块、物品和实体会使用方块(非方块状态)、物品和实体ID。

Custom拥有以下内容(单位只对客户端有影响):

名称 ID 单位
minecraft.leave_game 0
minecraft.play_one_minute 1 时间
minecraft.time_since_death 2 时间
minecraft.sneak_Time 3 时间
minecraft.walk_one_cm 4 距离
minecraft.crouch_one_cm 5 距离
minecraft.sprint_one_cm 6 距离
minecraft.swim_one_cm 7 距离
minecraft.fall_one_cm 8 距离
minecraft.climb_one_cm 9 距离
minecraft.fly_one_cm 10 距离
minecraft.dive_one_cm 11 距离
minecraft.minecart_one_cm 12 距离
minecraft.boat_one_cm 13 距离
minecraft.pig_one_cm 14 距离
minecraft.horse_one_cm 15 距离
minecraft.aviate_one_cm 16 距离
minecraft.jump 17
minecraft.drop 18
minecraft.damage_dealt 19 伤害
minecraft.damage_taken 20 伤害
minecraft.deaths 21
minecraft.mob_kills 22
minecraft.animals_bred 23
minecraft.player_kills 24
minecraft.fish_caught 25
minecraft.talked_to_villager 26
minecraft.traded_with_villager 27
minecraft.eat_cake_slice 28
minecraft.fill_cauldron 29
minecraft.use_cauldron 30
minecraft.clean_armor 31
minecraft.clean_banner 32
minecraft.interact_with_brewingstand 33
minecraft.interact_with_beacon 34
minecraft.inspect_dropper 35
minecraft.inspect_hopper 36
minecraft.inspect_dispenser 37
minecraft.play_noteblock 38
minecraft.tune_noteblock 39
minecraft.pot_flower 40
minecraft.trigger_trapped_chest 41
minecraft.open_enderchest 42
minecraft.enchant_item 43
minecraft.play_record 44
minecraft.interact_with_furnace 45
minecraft.interact_with_crafting_table 46
minecraft.open_chest 47
minecraft.sleep_in_bed 48
minecraft.open_shulker_box 49

单位:

  • 无:只是一个正常的数字(格式化为0个小数位)
  • 伤害:数值是十倍于正常量
  • 距离:以厘米为单位的距离(百分之一格)
  • 时间:以游戏刻为单位的时间跨度

方块破坏动画

0–9时可以显示的破坏阶段,而其他的数字代表在该坐标上没有动画。

方块破坏动画也用应用于空气上,尽管没有方块正在被破坏,但动画仍然是可见的。然而,如果将其应用于透明的方块上时,会发生古怪的图像效果,包括水会丢失它的透明。(类似于正常游玩过程中破坏冰块的效果)

如果你需要在同一时间显示多个破坏动画,那么你需要给它们每个一个唯一的实体ID。该实体ID不需要与客户端中的实际实体对应,就算使用随机生成的数字也是有效的。

数据包ID 状态 绑定至 字段名称 字段类型 注释
0x08 游玩(Play) 客户端 Entity ID VarInt 破坏方块的实体ID
Location Position 方块位置
Destroy Stage Byte 0–9来设置它,而其他值移除它

更新方块实体

Sets the block entity associated with the block at the given location.

Packet ID State Bound To Field Name Field Type Notes
0x09 Play Client Location Position
Action Unsigned Byte The type of update to perform, see below
NBT Data NBT Tag Data to set. May be a TAG_END (0), in which case the block entity at the given location is removed (though this is not required since the client will remove the block entity automatically on chunk unload or block removal)

Action field:

  • 1: Set data of a mob spawner (everything except for SpawnPotentials: current delay, min/max delay, mob to be spawned, spawn count, spawn range, etc.)
  • 2: Set command block text (command and last execution status)
  • 3: Set the level, primary, and secondary powers of a beacon
  • 4: Set rotation and skin of mob head
  • 5: Declare a conduit
  • 6: Set base color and patterns on a banner
  • 7: Set the data for a Structure tile entity
  • 8: Set the destination for a end gateway
  • 9: Set the text on a sign
  • 10: Unused
  • 11: Declare a bed
  • 12: Set data of a jigsaw block
  • 13: Set items in a campfire

方块动作

This packet is used for a number of actions and animations performed by blocks, usually non-persistent.

See Block Actions for a list of values.

Warning.png This packet uses a block ID, not a block state. Unfortunately, block IDs are not directly included in the output from Data Generators, but can manually be calculated.

Packet ID State Bound To Field Name Field Type Notes
0x0A Play Client Location Position Block coordinates
Action ID (Byte 1) Unsigned Byte Varies depending on block — see Block Actions
Action Param (Byte 2) Unsigned Byte Varies depending on block — see Block Actions
Block Type VarInt The block type ID for the block. This must match the block at the given coordinates.

方块更改

Fired whenever a block is changed within the render distance.

Warning.png Changing a block in a chunk that is not loaded is not a stable action. The Notchian client currently uses a shared empty chunk which is modified for all block changes in unloaded chunks; while in 1.9 this chunk never renders in older versions the changed block will appear in all copies of the empty chunk. Servers should avoid sending block changes in unloaded chunks and clients should ignore such packets.

Packet ID State Bound To Field Name Field Type Notes
0x0B Play Client Location Position Block Coordinates
Block ID VarInt The new block state ID for the block as given in the global palette. See that section for more information.

Boss条

Packet ID State Bound To Field Name Field Type Notes
0x0C Play Client UUID UUID Unique ID for this bar
Action VarInt Enum Determines the layout of the remaining packet
Action Field Name
0: add Title Chat
Health Float From 0 to 1. Values greater than 1 do not crash a Notchian client, and start rendering part of a second health bar at around 1.5.
Color VarInt Enum Color ID (see below)
Division VarInt Enum Type of division (see below)
Flags Unsigned Byte Bit mask. 0x1: should darken sky, 0x2: is dragon bar (used to play end music), 0x04: create fog (previously was also controlled by 0x02)
1: remove no fields no fields Removes this boss bar
2: update health Health Float as above
3: update title Title Chat
4: update style Color VarInt Enum Color ID (see below)
Dividers VarInt Enum as above
5: update flags Flags Unsigned Byte as above
ID Color
0 Pink
1 Blue
2 Red
3 Green
4 Yellow
5 Purple
6 White
ID Type of division
0 No division
1 6 notches
2 10 notches
3 12 notches
4 20 notches

服务端难度

Changes the difficulty setting in the client's option menu

Packet ID State Bound To Field Name Field Type Notes
0x0D Play Client Difficulty Unsigned Byte 0: peaceful, 1: easy, 2: normal, 3: hard
Difficulty locked? Boolean

聊天消息(客户端方)

Identifying the difference between Chat/System Message is important as it helps respect the user's chat visibility options. See processing chat for more info about these positions.

Warning.png Game info accepts json formatting but does not display it, although the deprecated §-based formatting works. This is not an issue when using the Title packet, so prefer that packet for displaying information in that slot. See MC-119145 for more information.

Packet ID State Bound To Field Name Field Type Notes
0x0E Play Client JSON Data Chat Limited to 32767 bytes
Position Byte 0: chat (chat box), 1: system message (chat box), 2: game info (above hotbar).

多个方块更改

Fired whenever 2 or more blocks are changed within the same chunk on the same tick.

Warning.png Changing blocks in chunks not loaded by the client is unsafe (see note on Block Change).

Packet ID State Bound To Field Name Field Type Notes
0x0F Play Client Chunk X Int Chunk X coordinate
Chunk Z Int Chunk Z coordinate
Record Count VarInt Number of elements in the following array, i.e. the number of blocks affected
Record Horizontal Position Array Unsigned Byte The 4 most significant bits (0xF0) encode the X coordinate, relative to the chunk. The 4 least significant bits (0x0F) encode the Z coordinate, relative to the chunk.
Y Coordinate Unsigned Byte Y coordinate of the block
Block ID VarInt The new block state ID for the block as given in the global palette. See that section for more information.

To decode the position into a world position:

worldX = (horizPos >> 4 & 15) + (chunkX * 16);
worldY = vertPos;
worldZ = (horizPos & 15) + (chunkZ * 16);

Tab补全(客户端方)

The server responds with a list of auto-completions of the last word sent to it. In the case of regular chat, this is a player username. Command names and parameters are also supported. The client sorts these alphabetically before listing them.

Packet ID State Bound To Field Name Field Type Notes
0x10 Play Client
ID VarInt Transaction ID
Start VarInt Start of the text to replace
Length VarInt Length of the text to replace
Count VarInt Number of elements in the following array
Matches Match Array String (32767) One eligible value to insert, note that each command is sent separately instead of in a single string, hence the need for Count. Note that for instance this doesn't include a leading / on commands.
Has tooltip Boolean True if the following is present
Tooltip Optional Chat Tooltip to display; only present if previous boolean is true

声明命令

Lists all of the commands on the server, and how they are parsed.

This is a directed graph, with one root node. Each redirect or child node must refer only to nodes that have already been declared.

Packet ID State Bound To Field Name Field Type Notes
0x11 Play Client Count VarInt Number of elements in the following array
Nodes Array of Node An array of nodes
Root index VarInt Index of the root node in the previous array

For more information on this packet, see the Command Data article.

确认交互(客户端方)

A packet from the server indicating whether a request from the client was accepted, or whether there was a conflict (due to lag). If the packet was not accepted, the client must respond with a serverbound confirm transaction packet.

Packet ID State Bound To Field Name Field Type Notes
0x12 Play Client Window ID Byte The ID of the window that the action occurred in
Action Number Short Every action that is to be accepted has a unique number. This number is an incrementing integer (starting at 0) with separate counts for each window ID.
Accepted Boolean Whether the action was accepted

关闭窗口(客户端方)

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.

Packet ID State Bound To Field Name Field Type Notes
0x13 Play Client Window ID Unsigned Byte This is the ID of the window that was closed. 0 for inventory.

窗口物品

The inventory slots

Sent by the server when items in multiple slots (in a window) are added/removed. This includes the main inventory, equipped armour and crafting slots.

Packet ID State Bound To Field Name Field Type Notes
0x14 Play Client Window ID Unsigned Byte The ID of window which items are being sent for. 0 for player inventory.
Count Short Number of elements in the following array
Slot Data Array of Slot

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

窗口属性

This packet is used to inform the client that part of a GUI window should be updated.

Packet ID State Bound To Field Name Field Type Notes
0x15 Play Client Window ID Unsigned Byte
Property Short The property to be updated, see below
Value Short The new value for the property, see below

The meaning of the Property field depends on the type of the window. The following table shows the known combinations of window type and property, and how the value is to be interpreted.

Window type Property Value
Furnace 0: Fire icon (fuel left) counting from fuel burn time down to 0 (in-game ticks)
1: Maximum fuel burn time fuel burn time or 0 (in-game ticks)
2: Progress arrow counting from 0 to maximum progress (in-game ticks)
3: Maximum progress always 200 on the notchian server
Enchantment Table 0: Level requirement for top enchantment slot The enchantment's xp level requirement
1: Level requirement for middle enchantment slot
2: Level requirement for bottom enchantment slot
3: The enchantment seed Used for drawing the enchantment names (in SGA) clientside. The same seed is used to calculate enchantments, but some of the data isn't sent to the client to prevent easily guessing the entire list (the seed value here is the regular seed bitwise and 0xFFFFFFF0).
4: Enchantment ID shown on mouse hover over top enchantment slot The enchantment id (set to -1 to hide it), see below for values
5: Enchantment ID shown on mouse hover over middle enchantment slot
6: Enchantment ID shown on mouse hover over bottom enchantment slot
7: Enchantment level shown on mouse hover over the top slot The enchantment level (1 = I, 2 = II, 6 = VI, etc.), or -1 if no enchant
8: Enchantment level shown on mouse hover over the middle slot
9: Enchantment level shown on mouse hover over the bottom slot
Beacon 0: Power level 0-4, controls what effect buttons are enabled
1: First potion effect Potion effect ID for the first effect, or -1 if no effect
2: Second potion effect Potion effect ID for the second effect, or -1 if no effect
Anvil 0: Repair cost The repair's cost in xp levels
Brewing Stand 0: Brew time 0 – 400, with 400 making the arrow empty, and 0 making the arrow full
1: Fuel time 0 - 20, with 0 making the arrow empty, and 20 making the arrow full

For an enchanting table, the following numerical IDs are used:

Numerical ID Enchantment ID Enchantment Name
0 minecraft:protection Protection
1 minecraft:fire_protection Fire Protection
2 minecraft:feather_falling Feather Falling
3 minecraft:blast_protection Blast Protection
4 minecraft:projectile_protection Projectile Protection
5 minecraft:respiration Respiration
6 minecraft:aqua_affinity Aqua Affinity
7 minecraft:thorns Thorns
8 minecraft:depth_strider Depth Strider
9 minecraft:frost_walker Frost Walker
10 minecraft:binding_curse Curse of Binding
11 minecraft:sharpness Sharpness
12 minecraft:smite Smite
13 minecraft:bane_of_arthropods Bane of Arthropods
14 minecraft:knockback Knockback
15 minecraft:fire_aspect Fire Aspect
16 minecraft:looting Looting
17 minecraft:sweeping Sweeping Edge
18 minecraft:efficiency Efficiency
19 minecraft:silk_touch Silk Touch
20 minecraft:unbreaking Unbreaking
21 minecraft:fortune Fortune
22 minecraft:power Power
23 minecraft:punch Punch
24 minecraft:flame Flame
25 minecraft:infinity Infinity
26 minecraft:luck_of_the_sea Luck of the Sea
27 minecraft:lure Lure
28 minecraft:loyalty Loyalty
29 minecraft:impaling Impaling
30 minecraft:riptide Riptide
31 minecraft:channeling Channeling
32 minecraft:mending Mending
33 minecraft:vanishing_curse Curse of Vanishing

设置槽

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

Packet ID State Bound To Field Name Field Type Notes
0x16 Play Client Window ID Byte 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 The slot that should be updated
Slot Data Slot

To set the cursor (the item currently dragged with the mouse), use -1 as Window ID and as Slot.

This packet can only be used to edit the hotbar of the player's inventory if window ID is set to 0 (slots 36 through 44). If the window ID is set to -2, then any slot in the inventory can be used but no add item animation will be played.

设置冷却

Applies a cooldown period to all items with the given type. Used by the Notchian server with enderpearls. This packet should be sent when the cooldown starts and also when the cooldown ends (to compensate for lag), although the client will end the cooldown automatically. Can be applied to any item, note that interactions still get sent to the server with the item but the client does not play the animation nor attempt to predict results (i.e block placing).

Packet ID State Bound To Field Name Field Type Notes
0x17 Play Client Item ID VarInt Numeric ID of the item to apply a cooldown to.
Cooldown Ticks VarInt Number of ticks to apply a cooldown for, or 0 to clear the cooldown.

插件消息(客户端方)

Main article: Plugin channels

Mods and plugins can use this to send their data. Minecraft itself uses several plugin channels. These internal channels are in the minecraft namespace.

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

Packet ID State Bound To Field Name Field Type Notes
0x18 Play Client Channel Identifier Name of the plugin channel used to send the data
Data Byte Array Any data, depending on the channel. minecraft: channels are documented here. The length of this array must be inferred from the packet length.

命名声音效果

See also: #Sound Effect

Used to play a sound effect on the client. Custom sounds may be added by resource packs.

Packet ID State Bound To Field Name Field Type Notes
0x19 Play Client Sound Name Identifier All sound effect names as of 1.14.4 can be seen here.
Sound Category VarInt Enum The category that this sound will be played from (current categories)
Effect Position X Int Effect X multiplied by 8 (fixed-point number with only 3 bits dedicated to the fractional part)
Effect Position Y Int Effect Y multiplied by 8 (fixed-point number with only 3 bits dedicated to the fractional part)
Effect Position Z Int Effect Z multiplied by 8 (fixed-point number with only 3 bits dedicated to the fractional part)
Volume Float 1 is 100%, can be more
Pitch Float Float between 0.5 and 2.0 by Notchian clients

断开连接(游玩)

Sent by the server before it disconnects a client. The client assumes that the server has already closed the connection by the time the packet arrives.

Packet ID State Bound To Field Name Field Type Notes
0x1A Play Client Reason Chat Displayed to the client when the connection terminates.

实体状态

Entity statuses generally trigger an animation for an entity. The available statuses vary by the entity's type (and are available to subclasses of that type as well).

Packet ID State Bound To Field Name Field Type Notes
0x1B Play Client Entity ID Int
Entity Status Byte Enum See below

See Entity statuses for a list of which statuses are valid for each type of entity.

爆炸

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

Each block in Records is set to air. Coordinates for each axis in record is int(X) + record.x

Packet ID State Bound To Field Name Field Type Notes
0x1C Play Client X Float
Y Float
Z Float
Radius Float Currently unused in the client
Record Count Int Number of elements in the following array
Records Array of (Byte, Byte, Byte) Each record is 3 signed bytes long, each bytes are the XYZ (respectively) offsets of affected blocks.
Player Motion X Float X velocity of the player being pushed by the explosion
Player Motion Y Float Y velocity of the player being pushed by the explosion
Player Motion Z Float Z velocity of the player being pushed by the explosion

卸载区块

Tells the client to unload a chunk column.

Packet ID State Bound To Field Name Field Type Notes
0x1D Play Client Chunk X Int Block coordinate divided by 16, rounded down
Chunk Z Int Block coordinate divided by 16, rounded down

It is legal to send this packet even if the given chunk is not currently loaded.

更改游戏状态

Used for a wide variety of game state things, from whether to bed use to gamemode to demo messages.

Packet ID State Bound To Field Name Field Type Notes
0x1E Play Client Reason Unsigned Byte See below
Value Float Depends on Reason

Reason codes:

Reason Effect Value
0 Invalid Bed Would be used to switch between messages, but the only used message is 0 for invalid bed
1 End raining
2 Begin raining
3 Change gamemode 0: Survival, 1: Creative, 2: Adventure, 3: Spectator
4 Exit end 0: Immediately send Client Status of respawn without showing end credits; 1: Show end credits and respawn at the end (or when esc is pressed). 1 is sent if the player has not yet received the "The end?" advancement, while if they do have it 0 is used.
5 Demo message 0: Show welcome to demo screen, 101: Tell movement controls, 102: Tell jump control, 103: Tell inventory control
6 Arrow hitting player Appears to be played when an arrow strikes another player in Multiplayer
7 Fade value The current darkness value. 1 = Dark, 0 = Bright, Setting the value higher causes the game to change color and freeze
8 Fade time Time in ticks for the sky to fade
9 Play pufferfish sting sound
10 Play elder guardian mob appearance (effect and sound)

打开马窗口

This packet is used exclusively for opening the horse GUI. Open Window is used for all other GUIs.

Packet ID State Bound To Field Name Field Type Notes
0x1F Play Client Window ID? Byte
Number of slots? VarInt
Entity ID? Integer

Keep Alive(客户端)

The server will frequently send out a keep-alive, each containing a random ID. The client must respond with the same packet. If the client does not respond to them for over 30 seconds, the server kicks the client. Vice versa, if the server does not send any keep-alives for 20 seconds, the client will disconnect and yields a "Timed out" exception.

The Notchian server uses a system-dependent time in milliseconds to generate the keep alive ID value.

Packet ID State Bound To Field Name Field Type Notes
0x20 Play Client Keep Alive ID Long

区块数据

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
0x21 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)
Full chunk 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).
Heightmaps NBT Compound containing one long array named MOTION_BLOCKING, which is a heightmap for the highest solid block at each position in the chunk (as a compacted long array with 256 entries at 9 bits per entry totaling 36 longs). The Notchian server also adds a WORLD_SURFACE long array, the purpose of which is unknown, but it's not required for the chunk to be accepted.
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.

Note that the Notchian client requires an Update View Position packet when it crosses a chunk border, otherwise it'll only display render distance + 2 chunks around the chunk it spawned in.

效果

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

By default, the Minecraft client adjusts the volume of sound effects based on distance. The final boolean field is used to disable this, and instead the effect is played from 2 blocks away in the correct direction. Currently this is only used for effect 1023 (wither spawn) and effect 1028 (enderdragon death); it is ignored on other effects.

Packet ID State Bound To Field Name Field Type Notes
0x22 Play Client Effect ID Int The ID of the effect, see below
Location Position The location of the effect
Data Int Extra data for certain effects, see below
Disable Relative Volume Boolean See above

Effect IDs:

ID Name Data
Sound
1000 Dispenser dispenses
1001 Dispenser fails to dispense
1002 Dispenser shoots
1003 Ender eye launched
1004 Firework shot
1005 Iron door opened
1006 Wooden door opened
1007 Wooden trapdoor opened
1008 Fence gate opened
1009 Fire extinguished
1010 Play record Special case, see below for more info
1011 Iron door closed
1012 Wooden door closed
1013 Wooden trapdoor closed
1014 Fence gate closed
1015 Ghast warns
1016 Ghast shoots
1017 Enderdragon shoots
1018 Blaze shoots
1019 Zombie attacks wood door
1020 Zombie attacks iron door
1021 Zombie breaks wood door
1022 Wither breaks block
1023 Wither spawned
1024 Wither shoots
1025 Bat takes off
1026 Zombie infects
1027 Zombie villager converted
1028 Ender dragon death
1029 Anvil destroyed
1030 Anvil used
1031 Anvil landed
1032 Portal travel
1033 Chorus flower grown
1034 Chorus flower died
1035 Brewing stand brewed
1036 Iron trapdoor opened
1037 Iron trapdoor closed
Particle
2000 Spawns 10 smoke particles, e.g. from a fire Direction, see below
2001 Block break + block break sound Block state, as an index into the global palette
2002 Splash potion. Particle effect + glass break sound. Potion ID
2003 Eye of Ender entity break animation — particles and sound
2004 Mob spawn particle effect: smoke + flames
2005 Bonemeal particles How many particles to spawn (if set to 0, 15 are spawned)
2006 Dragon breath
2007 Instant splash potion Potion ID
3000 End gateway spawn
3001 Enderdragon growl

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

Play record: This is actually a special case within this packet. You can start/stop a record at a specific location. Use a valid Record ID to start a record (or overwrite a currently playing one), any other value will stop the record. See Data Generators for information on item IDs.

粒子

Displays the named particle

Packet ID State Bound To Field Name Field Type Notes
0x23 Play Client Particle ID Int The particle ID listed in the particle data type.
Long Distance Boolean If true, particle distance increases from 256 to 65536
X Float X position of the particle
Y Float Y position of the particle
Z Float Z position of the particle
Offset X Float This is added to the X position after being multiplied by random.nextGaussian()
Offset Y Float This is added to the Y position after being multiplied by random.nextGaussian()
Offset Z Float This is added to the Z position after being multiplied by random.nextGaussian()
Particle Data Float The data of each particle
Particle Count Int The number of particles to create
Data Varies The variable data listed in the particle data type.

更新光照

Updates light levels for a chunk.

Packet ID State Bound To Field Name Field Type Notes
0x24 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
Empty Sky Light Mask VarInt Mask containing 18 bits, which indicates sections that have 0 for all their sky light values. If a section is set in both this mask and the main sky light mask, it is ignored for this mask and it is included in the sky light arrays (the notchian server does not create such masks). If it is only set in this mask, it is not included in the sky light arrays.
Empty Block Light Mask VarInt Mask containing 18 bits, which indicates sections that have 0 for all their block light values. If a section is set in both this mask and the main block light mask, it is ignored for this mask and it is included in the block light arrays (the notchian server does not create such masks). If it is only set in this mask, it is not included in the block light arrays.
Sky Light arrays Length Array VarInt Length of the following array in bytes (always 2048)
Sky Light array Array 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 Length Array VarInt Length of the following array in bytes (always 2048)
Block Light array Array 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.

加入游戏

See Protocol Encryption for information on logging in.

Packet ID State Bound To Field Name Field Type Notes
0x25 Play Client Entity ID Int The player's Entity ID (EID)
Gamemode Unsigned Byte 0: Survival, 1: Creative, 2: Adventure, 3: Spectator. Bit 3 (0x8) is the hardcore flag.
Dimension Int Enum -1: Nether, 0: Overworld, 1: End; also, note that this is not a VarInt but instead a regular int.
Max Players Unsigned Byte Was once used by the client to draw the player list, but now is ignored
Level Type String Enum (16) default, flat, largeBiomes, amplified, customized, buffet, default_1_1
View Distance VarInt Render distance (2-32)
Reduced Debug Info Boolean If true, a Notchian client shows reduced information on the debug screen. For servers in development, this should almost always be false.

地图数据

Updates a rectangular area on a map item.

Packet ID State Bound To Field Name Field Type Notes
0x26 Play Client Map ID VarInt Map ID of the map being modified
Scale Byte From 0 for a fully zoomed-in map (1 block per pixel) to 4 for a fully zoomed-out map (16 blocks per pixel)
Tracking Position Boolean Specifies whether player and item frame icons are shown
Locked Boolean True if the map has been locked in a cartography table
Icon Count VarInt Number of elements in the following array
Icon Type Array VarInt enum See below
X Byte Map coordinates: -128 for furthest left, +127 for furthest right
Z Byte Map coordinates: -128 for highest, +127 for lowest
Direction Byte 0-15
Has Display Name Boolean
Display Name Optional Chat Only present if previous Boolean is true
Columns Unsigned Byte Number of columns updated
Rows Optional Byte Only if Columns is more than 0; number of rows updated
X Optional Byte Only if Columns is more than 0; x offset of the westernmost column
Z Optional Byte Only if Columns is more than 0; z offset of the northernmost row
Length Optional VarInt Only if Columns is more than 0; length of the following array
Data Optional Array of Unsigned Byte Only if Columns is more than 0; see Map item format

For icons, a direction of 0 is a vertical icon and increments by 22.5° (360/16).

Types are based off of rows and columns in map_icons.png:

Icon type Result
0 White arrow (players)
1 Green arrow (item frames)
2 Red arrow
3 Blue arrow
4 White cross
5 Red pointer
6 White circle (off-map players)
7 Small white circle (far-off-map players)
8 Mansion
9 Temple
10 White Banner
11 Orange Banner
12 Magenta Banner
13 Light Blue Banner
14 Yellow Banner
15 Lime Banner
16 Pink Banner
17 Gray Banner
18 Light Gray Banner
19 Cyan Banner
20 Purple Banner
21 Blue Banner
22 Brown Banner
23 Green Banner
24 Red Banner
25 Black Banner
26 Treasure marker

交易列表

The list of trades a villager NPC is offering.

Packet ID State Bound To Field Name Field Type Notes
0x27 Play Client
Window ID VarInt The ID of the window that is open; this is an int rather than a byte.
Size Byte The number of trades in the following array
Trades Input item 1 Array Slot The first item the villager is buying
Output item Slot The item the villager is selling
Has second item Boolean Whether there is a second item
Input item 2 Optional Slot The second item the villager is buying; only present if they have a second item.
Trade disabled Boolean True if the trade is disabled; false if the trade is enabled.
Number of trade uses Integer Number of times the trade has been used so far
Maximum number of trade uses Integer Number of times this trade can be used
XP Integer
Special Price Integer
Price Multiplier Float
Demand Integer
Villager level VarInt Appears on the trade GUI; meaning comes from the translation key merchant.level. + level.

1: Novice, 2: Apprentice, 3: Journeyman, 4: Expert, 5: Master

Experience VarInt Total experience for this villager (always 0 for the wandering trader)
Is regular villager Boolean True if this is a regular villager; false for the wandering trader. When false, hides the villager level and some other GUI elements.
Can restock Boolean True for regular villagers and false for the wandering trader. If true, the "Villagers restock up to two times per day." message is displayed when hovering over disabled trades.
The merchant UI, for reference

实体相对移动

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

This packet allows at most 8 blocks movement in any direction, because short range is from -32768 to 32767. And 32768 / (128 * 32) = 8.

Packet ID State Bound To Field Name Field Type Notes
0x28 Play Client Entity ID VarInt
Delta X Short Change in X position as (currentX * 32 - prevX * 32) * 128
Delta Y Short Change in Y position as (currentY * 32 - prevY * 32) * 128
Delta Z Short Change in Z position as (currentZ * 32 - prevZ * 32) * 128
On Ground Boolean

实体外观和相对移动

This packet is sent by the server when an entity rotates and moves. Since a short range is limited from -32768 to 32767, and movement is offset of fixed-point numbers, this packet allows at most 8 blocks movement in any direction. (-32768 / (32 * 128) == -8)

Packet ID State Bound To Field Name Field Type Notes
0x29 Play Client Entity ID VarInt
Delta X Short Change in X position as (currentX * 32 - prevX * 32) * 128
Delta Y Short Change in Y position as (currentY * 32 - prevY * 32) * 128
Delta Z Short Change in Z position as (currentZ * 32 - prevZ * 32) * 128
Yaw Angle New angle, not a delta
Pitch Angle New angle, not a delta
On Ground Boolean

实体外观

This packet is sent by the server when an entity rotates.

Packet ID State Bound To Field Name Field Type Notes
0x2A Play Client Entity ID VarInt
Yaw Angle New angle, not a delta
Pitch Angle New angle, not a delta
On Ground Boolean

实体

This packet may be used to initialize an entity.

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 State Bound To Field Name Field Type Notes
0x2B Play Client Entity ID VarInt

载具移动(客户端方)

Note that all fields use absolute positioning and do not allow for relative positioning.

Packet ID State Bound To Field Name Field Type Notes
0x2C Play Client X Double Absolute position (X coordinate)
Y Double Absolute position (Y coordinate)
Z Double Absolute position (Z coordinate)
Yaw Float Absolute rotation on the vertical axis, in degrees
Pitch Float Absolute rotation on the horizontal axis, in degrees

打开书

Sent when a player right clicks with a signed book. This tells the client to open the book GUI.

Packet ID State Bound To Field Name Field Type Notes
0x2D Play Client Hand VarInt enum 0: Main hand, 1: Off hand

打开窗口

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. For horses, use Open Horse Window.

Packet ID State Bound To Field Name Field Type Notes
0x2E Play Client Window ID VarInt A unique id number for the window to be displayed. Notchian server implementation is a counter, starting at 1.
Window Type VarInt The window type to use for display. Contained in the minecraft:menu regisry; see Inventory for the different values.
Window Title Chat The title of the window

打开告示牌编辑器

Sent when the client has placed a sign and is allowed to send Update Sign. There must already be a sign at the given location (which the client does not do automatically) - send a Block Change first.

Packet ID State Bound To Field Name Field Type Notes
0x2F Play Client Location Position

合成配方响应

Response to the serverbound packet (Craft Recipe Request), with the same recipe ID. Appears to be used to notify the UI.

Packet ID State Bound To Field Name Field Type Notes
0x30 Play Client Window ID Byte
Recipe Identifier A recipe ID

玩家能力(客户端方)

The latter 2 floats are used to indicate the field of view and flying speed respectively, while the first byte is used to determine the value of 4 booleans.

Packet ID State Bound To Field Name Field Type Notes
0x31 Play Client Flags Byte Bit field, see below
Flying Speed Float 0.05 by default
Field of View Modifier Float Modifies the field of view, like a speed potion. A Notchian server will use the same value as the movement speed sent in the Entity Properties packet, which defaults to 0.1 for players.

About the flags:

Field Bit
Invulnerable 0x01
Flying 0x02
Allow Flying 0x04
Creative Mode (Instant Break) 0x08

战斗事件

Packet ID State Bound To Field Name Field Type Notes
0x32 Play Client Event VarInt Enum Determines the layout of the remaining packet
Event Field Name
0: enter combat no fields no fields
1: end combat Duration VarInt
Entity ID Int
2: entity dead Player ID VarInt
Entity ID Int
Message Chat

玩家信息

Sent by the server to update the user list (<tab> in the client).

Packet ID State Bound To Field Name Field Type Notes
0x33 Play Client Action VarInt Determines the rest of the Player format after the UUID
Number Of Players VarInt Number of elements in the following array
Player UUID Array UUID
Action Field Name
0: add player Name String (16)
Number Of Properties VarInt Number of elements in the following array
Property Name Array String (32767)
Value String (32767)
Is Signed Boolean
Signature Optional String (32767) Only if Is Signed is true
Gamemode VarInt
Ping VarInt Measured in milliseconds
Has Display Name Boolean
Display Name Optional Chat Only if Has Display Name is true
1: update gamemode Gamemode VarInt
2: update latency Ping VarInt Measured in milliseconds
3: update display name Has Display Name Boolean
Display Name Optional Chat Only send if Has Display Name is true
4: remove player no fields no fields

The Property field looks as in the response of Mojang API#UUID -> Profile + Skin/Cape, except of course using the protocol format instead of JSON. That is, each player will usually have one property with Name “textures” and Value being a base64-encoded JSON string as documented at Mojang API#UUID -> Profile + Skin/Cape. An empty properties array is also acceptable, and will cause clients to display the player with one of the two default skins depending on UUID.

Ping values correspond with icons in the following way:

  • A ping that negative (i.e. not known to the server yet) will result in the no connection icon.
  • A ping under 150 milliseconds will result in 5 bars
  • A ping under 300 milliseconds will result in 4 bars
  • A ping under 600 milliseconds will result in 3 bars
  • A ping under 1000 milliseconds (1 second) will result in 2 bars
  • A ping greater than or equal to 1 second will result in 1 bar.

面向玩家

Used to rotate the client player to face the given location or entity (for /teleport [<targets>] <x> <y> <z> facing).

Packet ID State Bound To Field Name Field Type Notes
0x34 Play Client
Feet/eyes VarInt enum Values are feet=0, eyes=1. If set to eyes, aims using the head position; otherwise aims using the feet position.
Target x Double x coordinate of the point to face towards
Target y Double y coordinate of the point to face towards
Target z Double z coordinate of the point to face towards
Is entity Boolean If true, additional information about an entity is provided.
Entity ID Optional VarInt Only if is entity is true — the entity to face towards
Entity feet/eyes Optional VarInt enum Whether to look at the entity's eyes or feet. Same values and meanings as before, just for the entity's head/feet.

If the entity given by entity ID cannot be found, this packet should be treated as if is entity was false.

玩家位置和外观(客户端方)

Updates the player's position on the server. This packet will also close the “Downloading Terrain” screen when joining/respawning.

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 meters, the client will be kicked for “You moved too quickly :( (Hacking?)”.

Also if the fixed-point number of X or Z is set greater than 3.2E7D the client will be kicked for “Illegal position”.

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 counterclockwise, with 90 at (-1, 0), 180 at (0, -1) and 270 at (1, 0). 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.

Packet ID State Bound To Field Name Field Type Notes
0x35 Play Client X Double Absolute or relative position, depending on Flags
Y Double Absolute or relative position, depending on Flags
Z Double Absolute or relative position, depending on Flags
Yaw Float Absolute or relative rotation on the X axis, in degrees
Pitch Float Absolute or relative rotation on the Y axis, in degrees
Flags Byte Bit field, see below
Teleport ID VarInt Client should confirm this packet with Teleport Confirm containing the same Teleport ID

About the Flags field:

<Dinnerbone> It's a bitfield, X/Y/Z/Y_ROT/X_ROT. If X is set, the x value is relative and not absolute.
Field Bit
X 0x01
Y 0x02
Z 0x04
Y_ROT 0x08
X_ROT 0x10

解锁配方

Packet ID State Bound To Field Name Field Type Notes
0x36 Play Client
Action VarInt 0: init, 1: add, 2: remove
Crafting Recipe Book Open Boolean If true, then the crafting recipe book will be open when the player opens its inventory.
Crafting Recipe Book Filter Active Boolean If true, then the filtering option is active when the players opens its inventory.
Smelting Recipe Book Open Boolean If true, then the smelting recipe book will be open when the player opens its inventory.
Smelting Recipe Book Filter Active Boolean If true, then the filtering option is active when the players opens its inventory.
Array size 1 VarInt Number of elements in the following array
Recipe IDs Array of Identifier
Array size 2 Optional VarInt Number of elements in the following array, only present if mode is 0 (init)
Recipe IDs Optional Array of Identifier, only present if mode is 0 (init)

Action:

  • 0 (init) = All the recipes in the list 2 will added to the recipe book. All the recipes in list 1 will be tagged as displayed, recipes that aren't tagged will be shown in the notification. VERIFY LIST ORDER?
  • 1 (add) = All the recipes in the list are added and their icon will be shown in the notification.
  • 2 (remove) = Remove all the recipes in the list. This allows them to re-displayed when they are readded.

破坏实体

Sent by the server when a list of entities is to be destroyed on the client.

Packet ID State Bound To Field Name Field Type Notes
0x37 Play Client Count VarInt Number of elements in the following array
Entity IDs Array of VarInt The list of entities of destroy

移除实体效果

Packet ID State Bound To Field Name Field Type Notes
0x38 Play Client Entity ID VarInt
Effect ID Byte See this table

响应包发送

Packet ID State Bound To Field Name Field Type Notes
0x39 Play Client URL String (32767) The URL to the resource pack.
Hash String (40) A 40 character hexadecimal and lowercase SHA-1 hash of the resource pack file. (must be lower case in order to work)
If it's not a 40 character hexadecimal string, the client will not use it for hash verification and likely waste bandwidth — but it will still treat it as a unique id

重生

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 State Bound To Field Name Field Type Notes
0x3A Play Client Dimension Int Enum -1: The Nether, 0: The Overworld, 1: The End
Gamemode Unsigned Byte 0: survival, 1: creative, 2: adventure, 3: spectator. The hardcore flag is not included
Level Type String (16) Same as Join Game

Warning.png Avoid changing player's dimension to same dimension they were already in unless they are dead. If you change the dimension to one they are already in, weird bugs can occur, such as the player being unable to attack other players in new world (until they die and respawn).

If you must respawn a player in the same dimension without killing them, send two respawn packets, one to a different world and then another to the world you want. You do not need to complete the first respawn; it only matters that you send two packets.

实体头部外观

Changes the direction an entity's head is facing.

While sending the Entity Look packet changes the vertical rotation of the head, sending this packet appears to be necessary to rotate the head horizontally.

Packet ID State Bound To Field Name Field Type Notes
0x3B Play Client Entity ID VarInt
Head Yaw Angle New angle, not a delta

选择进度标签页

Sent by the server to indicate that the client should switch advancement tab. Sent either when the client switches tab in the GUI or when an advancement in another tab is made.

Packet ID State Bound To Field Name Field Type Notes
0x3C Play Client Has id Boolean Indicates if the next field is present
Optional Identifier String (32767) See below

The Identifier can be one of the following:

Optional Identifier
minecraft:story/root
minecraft:nether/root
minecraft:end/root
minecraft:adventure/root
minecraft:husbandry/root

If no or an invalid identifier is sent, the client will switch to the first tab in the GUI.

世界边界

Packet ID State Bound To Field Name Field Type Notes
0x3D Play Client Action VarInt Enum Determines the format of the rest of the packet
Action Field Name
0: set size Diameter Double Length of a single side of the world border, in meters
1: lerp size Old Diameter Double Current length of a single side of the world border, in meters
New Diameter Double Target length of a single side of the world border, in meters
Speed VarLong Number of real-time milliseconds until New Diameter is reached. It appears that Notchian server does not sync world border speed to game ticks, so it gets out of sync with server lag. If the world border is not moving, this is set to 0.
2: set center X Double
Z Double
3: initialize X Double
Z Double
Old Diameter Double Current length of a single side of the world border, in meters
New Diameter Double Target length of a single side of the world border, in meters
Speed VarLong Number of real-time milliseconds until New Diameter is reached. It appears that Notchian server does not sync world border speed to game ticks, so it gets out of sync with server lag. If the world border is not moving, this is set to 0.
Portal Teleport Boundary VarInt Resulting coordinates from a portal teleport are limited to ±value. Usually 29999984.
Warning Time VarInt In seconds as set by /worldborder warning time
Warning Blocks VarInt In meters
4: set warning time Warning Time VarInt In seconds as set by /worldborder warning time
5: set warning blocks Warning Blocks VarInt In meters

The Notchian client determines how solid to display the warning by comparing to whichever is higher, the warning distance or whichever is lower, the distance from the current diameter to the target diameter or the place the border will be after warningTime seconds. In pseudocode:

distance = max(min(resizeSpeed * 1000 * warningTime, abs(targetDiameter - currentDiameter)), warningDistance);
if (playerDistance < distance) {
    warning = 1.0 - playerDistance / distance;
} else {
    warning = 0.0;
}

摄像机

Sets the entity that the player renders from. This is normally used when the player left-clicks an entity while in spectator mode.

The player's camera will move with the entity and look where it is looking. The entity is often another player, but can be any type of entity. The player is unable to move this entity (move packets will act as if they are coming from the other entity).

If the given entity is not loaded by the player, this packet is ignored. To return control to the player, send this packet with their entity ID.

The Notchian server resets this (sends it back to the default entity) whenever the spectated entity is killed or the player sneaks, but only if they were spectating an entity. It also sends this packet whenever the player switches out of spectator mode (even if they weren't spectating an entity).

Packet ID State Bound To Field Name Field Type Notes
0x3E Play Client Camera ID VarInt ID of the entity to set the client's camera to

The notchian also loads certain shaders for given entities:

  • Creeper → shaders/post/creeper.json
  • Spider (and cave spider) → shaders/post/spider.json
  • Enderman → shaders/post/invert.json
  • Anything else → the current shader is unloaded

手持物品更改(客户端方)

Sent to change the player's slot selection.

Packet ID State Bound To Field Name Field Type Notes
0x3F Play Client Slot Byte The slot which the player has selected (0–8)

更新视图位置

Huh.png The following information needs to be added to this page:
Why is this even needed? Is there a better name for it? My guess is that it's something to do with logical behavior with latency, but it still seems weird.

Updates the client's location. This is used to determine what chunks should remain loaded and if a chunk load should be ignored; chunks outside of the view distance may be unloaded.

Sent whenever the player moves across a chunk border horizontally, and also (according to testing) for any integer change in the vertical axis, even if it doesn't go across a chunk section border.

Packet ID State Bound To Field Name Field Type Notes
0x40 Play Client Chunk X VarInt Chunk X coordinate of the player's position
Chunk Z VarInt Chunk Z coordinate of the player's position

更新视图距离

Sent by the integrated singleplayer server when changing render distance. Does not appear to be used by the dedicated server, as view-distance in server.properties cannot be changed at runtime.

Packet ID State Bound To Field Name Field Type Notes
0x41 Play Client View Distance VarInt Render distance (2-32)

显示记分板

This is sent to the client when it should display a scoreboard.

Packet ID State Bound To Field Name Field Type Notes
0x42 Play Client Position Byte The position of the scoreboard. 0: list, 1: sidebar, 2: below name, 3 - 18: team specific sidebar, indexed as 3 + team color.
Score Name String (16) The unique name for the scoreboard to be displayed.

实体元数据

Updates one or more metadata properties for an existing entity. Any properties not included in the Metadata field are left unchanged.

Packet ID State Bound To Field Name Field Type Notes
0x43 Play Client Entity ID VarInt
Metadata Entity Metadata

附加实体

This packet is sent when an entity has been leashed to another entity.

Packet ID State Bound To Field Name Field Type Notes
0x44 Play Client Attached Entity ID Int Attached entity's EID
Holding Entity ID Int ID of the entity holding the lead. Set to -1 to detach.

实体速度

Velocity is believed to be in units of 1/8000 of a block per server tick (50ms); for example, -1343 would move (-1343 / 8000) = −0.167875 blocks per tick (or −3,3575 blocks per second).

Packet ID State Bound To Field Name Field Type Notes
0x45 Play Client Entity ID VarInt
Velocity X Short Velocity on the X axis
Velocity Y Short Velocity on the Y axis
Velocity Z Short Velocity on the Z axis

实体装备

Packet ID State Bound To Field Name Field Type Notes
0x46 Play Client Entity ID VarInt Entity's EID
Slot VarInt Enum Equipment slot. 0: main hand, 1: off hand, 2–5: armor slot (2: boots, 3: leggings, 4: chestplate, 5: helmet)
Item Slot

设置经验

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

Packet ID State Bound To Field Name Field Type Notes
0x47 Play Client Experience bar Float Between 0 and 1
Level VarInt
Total Experience VarInt See Experience#Leveling up on the Minecraft Wiki for Total Experience to Level conversion

更新生命值

Sent by the server to update/set the health of the player it is sent to.

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 State Bound To Field Name Field Type Notes
0x48 Play Client Health Float 0 or less = dead, 20 = full HP
Food VarInt 0–20
Food Saturation Float Seems to vary from 0.0 to 5.0 in integer increments

记分板记分项

This is sent to the client when it should create a new scoreboard objective or remove one.

Packet ID State Bound To Field Name Field Type Notes
0x49 Play Client Objective Name String (16) An unique name for the objective
Mode Byte 0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.
Objective Value Optional Chat Only if mode is 0 or 2. The text to be displayed for the score
Type Optional VarInt enum Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".

设置乘坐者

Packet ID State Bound To Field Name Field Type Notes
0x4A Play Client Entity ID VarInt Vehicle's EID
Passenger Count VarInt Number of elements in the following array
Passengers Array of VarInt EIDs of entity's passengers

队伍

Creates and updates teams.

Packet ID State Bound To Field Name Field Type Notes
0x4B Play Client Team Name String (16) A unique name for the team. (Shared with scoreboard).
Mode Byte Determines the layout of the remaining packet
0: create team Team Display Name Chat
Friendly Flags Byte Bit mask. 0x01: Allow friendly fire, 0x02: can see invisible players on same team
Name Tag Visibility String Enum (32) always, hideForOtherTeams, hideForOwnTeam, never
Collision Rule String Enum (32) always, pushOtherTeams, pushOwnTeam, never
Team Color VarInt enum Used to color the name of players on the team; see below
Team Prefix Chat Displayed before the names of players that are part of this team
Team Suffix Chat Displayed after the names of players that are part of this team
Entity Count VarInt Number of elements in the following array
Entities Array of String (40) Identifiers for the entities in this team. For players, this is their username; for other entities, it is their UUID.
1: remove team no fields no fields
2: update team info Team Display Name Chat
Friendly Flags Byte Bit mask. 0x01: Allow friendly fire, 0x02: can see invisible entities on same team
Name Tag Visibility String Enum (32) always, hideForOtherTeams, hideForOwnTeam, never
Collision Rule String Enum (32) always, pushOtherTeams, pushOwnTeam, never
Team Color VarInt enum Used to color the name of players on the team; see below
Team Prefix Chat Displayed before the names of players that are part of this team
Team Suffix Chat Displayed after the names of players that are part of this team
3: add players to team Entity Count VarInt Number of elements in the following array
Entities Array of String (40) Identifiers for the entities added. For players, this is their username; for other entities, it is their UUID.
4: remove players from team Entity Count VarInt Number of elements in the following array
Entities Array of String (40) Identifiers for the entities removed. For players, this is their username; for other entities, it is their UUID.

Team Color: The color of a team defines how the names of the team members are visualized; any formatting code can be used. The following table lists all the possible values.

ID Formatting
0-15 Color formatting, same values as Chat colors.
16 Obfuscated
17 Bold
18 Strikethrough
19 Underlined
20 Italic
21 Reset

更新分数

This is sent to the client when it should update a scoreboard item.

Packet ID State Bound To Field Name Field Type Notes
0x4C Play Client Entity Name String (40) The entity whose score this is. For players, this is their username; for other entities, it is their UUID.
Action Byte 0 to create/update an item. 1 to remove an item.
Objective Name String (16) The name of the objective the score belongs to
Value Optional VarInt The score to be displayed next to the entry. Only sent when Action does not equal 1.

生成位置

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 State Bound To Field Name Field Type Notes
0x4D Play Client Location Position Spawn location

时间更新

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 State Bound To Field Name Field Type Notes
0x4E Play Client World Age Long In ticks; not changed by server commands
Time of day Long The world (or region) time, in ticks. If negative the sun will stop moving at the Math.abs of the time

标题

Packet ID State Bound To Field Name Field Type Notes
0x4F Play Client Action VarInt Enum
Action Field Name
0: set title Title Text Chat
1: set subtitle Subtitle Text Chat
2: set action bar Action bar text Chat Displays a message above the hotbar (the same as position 2 in Chat Message (clientbound), except that it correctly renders formatted chat. See MC-119145 for more information.)
3: set times and display Fade In Int Ticks to spend fading in
Stay Int Ticks to keep the title displayed
Fade Out Int Ticks to spend out, not when to start fading out
4: hide no fields no fields
5: reset no fields no fields

“Hide” makes the title disappear, but if you run times again the same title will appear. “Reset” erases the text.

The title is visible on screen for Fade In + Stay + Fade Out ticks.

实体声音效果

Plays a sound effect from an entity.

Packet ID State Bound To Field Name Field Type Notes
0x50 Play Client Sound ID VarInt ID of hardcoded sound event (events as of 1.14.4)
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

声音效果

This packet is used to play a number of hardcoded sound events. For custom sounds, use Named Sound Effect.

Warning.png Numeric sound effect IDs are liable to change between versions

Packet ID State Bound To Field Name Field Type Notes
0x51 Play Client Sound ID VarInt ID of hardcoded sound event (events as of 1.14.4)
Sound Category VarInt Enum The category that this sound will be played from (current categories)
Effect Position X Int Effect X multiplied by 8 (fixed-point number with only 3 bits dedicated to the fractional part)
Effect Position Y Int Effect Y multiplied by 8 (fixed-point number with only 3 bits dedicated to the fractional part)
Effect Position Z Int Effect Z multiplied by 8 (fixed-point number with only 3 bits dedicated to the fractional part)
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

停止声音

Packet ID State Bound To Field Name Field Type Notes
0x52 Play Client Flags Byte Controls which fields are present.
Source Optional VarInt enum Only if flags is 3 or 1 (bit mask 0x1). See below. If not present, then sounds from all sources are cleared.
Sound Optional Identifier Only if flags is 2 or 3 (bit mask 0x2). A sound effect name, see Named Sound Effect. If not present, then all sounds are cleared.

Categories:

Name Value
master 0
music 1
record 2
weather 3
block 4
hostile 5
neutral 6
player 7
ambient 8
voice 9

玩家列表头和脚

This packet may be used by custom servers to display additional information above/below the player list. It is never sent by the Notchian server.

Packet ID State Bound To Field Name Field Type Notes
0x53 Play Client Header Chat To remove the header, send a empty translatable component: {"translate":""}
Footer Chat To remove the footer, send a empty translatable component: {"translate":""}

NBT查询响应

Sent in response to Query Block NBT or Query Entity NBT.

Packet ID State Bound To Field Name Field Type Notes
0x54 Play Client Transaction ID VarInt Can be compared to the one sent in the original query packet.
NBT NBT Tag The NBT of the block or entity. May be a TAG_END (0) in which case no NBT is present.

收集物品

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, and it doesn't add it to your inventory. The server only checks for items to be picked up after each Player Position (and Player Position And Look) packet sent by the client. The collector entity can be any entity; it does not have to be a player. The collected entity also can be any entity, but the Notchian server only uses this for items, experience orbs, and the different varieties of arrows.

Packet ID State Bound To Field Name Field Type Notes
0x55 Play Client Collected Entity ID VarInt
Collector Entity ID VarInt
Pickup Item Count VarInt Seems to be 1 for XP orbs, otherwise the number of items in the stack.

实体传送

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

Packet ID State Bound To Field Name Field Type Notes
0x56 Play Client Entity ID VarInt
X Double
Y Double
Z Double
Yaw Angle New angle, not a delta
Pitch Angle New angle, not a delta
On Ground Boolean

进度

Packet ID State Bound To Field Name Field Type Notes
0x57 Play Client Reset/Clear Boolean Whether to reset/clear the current advancements
Mapping size VarInt Size of the following array
Advancement mapping Key Array Identifier The identifier of the advancement
Value Advancement See below
List size VarInt Size of the following array
Identifiers Array of Identifier The identifiers of the advancements that should be removed
Progress size VarInt Size of the following array
Progress mapping Key Array Identifier The identifier of the advancement
Value Advancement progress See below

Advancement structure:

Field Name Field Type Notes
Has parent Boolean Indicates whether the next field exists.
Parent id Optional Identifier The identifier of the parent advancement.
Has display Boolean Indicates whether the next field exists
Display data Optional advancement display See below.
Number of criteria VarInt Size of the following array
Criteria Key Array Identifier The identifier of the criterion
Value Void There is no content written here. Perhaps this will be expanded in the future?
Array length VarInt Number of arrays in the following array
Requirements Array length 2 Array VarInt Number of elements in the following array
Requirement Array of String Array of required criteria

Advancement display:

Field Name Field Type Notes
Title Chat
Description Chat
Icon Slot
Frame type VarInt enum 0 = task, 1 = challenge, 2 = goal
Flags Integer 0x1: has background texture; 0x2: show_toast; 0x4: hidden
Background texture Optional Identifier Background texture location. Only if flags indicates it.
X coord Float
Y coord Float

Advancement progress:

Field Name Field Type Notes
Size VarInt Size of the following array
Criteria Criterion identifier Array Identifier The identifier of the criterion.
Criterion progress Criterion progress

Criterion progress:

Field Name Field Type Notes
Achieved Boolean If true, next field is present
Date of achieving Optional Long As returned by Date.getTime

实体属性

Sets attributes on the given entity.

Packet ID State Bound To Field Name Field Type Notes
0x58 Play Client Entity ID VarInt
Number Of Properties Int Number of elements in the following array
Property Key Array String (64) See below
Value Double See below
Number Of Modifiers VarInt Number of elements in the following array
Modifiers Array of Modifier Data See Attribute#Modifiers. Modifier Data defined below.

Known Key values (see also Attribute#Modifiers):

Key Default Min Max Label
generic.maxHealth 20.0 0.0 1024.0 Max Health
generic.followRange 32.0 0.0 2048.0 Follow Range
generic.knockbackResistance 0.0 0.0 1.0 Knockback Resistance
generic.movementSpeed 0.699999988079071 0.0 1024.0 Movement Speed
generic.attackDamage 2.0 0.0 2048.0 Attack Damage
generic.attackSpeed 4.0 0.0 1024.0 Attack Speed
generic.flyingSpeed 0.4000000059604645 0.0 1024.0 Flying Speed
horse.jumpStrength 0.7 0.0 2.0 Jump Strength
zombie.spawnReinforcements 0.0 0.0 1.0 Spawn Reinforcements Chance
generic.reachDistance 5.0 0.0 1024.0 Player Reach Distance (Forge only)
forge.swimSpeed 1.0 0.0 1024.0 Swimming Speed (Forge only)

Modifier Data structure:

Field Name Field Type Notes
UUID UUID
Amount Double May be positive or negative
Operation Byte See below

The operation controls how the base value of the modifier is changed.

  • 0: Add/subtract amount
  • 1: Add/subtract amount percent of the current value
  • 2: Multiply by amount percent

All of the 0's are applied first, and then the 1's, and then the 2's.

实体效果

Packet ID State Bound To Field Name Field Type Notes
0x59 Play Client Entity ID VarInt
Effect ID Byte See this table
Amplifier Byte Notchian client displays effect level as Amplifier + 1
Duration VarInt Seconds
Flags Byte Bit field, see below.

Within flags:

  • 0x01: Is ambient - was the effect spawned from a beacon? All beacon-generated effects are ambient. Ambient effects use a different icon in the HUD (blue border rather than gray). If all effects on an entity are ambient, the "Is potion effect ambient" living metadata field should be set to true. Usually should not be enabled.
  • 0x02: Show particles - should all particles from this effect be hidden? Effects with particles hidden are not included in the calculation of the effect color, and are not rendered on the HUD (but are still rendered within the inventory). Usually should be enabled.

声明配方

Packet ID State Bound To Field Name Field Type Notes
0x5A Play Client Num Recipes VarInt Number of elements in the following array
Recipe Recipe ID Array Identifier
Type String The recipe type, see below
Data Optional, varies Additional data for the recipe. For some types, there will be no data.

Recipe types:

Type Description Data
crafting_shapeless Shapeless crafting recipe. All items in the ingredient list must be present, but in any order/slot. As follows:
Name Type Description
Group String Used to group similar recipes together in the recipe book. Tag is present in recipe JSON.
Ingredient count VarInt Number of elements in the following array
Ingredients Array of Ingredient
Result Slot
crafting_shaped Shaped crafting recipe. All items must be present in the same pattern (which may be flipped horizontally or translated) As follows:
Name Type Description
Width VarInt
Height VarInt
Group String Used to group similar recipes together in the recipe book. Tag is present in recipe JSON.
Ingredients Array of Ingredient Length is width * height. Indexed by x + (y * width).
Result Slot
crafting_special_armordye Recipe for dying leather armor None
crafting_special_bookcloning Recipe for copying contents of written books None
crafting_special_mapcloning Recipe for copying maps None
crafting_special_mapextending Recipe for adding paper to maps None
crafting_special_firework_rocket Recipe for making firework rockets None
crafting_special_firework_star Recipe for making firework stars None
crafting_special_firework_star_fade Recipe for making firework stars fade between multiple colors None
crafting_special_repairitem Recipe for repairing items via crafting None
crafting_special_tippedarrow Recipe for crafting tipped arrows None
crafting_special_bannerduplicate Recipe for copying banner patterns None
crafting_special_banneraddpattern Recipe for adding patterns to banners None
crafting_special_shielddecoration Recipe for applying a banner's pattern to a shield None
crafting_special_shulkerboxcoloring Recipe for recoloring a shulker box None
smelting Smelting recipe As follows:
Name Type Description
Group String Used to group similar recipes together in the recipe book.
Ingredient Ingredient
Result Slot
Experience Float
Cooking time VarInt

Ingredient is defined as:

Name Type Description
Count VarInt Number of elements in the following array
Items Array of Slot Any item in this array may be used for the recipe. The count of each item should be 1.

标签

Packet ID State Bound To Field Name Field Type Notes
0x5B 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 IDs

Tags look like:

Field Name Field Type Notes
Length VarInt Number of elements in the following array
Tags Tag name Array Identifier
Count VarInt Number of elements in the following array
Entries Array of VarInt Numeric ID of the block/item.

确认玩家挖掘

Packet ID State Bound To Field Name Field Type Notes
0x5C Play Client Location Position Position where the digging was happening
Block VarInt Block state ID of the block that should be at that position now.
Status VarInt enum Same as Player Digging. Only Started digging (0), Cancelled digging (1), and Finished digging (2) are used.
Successful Boolean True if the digging succeeded; false if the client should undo any changes it made locally. (How does this work?)

服务端方

传送确认

Sent by client as confirmation of Player Position And Look.

Packet ID State Bound To Field Name Field Type Notes
0x00 Play Server Teleport ID VarInt The ID given by the Player Position And Look packet

查询方块NBT

Used when Shift+F3+I is pressed while looking at a block.

Packet ID State Bound To Field Name Field Type Notes
0x01 Play Server Transaction ID VarInt An incremental ID so that the client can verify that the response matches.
Location Position The location of the block to check.

设置难度

Must have at least op level 2 to use. Appears to only be used on singleplayer; the difficulty buttons are still disabled in multiplayer.

Packet ID State Bound To Field Name Field Type Notes
0x02 Play Server New difficulty Byte 0: peaceful, 1: easy, 2: normal, 3: hard

聊天消息(服务端方)

Used to send a chat message to the server. The message may not be longer than 256 characters or else the server will kick the client.

If the message starts with a /, the server will attempt to interpret it as a command. Otherwise, the server will broadcast the same chat message to all players on the server (including the player that sent the message), prepended with player's name. Specifically, it will respond with a translate chat component, "chat.type.text" with the first parameter set to the display name of the player (including some chat component logic to support clicking the name to send a PM) and the second parameter set to the message. See processing chat for more information.

Packet ID State Bound To Field Name Field Type Notes
0x03 Play Server Message String (256) The client sends the raw input, not a Chat component

客户端状态

Packet ID State Bound To Field Name Field Type Notes
0x04 Play Server Action ID VarInt Enum See below

Action ID values:

Action ID Action Notes
0 Perform respawn Sent when the client is ready to complete login and when the client is ready to respawn after death.
1 Request stats Sent when the client opens the Statistics menu

客户端设置

Sent when the player connects, or when settings are changed.

Packet ID State Bound To Field Name Field Type Notes
0x05 Play Server Locale String (16) e.g. en_GB
View Distance Byte Client-side render distance, in chunks
Chat Mode VarInt Enum 0: enabled, 1: commands only, 2: hidden. See processing chat for more information.
Chat Colors Boolean “Colors” multiplayer setting
Displayed Skin Parts Unsigned Byte Bit mask, see below
Main Hand VarInt Enum 0: Left, 1: Right

Displayed Skin Parts flags:

  • Bit 0 (0x01): Cape enabled
  • Bit 1 (0x02): Jacket enabled
  • Bit 2 (0x04): Left Sleeve enabled
  • Bit 3 (0x08): Right Sleeve enabled
  • Bit 4 (0x10): Left Pants Leg enabled
  • Bit 5 (0x20): Right Pants Leg enabled
  • Bit 6 (0x40): Hat enabled

The most significant bit (bit 7, 0x80) appears to be unused.

Tab补全(服务端方)

Sent when the client needs to tab-complete a minecraft:ask_server suggestion type.

Packet ID State Bound To Field Name Field Type Notes
0x06 Play Server Transaction Id VarInt The id received in the tab completion request packet, must match or the client will ignore this packet. Client generates this and increments it each time it sends another tab completion that doesn't get a response.
Text String (32500) All text behind the cursor without the / (e.g. to the left of the cursor in left-to-right languages like English)

确认交互(服务端方)

If a transaction sent by the client was not accepted, the server will reply with a Confirm Transaction (clientbound) packet with the Accepted field set to false. When this happens, the client must send this packet to apologize (as with movement), otherwise the server ignores any successive transactions.

Packet ID State Bound To Field Name Field Type Notes
0x07 Play Server Window ID Byte The ID of the window that the action occurred in
Action Number Short Every action that is to be accepted has a unique number. This number is an incrementing integer (starting at 1) with separate counts for each window ID.
Accepted Boolean Whether the action was accepted

单击窗口按钮

Used when clicking on window buttons. Until 1.14, this was only used by enchantment tables.

Packet ID State Bound To Field Name Field Type Notes
0x07 Play Server Window ID Byte The ID of the window sent by Open Window
Button ID Byte Meaning depends on window type; see below
Window type ID Meaning
Enchantment Table 0 Topmost enchantment
1 Middle enchantment
2 Bottom enchantment
Lectern 1 Unknown - maybe previous page? (which does give a redstone output)
2 Unknown - maybe next page?
3 Take Book
100? Unknown - actual value is 100 + some parameter, so there may be multiple
Stonecutter Recipe button number - 4*row + col. Depends on the item.
Loom Recipe button number - 4*row + col. Depends on the item.


单击窗口

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

Packet ID State Bound To Field Name Field Type Notes
0x09 Play Server Window ID Unsigned Byte The ID of the window which was clicked. 0 for player inventory.
Slot Short The clicked slot number, see below
Button Byte The button used in the click, see below
Action Number Short A unique number for the action, implemented by Notchian as a counter, starting at 1 (different counter for every window ID). Used by the server to send back a Confirm Transaction (clientbound).
Mode VarInt Enum Inventory operation mode, see below
Clicked item Slot The clicked slot. Has to be empty (item ID = -1) for drop mode.

See Inventory 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 distinct type of click performed by the client is determined by the combination of the Mode and Button fields.

Mode Button Slot Trigger
0 0 Normal Left mouse click
1 Normal Right mouse click
1 0 Normal Shift + left mouse click
1 Normal Shift + right mouse click (identical behavior)
2 0 Normal Number key 1
1 Normal Number key 2
2 Normal Number key 3
8 Normal Number key 9
3 2 Normal Middle click, only defined for creative players in non-player inventories.
4 0 Normal* Drop key (Q) (* Clicked item is different, see above)
1 Normal* Ctrl + Drop key (Ctrl-Q) (drops full stack)
0 -999 Left click outside inventory holding nothing (no-op)
1 -999 Right click outside inventory holding nothing (no-op)
5 0 -999 Starting left mouse drag
4 -999 Starting right mouse drag
8 -999 Starting middle mouse drag, only defined for creative players in non-player inventories. (Note: the vanilla client will still incorrectly send this for non-creative players - see MC-46584)
1 Normal Add slot for left-mouse drag
5 Normal Add slot for right-mouse drag
9 Normal Add slot for middle-mouse drag, only defined for creative players in non-player inventories. (Note: the vanilla client will still incorrectly send this for non-creative players - see MC-46584)
2 -999 Ending left mouse drag
6 -999 Ending right mouse drag
10 -999 Ending middle mouse drag, only defined for creative players in non-player inventories. (Note: the vanilla client will still incorrectly send this for non-creative players - see MC-46584)
6 0 Normal Double click

Starting from version 1.5, “painting mode” is available for use in inventory windows. It is done by picking up stack of something (more than 1 item), then holding mouse button (left, right or middle) and dragging held stack over empty (or same type in case of right button) slots. In that case client sends the following to server after mouse button release (omitting first pickup packet which is sent as usual):

  1. packet with mode 5, slot -999, button (0 for left | 4 for right);
  2. packet for every slot painted on, mode is still 5, button (1 | 5);
  3. packet with mode 5, slot -999, button (2 | 6);

If any of the painting packets other than the “progress” ones are sent out of order (for example, a start, some slots, then another start; or a left-click in the middle) the painting status will be reset.

The server will send back a Confirm Transaction packet. If the click was not accepted, the client must send a matching serverbound confirm transaction packet before sending more Click Window packets, otherwise the server will reject them silently. The Notchian server also sends a Window Items packet for the open window and Set Slot packets for the clicked and cursor slot, but only when the click was not accepted, probably to resynchronize client and server.

关闭窗口(服务端方)

This packet is sent by the client when closing a window.

Notchian clients send a Close Window packet with Window ID 0 to close their inventory even though there is never an Open Window packet for the inventory.

Packet ID State Bound To Field Name Field Type Notes
0x0A Play Server Window ID Unsigned Byte This is the ID of the window that was closed. 0 for player inventory.

插件消息(服务端方)

Main article: Plugin channels

Mods and plugins can use this to send their data. Minecraft itself uses some plugin channels. These internal channels are in the minecraft namespace.

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

Note that the length of Data is known only from the packet length, since the packet has no length field of any kind.

Packet ID State Bound To Field Name Field Type Notes
0x0B Play Server Channel Identifier Name of the plugin channel used to send the data
Data Byte Array Any data, depending on the channel. minecraft: channels are documented here. The length of this array must be inferred from the packet length.

编辑书

Packet ID State Bound To Field Name Field Type Notes
0x0C Play Server New book Slot
Is signing Boolean True if the player is signing the book; false if the player is saving a draft.
Hand VarInt enum 0: Main hand, 1: Off hand

When editing a draft, the NBT section of the Slot contains this:

TAG_Compound(''): 1 entry
{
  TAG_List('pages'): 2 entries
  {
    TAG_String(0): 'Something on Page 1'
    TAG_String(1): 'Something on Page 2'
  }
}

When signing the book, it instead looks like this:

TAG_Compound(''): 3 entires
{
  TAG_String('author'): 'Steve'
  TAG_String('title'): 'A Wonderful Book'
  TAG_List('pages'): 2 entries
  {
    TAG_String(0): 'Something on Page 1'
    TAG_String(1): 'Something on Page 2'
  }
}

查询实体NBT

Used when Shift+F3+I is pressed while looking at an entity.

Packet ID State Bound To Field Name Field Type Notes
0x0D Play Server Transaction ID VarInt An incremental ID so that the client can verify that the response matches.
Entity ID VarInt The ID of the entity to query.

使用实体

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.

Note that middle-click in creative mode is interpreted by the client and sent as a Creative Inventory Action packet instead.

Packet ID State Bound To Field Name Field Type Notes
0x0E Play Server Target VarInt
Type VarInt Enum 0: interact, 1: attack, 2: interact at
Target X Optional Float Only if Type is interact at
Target Y Optional Float Only if Type is interact at
Target Z Optional Float Only if Type is interact at
Hand Optional VarInt Enum Only if Type is interact or interact at; 0: main hand, 1: off hand

Keep Alive(服务端方)

The server will frequently send out a keep-alive, each containing a random ID. The client must respond with the same packet.

Packet ID State Bound To Field Name Field Type Notes
0x0F Play Server Keep Alive ID Long

锁定难度

Must have at least op level 2 to use. Appears to only be used on singleplayer; the difficulty buttons are still disabled in multiplayer.

Packet ID State Bound To Field Name Field Type Notes
0x10 Play Server Locked Boolean

玩家位置

Updates the player's XYZ position on the server.

Checking for moving too fast is achieved like this:

  • Each server tick, the player's current position is stored
  • When a player moves, the changes in x, y, and z coordinates are compared with the positions from the previous tick (Δx, Δy, Δz)
  • Total movement distance squared is computed as Δx² + Δy² + Δz²
  • The expected movement distance squared is computed as velocityX² + veloctyY² + velocityZ²
  • If the total movement distance squared value minus the expected movement distance squared value is more than 100 (300 if the player is using an elytra), they are moving too fast.

If the player is moving too fast, it will be logged that "<player> moved too quickly! " followed by the change in x, y, and z, and the player will be teleported back to their current (before this packet) serverside position.

Also, if the absolute value of X or the absolute value of Z is a value greater than 3.2×107, or X, Y, or Z are not finite (either positive infinity, negative infinity, or NaN), the client will be kicked for “Invalid move player packet received”.

Packet ID State Bound To Field Name Field Type Notes
0x11 Play Server X Double Absolute position
Feet Y Double Absolute feet position, normally Head Y - 1.62
Z Double Absolute position
On Ground Boolean True if the client is on the ground, false otherwise

玩家位置和外观(服务端方)

A combination of Player Look and Player Position.

Packet ID State Bound To Field Name Field Type Notes
0x12 Play Server X Double Absolute position
Feet Y Double Absolute feet position, normally Head Y - 1.62
Z Double Absolute position
Yaw Float Absolute rotation on the X Axis, in degrees
Pitch Float Absolute rotation on the Y Axis, in degrees
On Ground Boolean True if the client is on the ground, false otherwise

玩家外观

The unit circle for yaw
The unit circle of yaw, redrawn

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 counterclockwise, with 90 at (-1, 0), 180 at (0,-1) and 270 at (1, 0). 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.

The yaw and pitch of player (in degrees), standing at point (x0, y0, z0) and looking towards point (x, y, z) can be calculated with:

dx = x-x0
dy = y-y0
dz = z-z0
r = sqrt( dx*dx + dy*dy + dz*dz )
yaw = -atan2(dx,dz)/PI*180
if yaw < 0 then
    yaw = 360 + yaw
pitch = -arcsin(dy/r)/PI*180

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 State Bound To Field Name Field Type Notes
0x13 Play Server Yaw Float Absolute rotation on the X Axis, in degrees
Pitch Float Absolute rotation on the Y Axis, in degrees
On Ground Boolean True if the client is on the ground, False otherwise

玩家

This packet as well as Player Position, Player Look, and Player Position And Look are called the “serverbound movement packets”. Vanilla clients will send Player Position once every 20 ticks even for a stationary player.

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.

Packet ID State Bound To Field Name Field Type Notes
0x14 Play Server On Ground Boolean True if the client is on the ground, false otherwise

载具移动(服务端方)

Sent when a player moves in a vehicle. Fields are the same as in Player Position And Look. Note that all fields use absolute positioning and do not allow for relative positioning.

Packet ID State Bound To Field Name Field Type Notes
0x15 Play Server X Double Absolute position (X coordinate)
Y Double Absolute position (Y coordinate)
Z Double Absolute position (Z coordinate)
Yaw Float Absolute rotation on the vertical axis, in degrees
Pitch Float Absolute rotation on the horizontal axis, in degrees

操控船

Used to visually update whether boat paddles are turning. The server will update the Boat entity metadata to match the values here.

Packet ID State Bound To Field Name Field Type Notes
0x16 Play Server Left paddle turning Boolean
Right paddle turning Boolean

Right paddle turning is set to true when the left button or forward button is held; left paddle turning is set to true when the right button or forward button is set to true.

拾起物品

Used to swap out an empty space on the hotbar with the item in the given inventory slot. The Notchain client uses this for pick block functionality (middle click) to retrieve items from the inventory.


Packet ID State Bound To Field Name Field Type Notes
0x17 Play Server Slot to use VarInt See Inventory

The server will first search the player's hotbar for an empty slot, starting from the current slot and looping around to the slot before it. If there are no empty slots, it will start a second search from the current slot and find the first slot that does not contain an enchanted item. If there still are no slots that meet that criteria, then the server will use the currently selected slot.

After finding the appropriate slot, the server swaps the items and then send 3 packets:

  • Set Slot, with window ID set to -2 and slot set to the newly chosen slot and the item set to the item that is now in that slot (which was previously at the slot the client requested)
  • Set Slot, with window ID set to -2 and slot set to the slot the player requested, with the item that is now in that slot and was previously on the hotbar slot
  • Held Item Change, with the slot set to the newly chosen slot.

合成配方请求

This packet is sent when a player clicks a recipe in the crafting book that is craftable (white border).

Packet ID State Bound To Field Name Field Type Notes
0x18 Play Server Window ID Byte
Recipe Identifier A recipe ID
Make all Boolean Affects the amount of items processed; true if shift is down when clicked

玩家能力(服务端方)

The latter 2 fields are used to indicate the walking and flying speeds respectively, while the first field is used to determine the value of 4 booleans.

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

Packet ID State Bound To Field Name Field Type Notes
0x19 Play Server Flags Byte Bit mask. 0x08: damage disabled (god mode), 0x04: can fly, 0x02: is flying, 0x01: is Creative
Flying Speed Float
Walking Speed Float

玩家挖掘

Sent when the player mines a block. A Notchian server only accepts digging packets with coordinates within a 6-unit radius between the center of the block and 1.5 units from the player's feet (not their eyes).

Packet ID State Bound To Field Name Field Type Notes
0x1A Play Server Status VarInt Enum The action the player is taking against the block (see below)
Location Position Block position
Face Byte Enum The face being hit (see below)

Status can be one of seven values:

Value Meaning Notes
0 Started digging
1 Cancelled digging Sent when the player lets go of the Mine Block key (default: left click)
2 Finished digging Sent when the client thinks it is finished
3 Drop item stack Triggered by using the Drop Item key (default: Q) with the modifier to drop the entire selected stack (default: depends on OS). Location is always set to 0/0/0, Face is always set to -Y.
4 Drop item Triggered by using the Drop Item key (default: Q). Location is always set to 0/0/0, Face is always set to -Y.
5 Shoot arrow / finish eating Indicates that the currently held item should have its state updated such as eating food, pulling back bows, using buckets, etc. Location is always set to 0/0/0, Face is always set to -Y.
6 Swap item in hand Used to swap or assign an item to the second hand. Location is always set to 0/0/0, Face is always set to -Y.

The Face field can be one of the following values, representing the face being hit:

Value Offset Face
0 -Y Bottom
1 +Y Top
2 -Z North
3 +Z South
4 -X West
5 +X East

实体动作

Sent by the client to indicate that it has performed certain actions: sneaking (crouching), sprinting, exiting a bed, jumping with a horse, and opening a horse's inventory while riding it.

Packet ID State Bound To Field Name Field Type Notes
0x1B Play Server Entity ID VarInt Player ID
Action ID VarInt Enum The ID of the action, see below
Jump Boost VarInt Only used by the “start jump with horse” action, in which case it ranges from 0 to 100. In all other cases it is 0.

Action ID can be one of the following values:

ID Action
0 Start sneaking
1 Stop sneaking
2 Leave bed
3 Start sprinting
4 Stop sprinting
5 Start jump with horse
6 Stop jump with horse
7 Open horse inventory
8 Start flying with elytra

Leave bed is only sent when the “Leave Bed” button is clicked on the sleep GUI, not when waking up due today time.

Open horse inventory is only sent when pressing the inventory key (default: E) while on a horse — all other methods of opening a horse's inventory (involving right-clicking or shift-right-clicking it) do not use this packet.

操控载具

Packet ID State Bound To Field Name Field Type Notes
0x1C Play Server Sideways Float Positive to the left of the player
Forward Float Positive forward
Flags Unsigned Byte Bit mask. 0x1: jump, 0x2: unmount

Also known as 'Input' packet.

配方书数据

Packet ID State Bound To Field Name Field Type Notes
0x1D Play Server Type VarInt Determines the format of the rest of the packet
Type Field Name
0: Displayed Recipe Recipe ID Identifier A recipe ID
1: Recipe Book States Crafting Recipe Book Open Boolean Whether the player has the crafting recipe book currently opened/active.
Crafting Recipe Filter Active Boolean Whether the player has the crafting recipe book filter option currently active.
Smelting Recipe Book Open Boolean Whether the player has the smelting recipe book currently opened/active.
Smelting Recipe Filter Active Boolean Whether the player has the smelting recipe book filter option currently active.
Blasting Recipe Book Open Boolean May be swapped with smoking recipe book. Also, the notchian client appears to use the same value for both of those books currently.
Blasting Recipe Filter Active Boolean May be swapped with smoking recipe book. Also, the notchian client appears to use the same value for both of those books currently.
Smoking Recipe Book Open Boolean
Smoking Recipe Filter Active Boolean

The Recipe Book Status type is sent when one of the states changes.

命名物品

Sent as a player is renaming an item in an anvil (each keypress in the anvil UI sends a new Name Item packet). If the new name is empty, then the item loses its custom name (this is different from setting the custom name to the normal name of the item). The item name may be no longer than 35 characters long, and if it is longer than that, then the rename is silently ignored.

Packet ID State Bound To Field Name Field Type Notes
0x1E Play Server Item name String (32767) The new name of the item

资源包状态

Packet ID State Bound To Field Name Field Type Notes
0x1F Play Server Result VarInt Enum 0: successfully loaded, 1: declined, 2: failed download, 3: accepted

进度标签页

Packet ID State Bound To Field Name Field Type Notes
0x20 Play Server Action VarInt enum 0: Opened tab, 1: Closed screen
Tab ID Optional identifier Only present if action is Opened tab

选择交易

When a player selects a specific trade offered by a villager NPC.

Packet ID State Bound To Field Name Field Type Notes
0x21 Play Server Selected slot VarInt The selected slot int the players current (trading) inventory. (Was a full Integer for the plugin message)

设置信标效果

Changes the effect of the current beacon.

Packet ID State Bound To Field Name Field Type Notes
0x22 Play Server Primary Effect VarInt A Potion ID. (Was a full Integer for the plugin message)
Secondary Effect VarInt A Potion ID. (Was a full Integer for the plugin message)

手持物品更改(服务端方)

Sent when the player changes the slot selection

Packet ID State Bound To Field Name Field Type Notes
0x23 Play Server Slot Short The slot which the player has selected (0–8)

更新命令方块

Packet ID State Bound To Field Name Field Type Notes
0x24 Play Server
Location Position
Command String (32767)
Mode VarInt enum One of SEQUENCE (0), AUTO (1), or REDSTONE (2)
Flags Byte 0x01: Track Output (if false, the output of the previous command will not be stored within the command block); 0x02: Is conditional; 0x04: Automatic

更新命令方块矿车

Packet ID State Bound To Field Name Field Type Notes
0x25 Play Server Entity ID VarInt
Command String
Track Output Boolean If false, the output of the previous command will not be stored within the command block.

创造模式物品栏动作

While the user is in the standard inventory (i.e., not a crafting bench) in Creative mode, the player will send this packet.

Clicking in the creative inventory menu is quite different from non-creative inventory management. Picking up an item with the mouse actually deletes the item from the server, and placing an item into a slot or dropping it out of the inventory actually tells the server to create the item from scratch. (This can be verified by clicking an item that you don't mind deleting, then severing the connection to the server; the item will be nowhere to be found when you log back in.) As a result of this implementation strategy, the "Destroy Item" slot is just a client-side implementation detail that means "I don't intend to recreate this item.". Additionally, the long listings of items (by category, etc.) are a client-side interface for choosing which item to create. Picking up an item from such listings sends no packets to the server; only when you put it somewhere does it tell the server to create the item in that location.

This action can be described as "set inventory slot". Picking up an item sets the slot to item ID -1. Placing an item into an inventory slot sets the slot to the specified item. Dropping an item (by clicking outside the window) effectively sets slot -1 to the specified item, which causes the server to spawn the item entity, etc.. All other inventory slots are numbered the same as the non-creative inventory (including slots for the 2x2 crafting menu, even though they aren't visible in the vanilla client).

Packet ID State Bound To Field Name Field Type Notes
0x26 Play Server Slot Short Inventory slot
Clicked Item Slot

更新拼图方块

Sent when Done is pressed on the Jigsaw Block interface.

Packet ID State Bound To Field Name Field Type Notes
0x27 Play Server Location Position Block entity location
Attachment type Identifier
Target pool Identifier
Final state String "Turns into" on the GUI, final_state in NBT

更新结构方块

Packet ID State Bound To Field Name Field Type Notes
0x28 Play Server
Location Position Block entity location
Action VarInt enum An additional action to perform beyond simply saving the given data; see below
Mode VarInt enum One of SAVE (0), LOAD (1), CORNER (2), DATA (3).
Name String
Offset X Byte Between -32 and 32
Offset Y Byte Between -32 and 32
Offset Z Byte Between -32 and 32
Size X Byte Between 0 and 32
Size Y Byte Between 0 and 32
Size Z Byte Between 0 and 32
Mirror VarInt enum One of NONE (0), LEFT_RIGHT (1), FRONT_BACK (2).
Rotation VarInt enum One of NONE (0), CLOCKWISE_90 (1), CLOCKWISE_180 (2), COUNTERCLOCKWISE_90 (3).
Metadata String
Integrity Float Between 0 and 1
Seed VarLong
Flags Byte 0x01: Ignore entities; 0x02: Show air; 0x04: Show bounding box

Possible actions:

  • 0 - Update data
  • 1 - Save the structure
  • 2 - Load the structure
  • 3 - Detect size

The Notchian client uses update data to indicate no special action should be taken (i.e. the done button).

更新告示牌

This message is sent from the client to the server when the “Done” button is pushed after placing a sign.

The server only accepts this packet after Open Sign Editor, otherwise this packet is silently ignored.

Packet ID State Bound To Field Name Field Type Notes
0x29 Play Server Location Position Block Coordinates
Line 1 String (384) First line of text in the sign
Line 2 String (384) Second line of text in the sign
Line 3 String (384) Third line of text in the sign
Line 4 String (384) Fourth line of text in the sign

动画(服务端方)

Sent when the player's arm swings.

Packet ID State Bound To Field Name Field Type Notes
0x2A Play Server Hand VarInt Enum Hand used for the animation. 0: main hand, 1: off hand.

旁观

Teleports the player to the given entity. The player must be in spectator mode.

The Notchian client only uses this to teleport to players, but it appears to accept any type of entity. The entity does not need to be in the same dimension as the player; if necessary, the player will be respawned in the right world. If the given entity cannot be found (or isn't loaded), this packet will be ignored. It will also be ignored if the player attempts to teleport to themselves.

Packet ID State Bound To Field Name Field Type Notes
0x2B Play Server Target Player UUID UUID of the player to teleport to (can also be an entity UUID)

玩家方块放置

Packet ID State Bound To Field Name Field Type Notes
0x2C Play Server Hand VarInt Enum The hand from which the block is placed; 0: main hand, 1: off hand
Location Position Block position
Face VarInt Enum The face on which the block is placed (as documented at Player Digging)
Cursor Position X Float The position of the crosshair on the block, from 0 to 1 increasing from west to east
Cursor Position Y Float The position of the crosshair on the block, from 0 to 1 increasing from bottom to top
Cursor Position Z Float The position of the crosshair on the block, from 0 to 1 increasing from north to south
Inside block Boolean True when the player's head is inside of a block.

Upon placing a block, this packet is sent once.

The Cursor Position X/Y/Z fields (also known as in-block coordinates) are calculated using raytracing. The unit corresponds to sixteen pixels in the default resource pack. For example, let's say a slab is being placed against the south face of a full block. The Cursor Position X will be higher if the player was pointing near the right (east) edge of the face, lower if pointing near the left. The Cursor Position Y will be used to determine whether it will appear as a bottom slab (values 0.0–0.5) or as a top slab (values 0.5-1.0). The Cursor Position Z should be 1.0 since the player was looking at the southernmost part of the block.

Inside block is true when a player's head (specifically eyes) are inside of a block's collision. In 1.13 and later versions, collision is rather complicated and individual blocks can have multiple collision boxes. For instance, a ring of vines has a non-colliding hole in the middle. This value is only true when the player is directly in the box. In practice, though, this value is only used by scaffolding to place in front of the player when sneaking inside of it (other blocks will place behind when you intersect with them -- try with glass for instance).

使用物品

Sent when pressing the Use Item key (default: right click) with an item in hand.

Packet ID State Bound To Field Name Field Type Notes
0x2D Play Server Hand VarInt Enum Hand used for the animation. 0: main hand, 1: off hand.

状态

Main article: Server List Ping

客户端方

响应

Packet ID State Bound To Field Name Field Type Notes
0x00 Status Client JSON Response String (32767) See Server List Ping#Response

Pong

Packet ID State Bound To Field Name Field Type Notes
0x01 Status Client Payload Long Should be the same as sent by the client

服务端方

请求

Packet ID State Bound To Field Name Field Type Notes
0x00 Status Server no fields

Ping

Packet ID State Bound To Field Name Field Type Notes
0x01 Status Server Payload Long May be any number. Notchian clients use a system-dependent time value which is counted in milliseconds.

登入

The login process is as follows:

  1. C→S: Handshake with Next State set to 2 (login)
  2. C→S: Login Start
  3. S→C: Encryption Request
  4. Client auth
  5. C→S: Encryption Response
  6. Server auth, both enable encryption
  7. S→C: Set Compression (optional)
  8. S→C: Login Success

Set Compression, if present, must be sent before Login Success. Note that anything sent after Set Compression must use the Post Compression packet format.

For unauthenticated and localhost connections (either of the two conditions is enough for an unencrypted connection) there is no encryption. In that case Login Start is directly followed by Login Success.

See Protocol Encryption for details.

客户端方

断开连接(登入)

Packet ID State Bound To Field Name Field Type Notes
0x00 Login Client Reason Chat

加密请求

Packet ID State Bound To Field Name Field Type Notes
0x01 Login Client Server ID String (20) Appears to be empty
Public Key Length VarInt Length of Public Key
Public Key Byte Array
Verify Token Length VarInt Length of Verify Token. Always 4 for Notchian servers.
Verify Token Byte Array A sequence of random bytes generated by the server

See Protocol Encryption for details.

登入成功

Packet ID State Bound To Field Name Field Type Notes
0x02 Login Client UUID String (36) Unlike in other packets, this field contains the UUID as a string with hyphens.
Username String (16)

This packet switches the connection state to play.

设置压缩

Enables compression. If compression is enabled, all following packets are encoded in the compressed packet format. Negative values will disable compression, meaning the packet format should remain in the uncompressed packet format. However, this packet is entirely optional, and if not sent, compression will also not be enabled (the notchian server does not send the packet when compression is disabled).

Packet ID State Bound To Field Name Field Type Notes
0x03 Login Client Threshold VarInt Maximum size of a packet before it is compressed

登入插件请求

Used to implement a custom handshaking flow together with Login Plugin Response.

Unlike plugin messages in "play" mode, these messages follow a lock-step request/response scheme, where the client is expected to respond to a request indicating whether it understood. The notchian client always responds that it hasn't understood, and sends an empty payload.

Packet ID State Bound To Field Name Field Type Notes
0x04 Login Client Message ID VarInt Generated by the server - should be unique to the connection.
Channel Identifier Name of the plugin channel used to send the data
Data Byte Array Any data, depending on the channel. The length of this array must be inferred from the packet length.

服务端方

登入开始

Packet ID State Bound To Field Name Field Type Notes
0x00 Login Server Name String (16) Player's Username

加密响应

Packet ID State Bound To Field Name Field Type Notes
0x01 Login Server Shared Secret Length VarInt Length of Shared Secret
Shared Secret Byte Array
Verify Token Length VarInt Length of Verify Token
Verify Token Byte Array

See Protocol Encryption for details.

登入插件响应

Packet ID State Bound To Field Name Field Type Notes
0x02 Login Server Message ID VarInt Should match ID from server.
Successful Boolean true if the client understands the request, false otherwise. When false, no payload follows.
Data Optional Byte Array Any data, depending on the channel. The length of this array must be inferred from the packet length.