protocol

package
v0.0.0-...-e969f47 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2018 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package protocol provides definitions for Minecraft packets as well as methods for reading and writing them

Index

Constants

View Source
const (
	// SupportedProtocolVersion is current protocol version this package defines
	// 340 = 1.12.2
	SupportedProtocolVersionName = "1.12.2"
	SupportedProtocolVersion     = 340
)

Variables

View Source
var (
	// ErrVarIntTooLarge is returned when a read varint was too large
	// (more than 5 bytes)
	ErrVarIntTooLarge = errors.New("VarInt too large")
	// ErrVarLongTooLarge is returned when a read varint was too large
	// (more than 10 bytes)
	ErrVarLongTooLarge = errors.New("VarLong too large")
)

Functions

func ReadBool

func ReadBool(r io.Reader) (bool, error)

ReadBool reads a single byte from the reader as a bool.

func ReadByte

func ReadByte(r io.Reader) (byte, error)

ReadByte reads a single byte from the Reader. If the Reader is a ByteReader then that will be used instead.

func ReadNBT

func ReadNBT(r io.Reader) (*nbt.Compound, error)

ReadNBT reads an nbt tag from the reader. Returns nil if there is no tag.

func ReadString

func ReadString(r io.Reader) (string, error)

ReadString reads a VarInt prefixed utf-8 string to the reader.

func WriteBool

func WriteBool(w io.Writer, b bool) error

WriteBool writes a bool to the writer as a single byte.

func WriteByte

func WriteByte(w io.Writer, b byte) error

WriteByte writes a single byte to the writer. If the Writer is a ByteWriter then that will be used instead.

func WriteLong

func WriteLong(w io.Writer, l uint64) error

func WriteNBT

func WriteNBT(w io.Writer, n *nbt.Compound) error

WriteNBT writes an nbt tag to the wrtier. nil can be used to specify that there isn't a tag.

func WriteString

func WriteString(w io.Writer, str string) error

WriteString writes a VarInt prefixed utf-8 string to the writer.

func WriteVarInt

func WriteVarInt(w io.Writer, i VarInt) error

WriteVarInt encodes the passed VarInt into the writer.

func WriteVarLong

func WriteVarLong(w io.Writer, i VarLong) error

WriteVarLong encodes the passed VarLong into the writer.

Types

type Advancement

type Advancement struct {
	Key          string
	HasParent    bool
	Parent       string `if:".HasParent == true"`
	HasDisplay   bool
	Display      AdvancementDisplay `if:".HasDisplay == true"`
	Criteria     []string           `length:"VarInt"`
	Requirements []Requirement      `length:"VarInt"`
}

type AdvancementDisplay

type AdvancementDisplay struct {
	Title             format.AnyComponent `as:"json"`
	Description       format.AnyComponent `as:"json"`
	Item              ItemStack           `as:"raw"`
	FrameType         VarInt
	Flags             int32
	BackgroundTexture string `if:".Flags&1 == 1"`
	X, Y              float32
}

type AdvancementTab

type AdvancementTab struct {
	Action VarInt
	TabID  string `if:".Action==0"`
}

This is a Minecraft packet ID: 0x19

type Advancements

type Advancements struct {
	Reset        bool
	Advancements []Advancement `length:"VarInt"`
	Remove       []string      `length:"VarInt"`
	Progress     []Progress    `length:"VarInt"`
}

This is a Minecraft packet ID: 0x4D

type Animation

type Animation struct {
	EntityID    VarInt
	AnimationID byte
}

Animation is sent by the server to play an animation on a specific entity.

This is a Minecraft packet ID: 0x06

type ArmSwing

type ArmSwing struct {
	Hand VarInt
}

ArmSwing is sent by the client when the player left clicks (to swing their arm).

This is a Minecraft packet ID: 0x1D

type BlockAction

type BlockAction struct {
	Location  Position
	Byte1     byte
	Byte2     byte
	BlockType VarInt
}

BlockAction triggers different actions depending on the target block.

This is a Minecraft packet ID: 0x0A

type BlockBreakAnimation

type BlockBreakAnimation struct {
	EntityID VarInt
	Location Position
	Stage    int8
}

BlockBreakAnimation is used to create and update the block breaking animation played when a player starts digging a block.

This is a Minecraft packet ID: 0x08

type BlockChange

type BlockChange struct {
	Location Position
	BlockID  VarInt
}

BlockChange is used to update a single block on the client.

This is a Minecraft packet ID: 0x0B

type BlockChangeRecord

type BlockChangeRecord struct {
	XZ      byte
	Y       byte
	BlockID VarInt
}

BlockChangeRecord is a location/id record of a block to be updated

type BossBar

type BossBar struct {
	UUID   UUID `as:"raw"`
	Action VarInt
	Title  format.AnyComponent `as:"json" if:".Action == 0 .Action == 3"`
	Health float32             `if:".Action == 0 .Action == 2"`
	Color  VarInt              `if:".Action == 0 .Action == 4"`
	Style  VarInt              `if:".Action == 0 .Action == 4"`
	Flags  byte                `if:".Action == 0 .Action == 5"`
}

BossBar displays and/or changes a boss bar that is displayed on the top of the client's screen. This is normally used for bosses such as the ender dragon or the wither.

This is a Minecraft packet ID: 0x0C

type Camera

type Camera struct {
	TargetID VarInt
}

Camera causes the client to spectate the entity with the passed id. Use the player's id to de-spectate.

This is a Minecraft packet ID: 0x39

type ChangeGameState

type ChangeGameState struct {
	Reason byte
	Value  float32
}

ChangeGameState is used to modify the game's state like gamemode or weather.

This is a Minecraft packet ID: 0x1E

type ChatMessage

type ChatMessage struct {
	Message string
}

ChatMessage is sent by the client when it sends a chat message or executes a command (prefixed by '/').

This is a Minecraft packet ID: 0x02

