Packets
Gate provides a comprehensive packet system for handling Minecraft protocol communication. Every packet implements theproto.Packet interface and supports version-aware encoding and decoding.
Packet Interface
All packets in Gate implement theproto.Packet interface:
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:Keep Alive Packets
Keep alive packets maintain the connection:- 1.12.2+: int64
- 1.8-1.12.1: varint
- Before 1.8: int32
Chat Packets
Chat messages use different packet structures based on version:Disconnect Packets
Disconnect packets terminate connections with a reason:Join Game Packets
Join game packets are sent when a player joins a world:Packet Encoding
Packets use protocol-aware encoding utilities fromgo.minekube.com/gate/pkg/edition/java/proto/util:
Common Encoding Functions
| Function | Description |
|---|---|
util.WriteVarInt(w, int) | Writes a variable-length integer |
util.WriteString(w, string) | Writes a length-prefixed UTF-8 string |
util.WriteInt16(w, int16) | Writes a 16-bit integer |
util.WriteInt32(w, int32) | Writes a 32-bit integer |
util.WriteInt64(w, int64) | Writes a 64-bit integer |
util.WriteByte(w, byte) | Writes a single byte |
util.WriteUUID(w, uuid.UUID) | Writes a UUID |
util.WriteBytes(w, []byte) | Writes a byte array |
Packet Decoding
Decoding mirrors encoding with version-aware logic:Common Decoding Functions
| Function | Description |
|---|---|
util.ReadVarInt(r) | Reads a variable-length integer |
util.ReadString(r) | Reads a length-prefixed UTF-8 string |
util.ReadStringMax(r, max) | Reads a string with maximum length |
util.ReadInt16(r) | Reads a 16-bit integer |
util.ReadInt32(r) | Reads a 32-bit integer |
util.ReadInt64(r) | Reads a 64-bit integer |
util.ReadByte(r) | Reads a single byte |
util.ReadUUID(r) | Reads a UUID |
io.ReadAll(r) | Reads remaining bytes |
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, extendbackendPlaySessionHandler:
Packet Location Reference
Packets are organized by category in:See Also
- Plugin Channels - Plugin messaging system
- Sound System - Sound packet handling
- Protocol Documentation - Minecraft protocol reference
- pkg.go.dev - Complete API documentation

