protocol

package
v0.0.0-...-03afc55 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2015 License: Apache-2.0 Imports: 21 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
	SupportedProtocolVersion = 71
)

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 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 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

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

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

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

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

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

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

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

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

type ChunkData

type ChunkData struct {
	ChunkX, ChunkZ int32
	New            bool
	BitMask        VarInt
	Data           []byte `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

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

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

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

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

type ClientStatus

type ClientStatus struct {
	ActionID VarInt
}

ClientStatus is sent to update the client's status

This is a Minecraft packet

type CloseWindow

type CloseWindow struct {
	ID byte
}

CloseWindow is sent when the client closes a window.

This is a Minecraft packet

type CollectItem

type CollectItem struct {
	CollectedEntityID VarInt
	CollectorEntityID VarInt
}

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

This is a Minecraft packet

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

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

type ConfirmTransactionServerbound

type ConfirmTransactionServerbound struct {
	ID           byte
	ActionNumber int16
	Accepted     bool
}

ConfirmTransactionServerbound is a reply to ConfirmTransaction.

This is a Minecraft packet

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 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) WritePacket

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

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

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

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

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

type EnchantItem

type EnchantItem struct {
	ID          byte
	Enchantment byte
}

EnchantItem is sent when the client enchants an item.

This is a Minecraft packet

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

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

type Entity

type Entity struct {
	EntityID VarInt
}

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

This is a Minecraft packet

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

type EntityAttach

type EntityAttach struct {
	EntityID int32
	Vehicle  int32
	Leash    bool
}

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

This is a Minecraft packet

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

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

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

type EntityHeadLook

type EntityHeadLook struct {
	EntityID VarInt
	HeadYaw  int8
}

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

This is a Minecraft packet

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

type EntityLookAndMove

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

EntityLookAndMove is a combination of EntityMove and EntityLook.

This is a Minecraft packet

type EntityMetadata

type EntityMetadata struct {
	EntityID VarInt
	Metadata Metadata
}

EntityMetadata updates the metadata for an entity.

This is a Minecraft packet

type EntityMove

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

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

This is a Minecraft packet

type EntityProperties

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

EntityProperties updates the properties for an entity.

This is a Minecraft packet

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

type EntityTeleport

type EntityTeleport struct {
	EntityID   VarInt
	X, Y, Z    int32
	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

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

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

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

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

type HeldItemChange

type HeldItemChange struct {
	Slot int16
}

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

This is a Minecraft packet

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 int8
	// 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

type KeepAliveClientbound

type KeepAliveClientbound struct {
	ID VarInt
}

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

type KeepAliveServerbound

type KeepAliveServerbound struct {
	ID VarInt
}

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

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

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

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

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

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

type Packet

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

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

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

type Player

type Player struct {
	OnGround bool
}

Player is used to update whether the player is on the ground or not.

This is a Minecraft packet

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

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

type PlayerBlockPlacement

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

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

This is a Minecraft packet

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

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

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

type PlayerLook

type PlayerLook struct {
	Yaw, Pitch float32
	OnGround   bool
}

PlayerLook is used to update the player's rotation.

This is a Minecraft packet

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

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

type PlayerProperty

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

PlayerProperty is used by PlayerDetail

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

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

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 PropertyModifier

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

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

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

type ResourcePackStatus

type ResourcePackStatus struct {
	Hash   string
	Result VarInt
}

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

This is a Minecraft packet

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

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

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

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

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

type SetCompression

type SetCompression struct {
	Threshold VarInt
}

SetCompression updates the compression threshold.

This is a Minecraft packet

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

type SetCurrentHotbarSlot

type SetCurrentHotbarSlot struct {
	Slot byte
}

SetCurrentHotbarSlot changes the player's currently selected hotbar item.

This is a Minecraft packet

type SetExperience

type SetExperience struct {
	ExperienceBar   float32
	Level           VarInt
	TotalExperience VarInt
}

SetExperience updates the experience bar on the client.

This is a Minecraft packet

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

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

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

type SoundEffect

type SoundEffect struct {
	Name    string
	X, Y, Z int32
	Volume  float32
	Pitch   byte
}

SoundEffect plays the named sound at the target location.

This is a Minecraft packet

type SpawnExperienceOrb

type SpawnExperienceOrb struct {
	EntityID VarInt
	X, Y, Z  int32
	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

type SpawnGlobalEntity

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

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

This is a Minecraft packet

type SpawnMob

type SpawnMob struct {
	EntityID                        VarInt
	UUID                            UUID `as:"raw"`
	Type                            byte
	X, Y, Z                         int32
	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

type SpawnObject

type SpawnObject struct {
	EntityID                        VarInt
	UUID                            UUID `as:"raw"`
	Type                            byte
	X, Y, Z                         int32
	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

type SpawnPainting

type SpawnPainting struct {
	EntityID  VarInt
	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

type SpawnPlayer

type SpawnPlayer struct {
	EntityID   VarInt
	UUID       UUID `as:"raw"`
	X, Y, Z    int32
	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

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

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

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

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

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

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

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

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

type TabComplete

type TabComplete struct {
	Text      string
	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

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

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

type TeleportPlayer

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

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

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

type Title

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

Title configures an on-screen title.

This is a Minecraft packet

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 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

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

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

type UpdateSign

type UpdateSign struct {
	Location Position
	Line1    format.AnyComponent `as:"json"`
	Line2    format.AnyComponent `as:"json"`
	Line3    format.AnyComponent `as:"json"`
	Line4    format.AnyComponent `as:"json"`
}

UpdateSign sets or changes the text on a sign.

This is a Minecraft packet

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

type UseItem

type UseItem struct {
	Hand VarInt
}

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

This is a Minecraft packet

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 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

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

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

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

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

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

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