type ChunkData

type ChunkData struct {
	ChunkX, ChunkZ int32
	New            bool
	BitMask        VarInt
	Data           []byte          `length:"VarInt" nolimit:"true"`
	BlockEntities  []*nbt.Compound `length:"VarInt" nolimit:"true"`
}

ChunkData sends or updates a single chunk on the client. If New is set then biome data should be sent too.

This is a Minecraft packet ID: 0x20

type ChunkUnload

type ChunkUnload struct {
	X int32
	Z int32
}

ChunkUnload tells the client to unload the chunk at the specified position.

This is a Minecraft packet ID: 0x1D

type ClickWindow

type ClickWindow struct {
	ID           byte
	Slot         int16
	Button       byte
	ActionNumber int16
	Mode         byte
	ClickedItem  ItemStack `as:"raw"`
}

ClickWindow is sent when the client clicks in a window.

This is a Minecraft packet ID: 0x07

type ClientAbilities

type ClientAbilities struct {
	Flags        byte
	FlyingSpeed  float32
	WalkingSpeed float32
}

ClientAbilities is used to modify the players current abilities. Currently flying is the only one

This is a Minecraft packet ID: 0x13

type ClientSettings

type ClientSettings struct {
	Locale             string
	ViewDistance       byte
	ChatMode           byte
	ChatColors         bool
	DisplayedSkinParts byte
	MainHand           VarInt
}

ClientSettings is sent by the client to update its current settings.

This is a Minecraft packet ID: 0x04

type ClientStatus

type ClientStatus struct {
	ActionID VarInt
}

ClientStatus is sent to update the client's status

This is a Minecraft packet ID: 0x03

type CloseWindow

type CloseWindow struct {
	ID byte
}

CloseWindow is sent when the client closes a window.

This is a Minecraft packet ID: 0x08

type CollectItem

type CollectItem struct {
	CollectedEntityID VarInt
	CollectorEntityID VarInt
	Count             VarInt
}

CollectItem causes the collected item to fly towards the collector. This does not destroy the entity.

This is a Minecraft packet ID: 0x4B

type CombatEvent

type CombatEvent struct {
	Event    VarInt
	Duration VarInt              `if:".Event == 1"`
	PlayerID VarInt              `if:".Event == 2"`
	EntityID int32               `if:".Event == 1 .Event == 2"`
	Message  format.AnyComponent `as:"json" if:".Event == 2"`
}

CombatEvent is used for... you know, I never checked. I have no clue.

This is a Minecraft packet ID: 0x2D

type ConfirmTransaction

type ConfirmTransaction struct {
	ID           byte
	ActionNumber int16
	Accepted     bool
}

ConfirmTransaction notifies the client whether a transaction was successful or failed (e.g. due to lag).

This is a Minecraft packet ID: 0x11

type ConfirmTransactionServerbound

type ConfirmTransactionServerbound struct {
	ID           byte
	ActionNumber int16
	Accepted     bool
}

ConfirmTransactionServerbound is a reply to ConfirmTransaction.

This is a Minecraft packet ID: 0x05

type Conn

type Conn struct {
	State State

	Logger func(read bool, packet Packet)
	// contains filtered or unexported fields
}

Conn is a connection from or to a Minecraft client.

The Minecraft protocol as multiple states that it switches between during login/status pinging, the state may be set using the State field.

func Accept

func Accept(c net.Conn, host string, port int) (*Conn, error)

Accepts an incoming connection

func Dial

func Dial(address string) (*Conn, error)

Dial creates a connection to a Minecraft server at the passed address. The address is in same format as the vanilla client takes it

host:port
// or
host

If the port isn't provided then a SRV lookup is performed and if successful it will continue connecting using the returned address. If the lookup fails then the port is assumed to be 25565.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the underlying connection

func (*Conn) EnableEncryption

func (c *Conn) EnableEncryption(key []byte) error

EnableEncryption enables cfb8 encryption on the protocol using the passed key.

func (*Conn) LoginToServer

func (c *Conn) LoginToServer(profile mojang.Profile) (err error)

LoginToServer sends the necessary packets to join a server. This also authenticates the request with mojang for online mode connections. This stops before LoginSuccess (or any other preceding packets).

func (*Conn) ReadPacket

func (c *Conn) ReadPacket() (Packet, error)

ReadPacket deserializes a packet from the underlying connection, optionally decrypting and/or decompressing

func (*Conn) RequestStatus

func (c *Conn) RequestStatus() (response StatusReply, ping time.Duration, err error)

RequestStatus starts a status request to the server and returns the results of the request. The connection will be closed after this request.

func (*Conn) SetCompression

func (c *Conn) SetCompression(threshold int)

SetCompression changes the threshold at which packets are compressed.

func (*Conn) WriteBuffer

func (c *Conn) WriteBuffer(buf *bytes.Buffer) error

func (*Conn) WritePacket

func (c *Conn) WritePacket(packet Packet) error

WritePacket serializes the packet to the underlying connection, optionally encrypting and/or compressing

func (*Conn) WriteRaw

func (c *Conn) WriteRaw(buf []byte) error

type CraftRecipeRequest

type CraftRecipeRequest struct {
	WindowID byte
	RecipeID VarInt
	MakeAll  bool
}

CraftRecipeRequest is used to craft items.

This is a Minecraft packet ID: 0x12

type CraftRecipeResponse

type CraftRecipeResponse struct {
	WindowID byte
	Recipe   VarInt
}

CraftRecipeResponse is used to respond to the CraftRecipeRequest packet.

This is a Minecraft packet ID: 0x2B

type CraftingBookData

type CraftingBookData struct {
	Type               VarInt
	RecipeID           float32 `if:".Type==0"`
	CraftingBookOpen   bool    `if:".Type==1"`
	CraftingBookFilter bool    `if:".Type==1"`
}

