Skip to content

API reference / @jsprismarine/client / ClientPacketRegistry

Class: ClientPacketRegistry ​

Defined in: client/src/net/ClientPacketRegistry.ts:77

Which packet class handles which id, with no server anywhere in the signature.

The server's registry is built around a Server - it logs through it, and its handlers take it as their second argument - which is exactly why the client could not reuse it. This one maps ids to codecs and stops there; what to do with a decoded packet is the caller's business, and on the client that answer differs between the login sequence, the game session and a bot's behavior script.

An id with no class registered is not an error. A client meets packets it has no use for from its first join - the server sends crafting data and biome definitions before the player can move - and refusing to proceed until all of them are implemented would mean implementing all of them before anything works at all.

Constructors ​

Constructor ​

new ClientPacketRegistry(protocolVersion?): ClientPacketRegistry

Defined in: client/src/net/ClientPacketRegistry.ts:85

Creates a registry that decodes version-gated packets for one negotiated protocol.

Parameters ​

protocolVersion? ​

number = v2193.protocolVersion

The protocol version used by the connection.

Returns ​

ClientPacketRegistry

Methods ​

decode() ​

decode(buffer): DecodedPacket | null

Defined in: client/src/net/ClientPacketRegistry.ts:114

Decodes one packet, or returns null if nothing is registered for its id.

Parameters ​

buffer ​

Buffer

a single packet as it came out of the batch, header included.

Returns ​

DecodedPacket | null


getUnknownIds() ​

getUnknownIds(): number[]

Defined in: client/src/net/ClientPacketRegistry.ts:137

Every id seen that nothing was registered for.

Kept because it is the honest measure of how much of the protocol is implemented, and because it is what a "what is this server sending that we ignore?" question needs.

Returns ​

number[]


has() ​

has(id): boolean

Defined in: client/src/net/ClientPacketRegistry.ts:105

Parameters ​

id ​

number

Returns ​

boolean


register() ​

register(constructor): void

Defined in: client/src/net/ClientPacketRegistry.ts:91

Registers a packet class under its default network id.

Parameters ​

constructor ​

PacketConstructor

The packet class to register.

Returns ​

void


registerAll() ​

registerAll(constructors): void

Defined in: client/src/net/ClientPacketRegistry.ts:101

Parameters ​

constructors ​

readonly PacketConstructor[]

Returns ​

void


readPacketId() ​

static readPacketId(buffer): number

Defined in: client/src/net/ClientPacketRegistry.ts:148

Peeks the id without consuming anything.

The header is an unsigned varint, so the id is not simply the first byte - which is how the server reads it, and which works only because every id it handles happens to fit in seven bits or to have a low byte that collides with nothing.

Parameters ​

buffer ​

Buffer

Returns ​

number