Overview
Gophertunnel provides a high-level API for establishing Minecraft Bedrock Edition connections. The library handles the complete connection lifecycle including protocol negotiation, encryption, compression, and packet management.Client Connections
Dialer
TheDialer type allows you to configure and establish client connections to Minecraft servers. It’s located in minecraft/dial.go.
Logger for packet handling errors. By default, errors are not logged.
HTTP client for outbound requests (OpenID config, JWKs). Defaults to
http.DefaultClient.Client data including skin, locale, and UUIDs. A default is used if empty.
Identity data with username, UUID, and XUID. Obtained via auth if TokenSource is set.
Source for Microsoft Live Connect tokens used to authenticate to XBOX Live. If nil, no authentication is used.
Pre-obtained XBL token for the
https://multiplayer.minecraft.net relying party.Callback invoked for every packet read/written, including login packets.
Callback to determine whether to download each resource pack. Return true to download.
If true, close connection on unknown packets. If false, return as
packet.Unknown.If true, close connection on invalid packets. If false, skip or return partial data.
Protocol version for communication. Defaults to current protocol from
minecraft/protocol.Rate at which buffered packets are flushed. Default is
time.Second/20. Set negative to disable auto-flush.Enable client blob cache to reduce chunk transmission.
Pass XUID and title ID to server without authentication token. May cause kicks on some servers.
Use pre-1.21.90 authentication behavior. Only for outdated servers.
Establishing a Connection
Simple Connection
Connection with Timeout
Connection with Context
Authenticated Connection
Server Connections
ListenConfig
TheListenConfig type configures server listeners to accept incoming Minecraft client connections. It’s located in minecraft/listener.go.
Logger for client packet handling errors. By default, errors are not logged.
HTTP client for OpenID config/JWKs when authentication is enabled.
If true, skip XBOX Live verification for connecting players.
Maximum player count. If zero, unlimited players are accepted and count is dynamically updated.
If false, close connection on unknown packets. If true, return as
packet.Unknown.If false, close connection on invalid packets. If true, handle partial/oversized packets.
Provides server status info for pings. Defaults to
ListenerStatusProvider.List of accepted protocol versions. Current protocol is always added. Clients with other versions are disconnected.
Compression algorithm for packets. Defaults to
packet.DefaultCompression.Selects compression per connection based on protocol. Defaults to returning
Compression.Minimum data size in bytes to trigger compression. Default is 256. Set to -1 to disable compression.
Packet flush rate for buffering. Default is
time.Second/20. Negative value disables auto-flush.Resource packs sent to clients on join. Modify after listen with
AddResourcePack()/RemoveResourcePack().If true, clients must accept texture packs to join.
Called before sending ResourcePacksInfo to customize packs per client.
Callback for every packet read/written on accepted connections.
Maximum decompressed packet length. Default is 16MB. Negative disables limit.
Creating a Listener
Basic Server
Authenticated Server
Server with Resource Packs
The Conn Type
BothDialer.Dial() and Listener.Accept() return a *minecraft.Conn, which represents an active Minecraft connection. This type is defined in minecraft/conn.go.
Key Methods
ReadPacket() must not be called on multiple goroutines simultaneously, but WritePacket() is safe for concurrent use.Connection Context
Each connection has an associated context that is cancelled when the connection closes:Network Protocol
Gophertunnel supports the “raknet” network, which is the standard RakNet-based protocol used by Minecraft Bedrock Edition.The network string “raknet” is typically used for both Dial and Listen operations. This represents the RakNet protocol over UDP.