This is a Minecraft packet ID: 0x17

type CreativeInventoryAction

type CreativeInventoryAction struct {
	Slot        int16
	ClickedItem ItemStack `as:"raw"`
}

CreativeInventoryAction is sent when the client clicks in the creative inventory. This is used to spawn items in creative.

This is a Minecraft packet ID: 0x1B

type CriterionProgress

type CriterionProgress struct {
	Key          string
	Achieved     bool
	AchievedTime int64 `if:".Achieved == true"`
}

type Decoder

type Decoder struct {
	Reader io.Reader
}

func (*Decoder) ReadBody

func (d *Decoder) ReadBody() ([]byte, error)

func (*Decoder) ReadSpecific

func (d *Decoder) ReadSpecific(p Packet) error

type Disconnect

type Disconnect struct {
	Reason format.AnyComponent `as:"json"`
}

Disconnect causes the client to disconnect displaying the passed reason.

This is a Minecraft packet ID: 0x1A

type Effect

type Effect struct {
	EffectID        int32
	Location        Position
	Data            int32
	DisableRelative bool
}

Effect plays a sound effect or particle at the target location with the volume (of sounds) being relative to the player's position unless DisableRelative is set to true.

This is a Minecraft packet ID: 0x21

type EnchantItem

type EnchantItem struct {
	ID          byte
	Enchantment byte
}

EnchantItem is sent when the client enchants an item.

This is a Minecraft packet ID: 0x06

type EncryptionRequest

type EncryptionRequest struct {
	// Generally empty, left in from legacy auth
	// but is still used by the client if provided
	ServerID string
	// A RSA Public key serialized in x.509 PRIX format
	PublicKey []byte `length:"VarInt"`
	// Token used by the server to verify encryption is working
	// correctly
	VerifyToken []byte `length:"VarInt"`
}

EncryptionRequest is sent by the server if the server is in online mode. If it is not sent then its assumed the server is in offline mode.

This is a Minecraft packet ID: 0x01

type EncryptionResponse

type EncryptionResponse struct {
	// The key for the AES/CFB8 cipher encrypted with the
	// public key
	SharedSecret []byte `length:"VarInt"`
	// The verify token from the request encrypted with the
	// public key
	VerifyToken []byte `length:"VarInt"`
}

EncryptionResponse is sent as a reply to EncryptionRequest. All packets following this one must be encrypted with AES/CFB8 encryption.

This is a Minecraft packet ID: 0x01

type Entity

type Entity struct {
	EntityID VarInt
}

Entity does nothing. It is a result of subclassing used in Minecraft.

This is a Minecraft packet ID: 0x25

type EntityAction

type EntityAction struct {
	EntityID int32
	ActionID byte
}

EntityAction causes an entity to preform an action based on the passed id.

This is a Minecraft packet ID: 0x1B

type EntityAttach

type EntityAttach struct {
	EntityID int32
	Vehicle  int32
}

EntityAttach attaches to entities together by leashing. -1 can be used at the EntityID to deattach.

This is a Minecraft packet ID: 0x3D

type EntityDestroy

type EntityDestroy struct {
	EntityIDs []VarInt `length:"VarInt"`
}

EntityDestroy destroys the entities with the ids in the provided slice.

This is a Minecraft packet ID: 0x32

type EntityEffect

type EntityEffect struct {
	EntityID      VarInt
	EffectID      int8
	Amplifier     int8
	Duration      VarInt
	HideParticles bool
}

EntityEffect applies a status effect to an entity for a given duration.

This is a Minecraft packet ID: 0x4F

type EntityEquipment

type EntityEquipment struct {
	EntityID VarInt
	Slot     VarInt
	Item     ItemStack `as:"raw"`
}

EntityEquipment is sent to display an item on an entity, like a sword or armor. Slot 0 is the held item and slots 1 to 4 are boots, leggings chestplate and helmet respectively.

This is a Minecraft packet ID: 0x3F

type EntityHeadLook

type EntityHeadLook struct {
	EntityID VarInt
	HeadYaw  int8
}

EntityHeadLook rotates an entity's head to the new angle.

This is a Minecraft packet ID: 0x36

type EntityLook

type EntityLook struct {
	EntityID   VarInt
	Yaw, Pitch int8
	OnGround   bool
}

EntityLook rotates the entity to the new angles provided.

This is a Minecraft packet ID: 0x28

type EntityLookAndMove

type EntityLookAndMove struct {
	EntityID               VarInt
	DeltaX, DeltaY, DeltaZ int16
	Yaw, Pitch             int8
	OnGround               bool
}

EntityLookAndMove is a combination of EntityMove and EntityLook.

This is a Minecraft packet ID: 0x27

type EntityMetadata

type EntityMetadata struct {
	EntityID VarInt
	Metadata Metadata
}

EntityMetadata updates the metadata for an entity.

This is a Minecraft packet ID: 0x3C

type EntityMove

type EntityMove struct {
	EntityID               VarInt
	DeltaX, DeltaY, DeltaZ int16
	OnGround               bool
}

EntityMove moves the entity with the id by the offsets provided.

This is a Minecraft packet ID: 0x26

type EntityProperties

type EntityProperties struct {
	EntityID   VarInt
	Properties []EntityProperty `length:"int32"`
}

EntityProperties updates the properties for an entity.

This is a Minecraft packet ID: 0x4E

type EntityProperty

type EntityProperty struct {
	Key       string
	Value     float64
	Modifiers []PropertyModifier `length:"VarInt"`
}

EntityProperty is a key/value pair with optional modifiers. Used by EntityProperties.

type EntityRemoveEffect

type EntityRemoveEffect struct {
	EntityID VarInt
	EffectID int8
}

EntityRemoveEffect removes an effect from an entity.

This is a Minecraft packet ID: 0x33

type EntityTeleport

type EntityTeleport struct {
	EntityID   VarInt
	X, Y, Z    float64
	Yaw, Pitch int8
	OnGround   bool
}

