Skip to main content

Version to protocol

Minecraft Java Edition tells versions apart not by name but by a number, the protocol version. It decides the layout of a packet's fields: the library keeps several layouts for the same packet, and the number that comes from the calling code picks the one to use. That number is passed as a parameter to SendAsync, PacketIo.TryDecode, PacketFlow.Dispatch, PacketRegistry.TryResolve, and in the first handshake packet:

await client.SendAsync(
new HandshakeSb.SetProtocolPacket(Pv, host, port, 2), Pv);

Supported range

The library supports the range from 1.16 to 26.2. In the code, the boundaries are named constants:

public const int StartProtocol = V1_16_Protocol; // 735
public const int LatestProtocol = V26_2_Protocol; // 776

Mapping table

MinecraftVersion.FromProtocol reduces a number to a version. Snapshots and pre-releases of 1.16.2 collapse to the string 1.16.2, and 1.16.3-rc1 collapses to 1.16.3. The full, constantly updated table of versions and protocol numbers is on the Protocol version page on minecraft.wiki.

Game versionProtocol
1.16735
1.16.1736
1.16.2751
1.16.3753
1.16.4-1.16.5754
1.17755
1.17.1756
1.18-1.18.1757
1.18.2758
1.19759
1.19.2760
1.19.3761
1.19.4762
1.20-1.20.1763
1.20.2764
1.20.3-1.20.4765
1.20.5-1.20.6766
1.21-1.21.1767
1.21.3768
1.21.4769
1.21.5770
1.21.6771
1.21.7-1.21.8772
1.21.9-1.21.10773
1.21.11774
26.1-26.1.2775
26.2776

Getting the number from code

MinecraftVersion carries named constants, a reverse lookup, and the full list. There is no need to copy the table into application code:

int pv = MinecraftVersion.V1_21_11; // implicit to int, gives 774
string name = MinecraftVersion.FromProtocol(772).Name; // "1.21.7–1.21.8"
foreach (var v in MinecraftVersion.AllVersions)
Console.WriteLine($"{v.Name} -> {v.Protocol}");

FromProtocol throws NotSupportedException on a number outside the table, including inside the 735-776 range, if it does not match a version.

A number outside the range

MinecraftClient does no check on input. The check comes from the packets themselves. SetProtocolPacket, and any packet with layouts that vary by version, declares a range:

[ProtocolSupport(MinecraftVersion.StartProtocol, MinecraftVersion.LatestProtocol)]

A number outside the range produces ProtocolNotSupportException on the first attempt to send or parse a packet, before it reaches the network. The exception carries the type name, the number, and the ranges the type exists on.

Next