Skip to main content

Packets

Gate provides a comprehensive packet system for handling Minecraft protocol communication. Every packet implements the proto.Packet interface and supports version-aware encoding and decoding.

Packet Interface

All packets in Gate implement the proto.Packet interface:
The PacketContext provides protocol version information, packet direction, and state information needed for version-specific handling.

Common Packet Types

Gate includes packets for all Minecraft protocol states:

Handshake Packets

The handshake packet initiates the connection:
Example:

Keep Alive Packets

Keep alive packets maintain the connection:
The encoding varies by protocol version:
  • 1.12.2+: int64
  • 1.8-1.12.1: varint
  • Before 1.8: int32
Example:

Chat Packets

Chat messages use different packet structures based on version:
Example:

Disconnect Packets

Disconnect packets terminate connections with a reason:
Example:

Join Game Packets

Join game packets are sent when a player joins a world:
This packet demonstrates version-specific fields that are only encoded/decoded for certain protocol versions.

Packet Encoding

Packets use protocol-aware encoding utilities from go.minekube.com/gate/pkg/edition/java/proto/util:

Common Encoding Functions

Packet Decoding

Decoding mirrors encoding with version-aware logic:

Common Decoding Functions

Version-Specific Encoding

Packets often need different encoding based on the protocol version:

Packet Interception

You can intercept and modify packets in session handlers:

Intercepting Specific Packets

For backend server packets, extend backendPlaySessionHandler:

Packet Location Reference

Packets are organized by category in:

See Also