EntityTeleport teleports the entity to the target location. This is sent if the entity moves further than EntityMove allows.

This is a Minecraft packet ID: 0x4C

type EntityUsedBed

type EntityUsedBed struct {
	EntityID VarInt
	Location Position
}

EntityUsedBed is sent by the server when a player goes to bed.

This is a Minecraft packet ID: 0x30

type EntityVelocity

type EntityVelocity struct {
	EntityID                        VarInt
	VelocityX, VelocityY, VelocityZ int16
}

EntityVelocity sets the velocity of an entity in 1/8000 of a block per a tick.

This is a Minecraft packet ID: 0x3E

type Explosion

type Explosion struct {
	X, Y, Z                         float32
	Radius                          float32
	Records                         []ExplosionRecord `length:"int32"`
	VelocityX, VelocityY, VelocityZ float32
}

Explosion is sent when an explosion is triggered (tnt, creeper etc). This plays the effect and removes the effected blocks.

This is a Minecraft packet ID: 0x1C

type ExplosionRecord

type ExplosionRecord struct {
	X, Y, Z int8
}

ExplosionRecord is used by explosion to mark an affected block.

type Handshake

type Handshake struct {
	// The protocol version of the connecting client
	ProtocolVersion VarInt
	// The hostname the client connected to
	Host string
	// The port the client connected to
	Port uint16
	// The next protocol state the client wants
	Next VarInt
}

Handshake is the first packet sent in the protocol. Its used for deciding if the request is a client is requesting status information about the server (MOTD, players etc) or trying to login to the server.

The host and port fields are not used by the vanilla server but are there for virtual server hosting to be able to redirect a client to a target server with a single address + port.

Some modified servers/proxies use the handshake field differently, packing information into the field other than the hostname due to the protocol not providing any system for custom information to be transfered by the client to the server until after login.

This is a Minecraft packet ID: 0x00

type HeldItemChange

type HeldItemChange struct {
	Slot int16
}

HeldItemChange is sent when the player changes the currently active hotbar slot.

This is a Minecraft packet ID: 0x1A

type ItemStack

type ItemStack struct {
	ID     int16
	Count  byte
	Damage int16
	NBT    *nbt.Compound
}

ItemStack is a stack of items of a single type that can be serilized in the protocol.

func (*ItemStack) Deserialize

func (i *ItemStack) Deserialize(r io.Reader) error

Deserialize reads an item stack from the reader into this item stack.

func (*ItemStack) Serialize

func (i *ItemStack) Serialize(w io.Writer) error

Serialize writes the item stack into the writer.

type JoinGame

type JoinGame struct {
	// The entity id the client will be referenced by
	EntityID int32
	// The starting gamemode of the client
	Gamemode byte
	// The dimension the client is starting in
	Dimension int32
	// The difficuilty setting for the server
	Difficulty byte
	// The max number of players on the server
	MaxPlayers byte
	// The level type of the server
	LevelType string
	// Whether the client should reduce the amount of debug
	// information it displays in F3 mode
	ReducedDebugInfo bool
}

JoinGame is sent after completing the login process. This sets the initial state for the client.

This is a Minecraft packet ID: 0x23

type KeepAliveClientbound

type KeepAliveClientbound struct {
	ID int64
}

KeepAliveClientbound is sent by a server to check if the client is still responding and keep the connection open. The client should reply with the KeepAliveServerbound packet setting ID to the same as this one.

This is a Minecraft packet ID: 0x1F

type KeepAliveServerbound

type KeepAliveServerbound struct {
	ID int64
}

KeepAliveServerbound is sent by a client as a response to a KeepAliveClientbound. If the client doesn't reply the server may disconnect the client.

This is a Minecraft packet ID: 0x0B

type LoginDisconnect

type LoginDisconnect struct {
	Reason format.AnyComponent `as:"json"`
}

LoginDisconnect is sent by the server if there was any issues authenticating the player during login or the general server issues (e.g. too many players).

This is a Minecraft packet ID: 0x00

type LoginStart

type LoginStart struct {
	Username string
}

LoginStart is sent immeditately after switching into the login state. The passed username is used by the server to authenticate the player in online mode.

This is a Minecraft packet ID: 0x00

type LoginSuccess

type LoginSuccess struct {
	// String encoding of a uuid (with hyphens)
	UUID     string
	Username string
}

LoginSuccess is sent by the server if the player successfully authenicates with the session servers (online mode) or straight after LoginStart (offline mode).

This is a Minecraft packet ID: 0x02

type MapIcon

type MapIcon struct {
	DirectionType int8
	X, Z          int8
}

MapIcon is used by Maps

type Maps

type Maps struct {
	ItemDamage       VarInt
	Scale            int8
	TrackingPosition bool
	Icons            []MapIcon `length:"VarInt"`
	Columns          byte
	Rows             byte   `if:".Columns>0"`
	X                byte   `if:".Columns>0"`
	Z                byte   `if:".Columns>0"`
	Data             []byte `if:".Columns>0" length:"VarInt"`
}

Maps updates a single map's contents

This is a Minecraft packet ID: 0x24

type MetaCompound

type MetaCompound struct {
	*nbt.Compound
}

type Metadata

type Metadata map[int]interface{}

Metadata is a simple index -> value map used in the Minecraft protocol. A limited number of types are supported:

int8
int16
int32
float32
string
ItemStack
[]int32
[]float32
VarInt
UUID
format.AnyComponent

type MultiBlockChange

type MultiBlockChange struct {
	ChunkX, ChunkZ int32
	Records        []BlockChangeRecord `length:"VarInt"`
}

MultiBlockChange is used to update a batch of blocks in a single packet.

This is a Minecraft packet ID: 0x10

type NamedSoundEffect

type NamedSoundEffect struct {
	Sound         string
	SoundCategory VarInt
	X, Y, Z       int32
	Volume, Pitch float32
}

This is a Minecraft packet ID: 0x19

type NextState

type NextState VarInt
const (
	NextStateStatus NextState = 1
	NextStateLogin  NextState = 2
)

func (NextState) String

func (i NextState) String() string

type Packet

type Packet interface {
	// contains filtered or unexported methods
}

Packet is a structure that can be serialized or deserialized from Minecraft connection

type PacketEncoder

type PacketEncoder struct {
	Writer               io.Writer
	CompressionThreshold int
	ZlibWriter           *zlib.Writer
}

func (*PacketEncoder) EncodePacket

func (e *PacketEncoder) EncodePacket(packet Packet) (*bytes.Buffer, error)

func (*PacketEncoder) WritePacket

func (e *PacketEncoder) WritePacket(packet Packet) error

type Particle

type Particle struct {
	ParticleID                int32
	LongDistance              bool
	X, Y, Z                   float32
	OffsetX, OffsetY, OffsetZ float32
	Speed                     float32
	Count                     int32
	Data                      []VarInt `length:"@particleDataLength"`
}

Particle spawns particles at the target location with the various modifiers. Data's length depends on the particle ID.

This is a Minecraft packet ID: 0x22

type Player

type Player struct {
	OnGround bool
}

Player is used to update the player's on ground status.

This is a Minecraft packet ID: 0x0C

type PlayerAbilities

type PlayerAbilities struct {
	Flags        byte
	FlyingSpeed  float32
	WalkingSpeed float32
}

PlayerAbilities is used to modify the players current abilities. Flying, creative, god mode etc.

This is a Minecraft packet ID: 0x2C

type PlayerAction

type PlayerAction struct {
	EntityID  VarInt
	ActionID  VarInt
	JumpBoost VarInt
}

PlayerAction is sent when a player preforms various actions.

This is a Minecraft packet ID: 0x15

type PlayerBlockPlacement

type PlayerBlockPlacement struct {
	Location                  Position
	Face                      VarInt
	Hand                      VarInt
	CursorX, CursorY, CursorZ float32
}

PlayerBlockPlacement is sent when the client tries to place a block.

This is a Minecraft packet ID: 0x1F

type PlayerDetail

type PlayerDetail struct {
	UUID        UUID                `as:"raw"`
	Name        string              `if:"..Action==0"`
	Properties  []PlayerProperty    `length:"VarInt" if:"..Action==0"`
	GameMode    VarInt              `if:"..Action==0 ..Action == 1"`
	Ping        VarInt              `if:"..Action==0 ..Action == 2"`
	HasDisplay  bool                `if:"..Action==0 ..Action == 3"`
	DisplayName format.AnyComponent `as:"json" if:".HasDisplay == true"`
}

PlayerDetail is used by PlayerInfo

type PlayerDigging

type PlayerDigging struct {
	Status   byte
	Location Position
	Face     byte
}

PlayerDigging is sent when the client starts/stops digging a block. It also can be sent for droppping items and eating/shooting.

This is a Minecraft packet ID: 0x14

type PlayerInfo

type PlayerInfo struct {
	Action  VarInt
	Players []PlayerDetail `length:"VarInt"`
}

PlayerInfo is sent by the server for every player connected to the server to provide skin and username information as well as ping and gamemode info.

This is a Minecraft packet ID: 0x2E

type PlayerListHeaderFooter

type PlayerListHeaderFooter struct {
	Header format.AnyComponent `as:"json"`
	Footer format.AnyComponent `as:"json"`
}

PlayerListHeaderFooter updates the header/footer of the player list.

This is a Minecraft packet ID: 0x4A

type PlayerLook

type PlayerLook struct {
	Yaw, Pitch float32
	OnGround   bool
}

PlayerLook is used to update the player's rotation.

This is a Minecraft packet ID: 0x0F

type PlayerPosition

type PlayerPosition struct {
	X, Y, Z  float64
	OnGround bool
}

PlayerPosition is used to update the player's position.

This is a Minecraft packet ID: 0x0D

type PlayerPositionLook

type PlayerPositionLook struct {
	X, Y, Z    float64
	Yaw, Pitch float32
	OnGround   bool
}

PlayerPositionLook is a combination of PlayerPosition and PlayerLook.

This is a Minecraft packet ID: 0x0E

type PlayerProperty

type PlayerProperty struct {
	Name      string
	Value     string
	IsSigned  bool
	Signature string `if:".IsSigned==true"`
}

PlayerProperty is used by PlayerDetail

type PlayerVehicleMove

type PlayerVehicleMove struct {
	X, Y, Z    float64
	Yaw, Pitch float32
}

PlayerVehicleMove is used to update the location of the player's vehicle.

This is a Minecraft packet ID: 0x10

type PluginMessageClientbound

type PluginMessageClientbound struct {
	Channel string
	Data    []byte `length:"remaining"`
}

PluginMessageClientbound is used for custom messages between the client and server. This is mainly for plugins/mods but vanilla has a few channels registered too.

This is a Minecraft packet ID: 0x18

type PluginMessageServerbound

type PluginMessageServerbound struct {
	Channel string
	Data    []byte `length:"remaining"`
}

PluginMessageServerbound is used for custom messages between the client and server. This is mainly for plugins/mods but vanilla has a few channels registered too.

This is a Minecraft packet ID: 0x09

type Position

type Position uint64

Position is a location in the world packed into a 64 bit integer

func NewPosition

func NewPosition(x, y, z int) Position

NewPosition creates a Position for the given location.

func (Position) String

func (p Position) String() string

String returns a string representation of the position

func (Position) X

func (p Position) X() int

X returns the X component of the position

func (Position) Y

func (p Position) Y() int

Y returns the Y component of the position

func (Position) Z

func (p Position) Z() int

Z returns the Z component of the position

type Progress

type Progress struct {
	Key      string
	Criteria []CriterionProgress `length:"VarInt"`
}

type PropertyModifier

type PropertyModifier struct {
	UUID      UUID `as:"raw"`
	Amount    float64
	Operation int8
}

PropertyModifier is a modifier on a property. Used by EntityProperty.

type Requirement

type Requirement struct {
	Criteria []string `length:"VarInt"`
}

type ResourcePackSend

type ResourcePackSend struct {
	URL  string
	Hash string
}

ResourcePackSend causes the client to check its cache for the requested resource packet and download it if its missing. Once the resource pack is obtained the client will use it.

This is a Minecraft packet ID: 0x34

type ResourcePackStatus

type ResourcePackStatus struct {
	Result VarInt
}

ResourcePackStatus informs the server of the client's current progress in activating the requested resource pack

This is a Minecraft packet ID: 0x18

type Respawn

type Respawn struct {
	Dimension  int32
	Difficulty byte
	Gamemode   byte
	LevelType  string
}

Respawn is sent to respawn the player after death or when they move worlds.

This is a Minecraft packet ID: 0x35

type ScoreboardDisplay

type ScoreboardDisplay struct {
	Position byte
	Name     string
}

ScoreboardDisplay is used to set the display position of a scoreboard.

This is a Minecraft packet ID: 0x3B

type ScoreboardObjective

type ScoreboardObjective struct {
	Name  string
	Mode  byte
	Value string `if:".Mode == 0 .Mode == 2"`
	Type  string `if:".Mode == 0 .Mode == 2"`
}

ScoreboardObjective creates/updates a scoreboard objective.

This is a Minecraft packet ID: 0x42

type SelectAdvancementTab

type SelectAdvancementTab struct {
	HasID bool
	Tab   string `if:".HasID == true`
}

SelectAdvancementTab selects an advancement tab on the client.

This is a Minecraft packet ID: 0x37

type Serializable

type Serializable interface {
	Serialize(w io.Writer) error
	Deserialize(r io.Reader) error
}

Serializable is a type which can be serialized into a packet. This is used by protocol-builder when the struct tag 'as' is set to "raw".

type ServerDifficulty

type ServerDifficulty struct {
	Difficulty byte
}

ServerDifficulty changes the displayed difficulty in the client's menu as well as some ui changes for hardcore.

This is a Minecraft packet ID: 0x0D

type ServerMessage

type ServerMessage struct {
	Message format.AnyComponent `as:"json"`
	// 0 - Chat message, 1 - System message, 2 - Action bar message
	Type byte
}

ServerMessage is a message sent by the server. It could be from a player or just a system message. The Type field controls the location the message is displayed at and when the message is displayed.

This is a Minecraft packet ID: 0x0F

type SetCooldown

type SetCooldown struct {
	ItemID VarInt
	Ticks  VarInt
}

SetCooldown disables a set item (by id) for the set number of ticks

This is a Minecraft packet ID: 0x17

type SetCurrentHotbarSlot

type SetCurrentHotbarSlot struct {
	Slot byte
}

SetCurrentHotbarSlot changes the player's currently selected hotbar item.

This is a Minecraft packet ID: 0x3A

type SetExperience

type SetExperience struct {
	ExperienceBar   float32
	Level           VarInt
	TotalExperience VarInt
}

SetExperience updates the experience bar on the client.

This is a Minecraft packet ID: 0x40

type SetInitialCompression

type SetInitialCompression struct {
	// Threshold where a packet should be sent compressed
	Threshold VarInt
}

SetInitialCompression sets the compression threshold during the login state.

This is a Minecraft packet ID: 0x03

type SetPassengers

type SetPassengers struct {
	EntityID   VarInt
	Passengers []VarInt `length:"VarInt"`
}

This is a Minecraft packet ID: 0x43

type SetSign

type SetSign struct {
	Location Position
	Line1    string
	Line2    string
	Line3    string
	Line4    string
}

SetSign sets the text on a sign after placing it.

This is a Minecraft packet ID: 0x1C

type SignEditorOpen

type SignEditorOpen struct {
	Location Position
}

SignEditorOpen causes the client to open the editor for a sign so that it can write to it. Only sent in vanilla when the player places a sign.

This is a Minecraft packet ID: 0x2A

type SoundEffect

type SoundEffect struct {
	SoundID       VarInt
	Category      VarInt
	X, Y, Z       int32
	Volume, Pitch float32
}

This is a Minecraft packet ID: 0x49

type SpawnExperienceOrb

type SpawnExperienceOrb struct {
	EntityID VarInt
	X, Y, Z  float64
	Count    int16
}

SpawnExperienceOrb spawns a single experience orb into the world when it is in range of the client. The count controls the amount of experience gained when collected.

This is a Minecraft packet ID: 0x01

type SpawnGlobalEntity

type SpawnGlobalEntity struct {
	EntityID VarInt
	Type     byte
	X, Y, Z  float64
}

SpawnGlobalEntity spawns an entity which is visible from anywhere in the world. Currently only used for lightning.

This is a Minecraft packet ID: 0x02

type SpawnMob

type SpawnMob struct {
	EntityID                        VarInt
	UUID                            UUID `as:"raw"`
	Type                            byte
	X, Y, Z                         float64
	Yaw, Pitch                      int8
	HeadPitch                       int8
	VelocityX, VelocityY, VelocityZ int16
	Metadata                        Metadata
}

SpawnMob is used to spawn a living entity into the world when it is in range of the client.

This is a Minecraft packet ID: 0x03

type SpawnObject

type SpawnObject struct {
	EntityID                        VarInt
	UUID                            UUID `as:"raw"`
	Type                            byte
	X, Y, Z                         float64
	Pitch, Yaw                      int8
	Data                            int32
	VelocityX, VelocityY, VelocityZ int16
}

SpawnObject is used to spawn an object or vehicle into the world when it is in range of the client.

This is a Minecraft packet ID: 0x00

type SpawnPainting

type SpawnPainting struct {
	EntityID  VarInt
	UUID      UUID `as:"raw"`
	Title     string
	Location  Position
	Direction byte
}

SpawnPainting spawns a painting into the world when it is in range of the client. The title effects the size and the texture of the painting.

This is a Minecraft packet ID: 0x04

type SpawnPlayer

type SpawnPlayer struct {
	EntityID   VarInt
	UUID       UUID `as:"raw"`
	X, Y, Z    float64
	Yaw, Pitch int8
	Metadata   Metadata
}

SpawnPlayer is used to spawn a player when they are in range of the client. This packet alone isn't enough to display the player as the skin and username information is in the player information packet.

This is a Minecraft packet ID: 0x05

type SpawnPosition

type SpawnPosition struct {
	Location Position
}

SpawnPosition is sent to change the player's current spawn point. Currently only used by the client for the compass.

This is a Minecraft packet ID: 0x46

type SpectateTeleport

type SpectateTeleport struct {
	Target UUID `as:"raw"`
}

SpectateTeleport is sent by clients in spectator mode to teleport to a player.

This is a Minecraft packet ID: 0x1E

type State

type State int

State defined which state the protocol is in.

const (
	Handshaking State = 0
	Play        State = 1
	Status      State = 2
	Login       State = 3
)

States of the protocol. Handshaking is default.

func (State) String

func (i State) String() string

type Statistic

type Statistic struct {
	Name  string
	Value VarInt
}

Statistic is used by Statistics

type Statistics

type Statistics struct {
	Statistics []Statistic `length:"VarInt"`
}

Statistics is used to update the statistics screen for the client.

This is a Minecraft packet ID: 0x07

type StatusPing

type StatusPing struct {
	// The time when the ping was sent
	Time int64
}

StatusPing is sent by the client after recieving a StatusResponse. The client uses the time from sending the ping until the time of recieving a pong to measure the latency between the client and the server.

This is a Minecraft packet ID: 0x01

type StatusPlayer

type StatusPlayer struct {
	Name string `json:"name"`
	ID   string `json:"id"`
}

StatusPlayer is one of the sample players in a StatusReply

type StatusPong

type StatusPong struct {
	Time int64
}

StatusPong is sent as a reply to a StatusPing. The Time field should be exactly the same as the one sent by the client.

This is a Minecraft packet ID: 0x01

type StatusReply

type StatusReply struct {
	Version struct {
		Name     string `json:"name"`
		Protocol int    `json:"protocol"`
	} `json:"version"`
	Players struct {
		Max    int            `json:"max"`
		Online int            `json:"online"`
		Sample []StatusPlayer `json:"sample,omitempty"`
	} `json:"players"`
	Description format.AnyComponent `json:"description"`
	Favicon     string              `json:"favicon"`
}

StatusReply is the reply retrieved from a server when pinging it.

type StatusRequest

type StatusRequest struct {
}

StatusRequest is sent by the client instantly after switching to the Status protocol state and is used to signal the server to send a StatusResponse to the client

This is a Minecraft packet ID: 0x00

type StatusResponse

type StatusResponse struct {
	Status StatusReply `as:"json"`
}

StatusResponse is sent as a reply to a StatusRequest. The Status should contain a json encoded structure with version information, a player sample, a description/MOTD and optionally a favicon.

The structure is as follows

{
    "version": {
        "name": "1.8.3",
        "protocol": 47,
    },
    "players": {
        "max": 20,
        "online": 1,
        "sample": [
            {"name": "Thinkofdeath", "id": "4566e69f-c907-48ee-8d71-d7ba5aa00d20"}
        ]
    },
    "description": "Hello world",
    "favicon": "data:image/png;base64,<data>"
}

This is a Minecraft packet ID: 0x00

type SteerBoat

type SteerBoat struct {
	LeftPaddle, RightPaddle bool
}

SteerBoat is used to update the status of the player's boat.

This is a Minecraft packet ID: 0x11

type SteerVehicle

type SteerVehicle struct {
	Sideways float32
	Forward  float32
	Flags    byte
}

SteerVehicle is sent by the client when steers or preforms an action on a vehicle.

This is a Minecraft packet ID: 0x16

type TabComplete

type TabComplete struct {
	Text         string
	AssumeComman bool
	HasTarget    bool
	Target       Position `if:".HasTarget==true"`
}

TabComplete is sent by the client when the client presses tab in the chat box.

This is a Minecraft packet ID: 0x01

type TabCompleteReply

type TabCompleteReply struct {
	Matches []string `length:"VarInt"`
}

TabCompleteReply is sent as a reply to a tab completion request. The matches should be possible completions for the command/chat the player sent.

This is a Minecraft packet ID: 0x0E

type Teams

type Teams struct {
	Name              string
	Mode              byte
	DisplayName       string   `if:".Mode == 0 .Mode == 2"`
	Prefix            string   `if:".Mode == 0 .Mode == 2"`
	Suffix            string   `if:".Mode == 0 .Mode == 2"`
	Flags             byte     `if:".Mode == 0 .Mode == 2"`
	NameTagVisibility string   `if:".Mode == 0 .Mode == 2"`
	CollisionRule     string   `if:".Mode == 0 .Mode == 2"`
	Color             byte     `if:".Mode == 0 .Mode == 2"`
	Players           []string `length:"VarInt" if:".Mode == 0 .Mode == 3 .Mode == 4"`
}

Teams creates and updates teams

This is a Minecraft packet ID: 0x44

type TeleportConfirm

type TeleportConfirm struct {
	TeleportID VarInt
}

This is a Minecraft packet ID: 0x00

type TeleportPlayer

type TeleportPlayer struct {
	X, Y, Z    float64
	Yaw, Pitch float32
	Flags      byte
	TeleportID VarInt
}

TeleportPlayer is sent to change the player's position. The client is expected to reply to the server with the same positions as contained in this packet otherwise will reject future packets.

This is a Minecraft packet ID: 0x2F

type TimeUpdate

type TimeUpdate struct {
	WorldAge  int64
	TimeOfDay int64
}

TimeUpdate is sent to sync the world's time to the client, the client will manually tick the time itself so this doesn't need to sent repeatedly but if the server or client has issues keeping up this can fall out of sync so it is a good idea to sent this now and again

This is a Minecraft packet ID: 0x47

type Title

type Title struct {
	Action    VarInt
	Title     format.AnyComponent `as:"json" if:".Action == 0"`
	SubTitle  format.AnyComponent `as:"json" if:".Action == 1"`
	ActionBar format.AnyComponent `as:"json" if:".Action == 2"`
	FadeIn    int32               `if:".Action == 3"`
	FadeStay  int32               `if:".Action == 3"`
	FadeOut   int32               `if:".Action == 3"`
}

Title configures an on-screen title.

This is a Minecraft packet ID: 0x48

type UUID

type UUID [16]byte

UUID is an unique identifier

func (*UUID) Deserialize

func (u *UUID) Deserialize(r io.Reader) error

Deserialize deserializes the uuid from the reader

func (*UUID) Serialize

func (u *UUID) Serialize(w io.Writer) error

Serialize serializes the uuid into the writer

type UnlockRecipes

type UnlockRecipes struct {
	Action                               VarInt
	CraftingBookOpen, FilteringCraftable bool
	RecipeIDs                            []VarInt `length:"VarInt"`
	RecipeIDs2                           []VarInt `length:"VarInt",if:".Action==0"`
}

This is a Minecraft packet ID: 0x31

type UpdateBlockEntity

type UpdateBlockEntity struct {
	Location Position
	Action   byte
	NBT      *nbt.Compound
}

UpdateBlockEntity updates the nbt tag of a block entity in the world.

This is a Minecraft packet ID: 0x09

type UpdateHealth

type UpdateHealth struct {
	Health         float32
	Food           VarInt
	FoodSaturation float32
}

UpdateHealth is sent by the server to update the player's health and food.

This is a Minecraft packet ID: 0x41

type UpdateScore

type UpdateScore struct {
	Name       string
	Action     byte
	ObjectName string
	Value      VarInt `if:".Action != 1"`
}

UpdateScore is used to update or remove an item from a scoreboard objective.

This is a Minecraft packet ID: 0x45

type UseEntity

type UseEntity struct {
	TargetID VarInt
	Type     VarInt
	TargetX  float32 `if:".Type==2"`
	TargetY  float32 `if:".Type==2"`
	TargetZ  float32 `if:".Type==2"`
	Hand     VarInt  `if:".Type==0 .Type==2"`
}

UseEntity is sent when the user interacts (right clicks) or attacks (left clicks) an entity.

This is a Minecraft packet ID: 0x0A

type UseItem

type UseItem struct {
	Hand VarInt
}

UseItem is sent when the client tries to use an item.

This is a Minecraft packet ID: 0x20

type VarInt

type VarInt int32

VarInt is a variable length integer with a cap of 32 bits

func ReadVarInt

func ReadVarInt(r io.Reader) (VarInt, error)

ReadVarInt reads a VarInt encoded integer from the reader.

type VarLong

type VarLong int64

VarLong is a variable length integer with a cap of 64 bits

func ReadVarLong

func ReadVarLong(r io.Reader) (VarLong, error)

ReadVarLong reads a VarLong encoded 64 bit integer from the reader.

type VebicleMoveClientbound

type VebicleMoveClientbound struct {
	X, Y, Z    float64
	Yaw, Pitch float32
}

VehicleMoveClientbound is used to update the vehicle information of the current player.

This is a Minecraft packet ID: 0x29

type WindowClose

type WindowClose struct {
	ID byte
}

WindowClose forces the client to close the window with the given id, e.g. a chest getting destroyed.

This is a Minecraft packet ID: 0x12

type WindowItems

type WindowItems struct {
	ID    byte
	Items []ItemStack `length:"int16" as:"raw"`
}

WindowItems sets every item in a window.

This is a Minecraft packet ID: 0x14

type WindowOpen

type WindowOpen struct {
	ID        byte
	Type      string
	Title     format.AnyComponent `as:"json"`
	SlotCount byte
	EntityID  int32 `if:".Type == \"EntityHorse\""`
}

WindowOpen tells the client to open the inventory window of the given type. The ID is used to reference the instance of the window in other packets.

This is a Minecraft packet ID: 0x13

type WindowProperty

type WindowProperty struct {
	ID       byte
	Property int16
	Value    int16
}

WindowProperty changes the value of a property of a window. Properties vary depending on the window type.

This is a Minecraft packet ID: 0x15

type WindowSetSlot

type WindowSetSlot struct {
	ID        byte
	Slot      int16
	ItemStack ItemStack `as:"raw"`
}

WindowSetSlot changes an itemstack in one of the slots in a window.

This is a Minecraft packet ID: 0x16

type WorldBorder

type WorldBorder struct {
	Action         VarInt
	OldRadius      float64 `if:".Action == 3 .Action == 1"`
	NewRadius      float64 `if:".Action == 3 .Action == 1 .Action == 0"`
	Speed          VarLong `if:".Action == 3 .Action == 1"`
	X, Z           float64 `if:".Action == 3 .Action == 2"`
	PortalBoundary VarInt  `if:".Action == 3"`
	WarningTime    VarInt  `if:".Action == 3 .Action == 4"`
	WarningBlocks  VarInt  `if:".Action == 3 .Action == 5"`
}

WorldBorder configures the world's border.

This is a Minecraft packet ID: 0x38

Notes

Bugs

  • LoginToServer doesn't support offline mode. Call it a feature?

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL