Documentation ¶
Index ¶
- Constants
- func ByteSlice(io protocol.IO, x []byte)
- func CommandData(r *protocol.Reader, x *Command, enums []CommandEnum, suffixes []string)
- func CommandOriginData(r protocol.IO, x *CommandOrigin)
- func CommandParam(r *protocol.Reader, x *CommandParameter, enums []CommandEnum, ...)
- func DowngradeEntityMetadata(data map[uint32]any) map[uint32]any
- func GameRules(io protocol.IO, x *map[string]any)
- func IoBackwardsCompatibility(io protocol.IO, readerFunc func(reader *protocol.Reader), ...)
- func Item(io protocol.IO, x *ItemStack)
- func ReadByteSlice(r *protocol.Reader, x []byte)
- func ReadGameRules(r *protocol.Reader, x *map[string]any)
- func ReadItem(r *protocol.Reader, x *ItemStack)
- func UpgradeEntityMetadata(data map[uint32]any) map[uint32]any
- func WriteByteSlice(w *protocol.Writer, x []byte)
- func WriteCommandData(w *protocol.Writer, x *Command, enumIndices map[string]int, ...)
- func WriteCommandParam(w *protocol.Writer, x *CommandParameter, enumIndices map[string]int, ...)
- func WriteGameRules(w *protocol.Writer, x *map[string]any)
- func WriteItem(w *protocol.Writer, x *ItemStack)
- type Attribute
- type Command
- type CommandEnum
- type CommandOrigin
- type CommandOutputMessage
- type CommandOverload
- type CommandParameter
- type EntityLink
- type InventoryAction
- type InventoryTransactionData
- type ItemStack
- type ItemType
- type MismatchTransactionData
- type NormalTransactionData
- type ReleaseItemTransactionData
- type ResourcePackInfo
- type StackResourcePack
- type UseItemOnEntityTransactionData
- type UseItemTransactionData
Constants ¶
const ( CommandArgValid = 0x100000 CommandArgEnum = 0x200000 CommandArgSuffixed = 0x1000000 CommandArgSoftEnum = 0x4000000 CommandArgTypeInt = iota + 1 CommandArgTypeFloat CommandArgTypeValue CommandArgTypeWildcardInt CommandArgTypeOperator CommandArgTypeTarget CommandArgTypeFilepath = 0x0e CommandArgTypeString = 0x1b CommandArgTypePosition = 0x1d CommandArgTypeMessage = 0x20 CommandArgTypeRawText = 0x22 CommandArgTypeJSON = 0x25 CommandArgTypeCommand = 0x2c )
const ( CommandOriginPlayer = iota CommandOriginBlock CommandOriginMinecartBlock CommandOriginDevConsole CommandOriginTest CommandOriginAutomationPlayer CommandOriginClientAutomation CommandOriginDedicatedServer CommandOriginEntity CommandOriginVirtual CommandOriginGameArgument CommandOriginEntityServer )
const ( InventoryActionSourceContainer = 0 InventoryActionSourceWorld = 2 InventoryActionSourceCreative = 3 InventoryActionSourceTODO = 99999 )
const ( WindowIDInventory = 0 WindowIDOffHand = 119 WindowIDArmour = 120 WindowIDUI = 124 )
const ( UseItemActionClickBlock = iota UseItemActionClickAir UseItemActionBreakBlock )
const ( UseItemOnEntityActionInteract = iota UseItemOnEntityActionAttack )
const ( ReleaseItemActionRelease = iota ReleaseItemActionConsume )
Variables ¶
This section is empty.
Functions ¶
func CommandData ¶
func CommandData(r *protocol.Reader, x *Command, enums []CommandEnum, suffixes []string)
CommandData reads a Command x from Buffer src using the enums and suffixes passed to match indices with the values these slices hold.
func CommandOriginData ¶
func CommandOriginData(r protocol.IO, x *CommandOrigin)
CommandOriginData reads/writes a CommandOrigin x using IO r.
func CommandParam ¶
func CommandParam(r *protocol.Reader, x *CommandParameter, enums []CommandEnum, suffixes []string)
CommandParam reads a CommandParam x from Buffer src using the enums and suffixes passed to translate offsets to their respective values. CommandParam does not handle soft/dynamic enums. The caller is responsible to do this itself.
func DowngradeEntityMetadata ¶
DowngradeEntityMetadata downgrades entity metadata from latest version to legacy version.
func ReadByteSlice ¶
func ReadGameRules ¶
ReadGameRules reads a map of game rules from Reader r. It sets one of the types 'bool', 'float32' or 'uint32' to the map x, with the key being the name of the game rule.
func UpgradeEntityMetadata ¶
UpgradeEntityMetadata upgrades entity metadata from legacy version to latest version.
func WriteByteSlice ¶
func WriteCommandData ¶
func WriteCommandData(w *protocol.Writer, x *Command, enumIndices map[string]int, suffixIndices map[string]int, dynamicEnumIndices map[string]int)
WriteCommandData writes a Command x to Writer w, using the enum indices and suffix indices passed to translate enums and suffixes to the indices that they're written in in the buffer.
func WriteCommandParam ¶
func WriteCommandParam(w *protocol.Writer, x *CommandParameter, enumIndices map[string]int, suffixIndices map[string]int, dynamicEnumIndices map[string]int)
WriteCommandParam writes a CommandParameter x to Writer w, using the enum indices and suffix indices to translate the respective values to the offset in the buffer.
func WriteGameRules ¶
WriteGameRules writes a map of game rules x, indexed by their names to Writer w. The types of the map values must be either 'bool', 'float32' or 'uint32'. If one of the values has a different type, the function will panic.
Types ¶
type Attribute ¶
type Attribute struct { // Name is the name of the attribute, for example 'minecraft:health'. These names must be identical to // the ones defined client-side. Name string // Value is the current value of the attribute. This value will be applied to the entity when sent in a // packet. Value float32 // Max and Min specify the boundaries within the value of the attribute must be. The definition of these // fields differ per attribute. The maximum health of an entity may be changed, whereas the maximum // movement speed for example may not be. Max, Min float32 // Default is the default value of the attribute. It's not clear why this field must be sent to the // client, but it is required regardless. Default float32 }
Attribute is an entity attribute, that holds specific data such as the health of the entity. Each attribute holds a default value, maximum and minimum value, name and its current value.
type Command ¶
type Command struct { // Name is the name of the command. The command may be executed using this name, and will be shown in the // /help list with it. It currently seems that the client crashes if the Name contains uppercase letters. Name string // Description is the description of the command. It is shown in the /help list and when starting to write // a command. Description string // Flags is a combination of flags not currently known. Leaving the Flags field empty appears to work. Flags byte // PermissionLevel is the command permission level that the player required to execute this command. The // field no longer seems to serve a purpose, as the client does not handle the execution of commands // anymore: The permissions should be checked server-side. PermissionLevel byte // Aliases is a list of aliases of the command name, that may alternatively be used to execute the command // in the same way. Aliases []string // Overloads is a list of command overloads that specify the ways in which a command may be executed. The // overloads may be completely different. Overloads []CommandOverload }
Command holds the data that a command requires to be shown to a player client-side. The command is shown in the /help command and auto-completed using this data.
type CommandEnum ¶
type CommandEnum struct { // Type is the type of the command enum. The type will show up in the command usage as the type of the // argument if it has a certain amount of arguments, or when CollapseEnumOptions is set to true in the // command holding the enum. Type string // Options is a list of options that are valid for the client to submit to the command. They will be able // to be auto-completed and show up as options client-side. Options []string // Dynamic specifies if the command enum is considered dynamic. If set to true, it is written differently // and may be updated during runtime as a result using the UpdateSoftEnum packet. Dynamic bool }
CommandEnum represents an enum in a command usage. The enum typically has a type and a set of options that are valid. A value that is not one of the options results in a failure during execution.
type CommandOrigin ¶
type CommandOrigin struct { // Origin is one of the values above that specifies the origin of the command. The origin may change, // depending on what part of the client actually called the command. The command may be issued by a // websocket server, for example. Origin uint32 // UUID is the UUID of the command called. This UUID is a bit odd as it is not specified by the server. It // is not clear what exactly this UUID is meant to identify, but it is unique for each command called. UUID uuid.UUID // RequestID is an ID that identifies the request of the client. The server should send a CommandOrigin // with the same request ID to ensure it can be matched with the request by the caller of the command. // This is especially important for websocket servers and it seems that this field is only non-empty for // these websocket servers. RequestID string // PlayerUniqueID is an ID that identifies the player, the same as the one found in the AdventureSettings // packet. Filling it out with 0 seems to work. // PlayerUniqueID is only written if Origin is CommandOriginDevConsole or CommandOriginTest. PlayerUniqueID int64 }
CommandOrigin holds data that identifies the origin of the requesting of a command. It holds several fields that may be used to get specific information. When sent in a CommandRequest packet, the same CommandOrigin should be sent in a CommandOutput packet.
type CommandOutputMessage ¶
type CommandOutputMessage struct { // Success indicates if the output message was one of a successful command execution. If set to true, the // output message is by default coloured white, whereas if set to false, the message is by default // coloured red. Success bool // Message is the message that is sent to the client in the chat window. It may either be simply a // message or a translated built-in string like 'commands.tp.success.coordinates', combined with specific // parameters below. Message string // Parameters is a list of parameters that serve to supply the message sent with additional information, // such as the position that a player was teleported to or the effect that was applied to an entity. // These parameters only apply for the Minecraft built-in command output. Parameters []string }
CommandOutputMessage represents a message sent by a command that holds the output of one of the commands executed.
func (*CommandOutputMessage) Marshal ¶
func (x *CommandOutputMessage) Marshal(r protocol.IO)
Marshal encodes/decodes a CommandOutputMessage.
type CommandOverload ¶
type CommandOverload struct { // Parameters is a list of command parameters that are part of the overload. These parameters specify the // usage of the command when this overload is applied. Parameters []CommandParameter }
CommandOverload represents an overload of a command. This overload can be compared to function overloading in languages such as java. It represents a single usage of the command. A command may have multiple different overloads, which are handled differently.
type CommandParameter ¶
type CommandParameter struct { // Name is the name of the command parameter. It shows up in the usage like <$Name: $Type>, with the // exception of enum types, which show up simply as a list of options if the list is short enough and // CollapseEnumOptions is set to false. Name string // Type is a rather odd combination of type(flag)s that result in a certain parameter type to show up // client-side. It is a combination of the flags above. The basic types must be combined with the // ArgumentTypeFlagBasic flag (and integers with a suffix ArgumentTypeFlagSuffixed), whereas enums are // combined with the ArgumentTypeFlagEnum flag. Type uint32 // Optional specifies if the command parameter is optional to enter. Note that no non-optional parameter // should ever be present in a command overload after an optional parameter. When optional, the parameter // shows up like so: [$Name: $Type], whereas when mandatory, it shows up like so: <$Name: $Type>. Optional bool // CollapseEnumOptions specifies if the enum (only if the Type is actually an enum type. If not, setting // this to true has no effect) should be collapsed. This means that the options of the enum are never // shown in the actual usage of the command, but only as auto-completion, like it automatically does with // enums that have a big amount of options. To illustrate, it can make <false|true|yes|no> <$Name: bool>. CollapseEnumOptions bool // Enum is the enum of the parameter if it should be of the type enum. If non-empty, the parameter will // be treated as an enum and show up as such client-side. Enum CommandEnum // Suffix is the suffix of the parameter if it should receive one. Note that only integer argument types // are able to receive a suffix, and so the type, if Suffix is a non-empty string, will always be an // integer. Suffix string }
CommandParameter represents a single parameter of a command overload, which accepts a certain type of input values. It has a name and a type which show up client-side when a player is entering the command.
type EntityLink ¶
type EntityLink struct { // RiddenEntityUniqueID is the entity unique ID of the entity that is being ridden. For a player sitting // in a boat, this is the unique ID of the boat. RiddenEntityUniqueID int64 // RiderEntityUniqueID is the entity unique ID of the entity that is riding. For a player sitting in a // boat, this is the unique ID of the player. RiderEntityUniqueID int64 // Type is one of the types above. It specifies the way the entity is linked to another entity. Type byte // Immediate is set to immediately dismount an entity from another. This should be set when the mount of // an entity is killed. Immediate bool }
EntityLink is a link between two entities, typically being one entity riding another.
func (*EntityLink) Marshal ¶
func (x *EntityLink) Marshal(r protocol.IO)
Marshal encodes/decodes a single entity link.
type InventoryAction ¶
type InventoryAction struct { // SourceType is the source type of the inventory action. It is one of the constants above. SourceType uint32 // WindowID is the ID of the window that the client has opened. The window ID is not set if the SourceType // is InventoryActionSourceWorld. WindowID int32 // SourceFlags is a combination of flags that is only set if the SourceType is InventoryActionSourceWorld. SourceFlags uint32 // InventorySlot is the slot in which the action took place. Each action only describes the change of item // in a single slot. InventorySlot uint32 // OldItem is the item that was present in the slot before the inventory action. It should be checked by // the server to ensure the inventories were not out of sync. OldItem ItemStack // NewItem is the new item that was put in the InventorySlot that the OldItem was in. It must be checked // in combination with other inventory actions to ensure that the transaction is balanced. NewItem ItemStack }
InventoryAction represents a single action that took place during an inventory transaction. On itself, this inventory action is always unbalanced: It must be combined with other actions in an inventory transaction to form a balanced transaction.
func (*InventoryAction) Marshal ¶
func (x *InventoryAction) Marshal(io protocol.IO)
Marshal encodes/decodes an InventoryAction.
type InventoryTransactionData ¶
type InventoryTransactionData interface { // Marshal encodes a serialised inventory transaction data object. Marshal(w *protocol.Writer) // Unmarshal decodes a serialised inventory transaction data object. Unmarshal(r *protocol.Reader) }
InventoryTransactionData represents an object that holds data specific to an inventory transaction type. The data it holds depends on the type.
type ItemStack ¶
type ItemStack struct { ItemType // Count is the count of items that the item stack holds. Count int16 // NBTData is a map that is serialised to its NBT representation when sent in a packet. NBTData map[string]any // CanBePlacedOn is a list of block identifiers like 'minecraft:stone' which the item, if it is an item // that can be placed, can be placed on top of. CanBePlacedOn []string // CanBreak is a list of block identifiers like 'minecraft:dirt' that the item is able to break. CanBreak []string }
ItemStack represents an item instance/stack over network. It has a network ID and a metadata value that define its type.
type ItemType ¶
type ItemType struct { // NetworkID is the numerical network ID of the item. This is sometimes a positive ID, and sometimes a // negative ID, depending on what item it concerns. NetworkID int32 // MetadataValue is the metadata value of the item. For some items, this is the damage value, whereas for // other items it is simply an identifier of a variant of the item. MetadataValue int16 }
ItemType represents a consistent combination of network ID and metadata value of an item. It cannot usually be changed unless a new item is obtained.
type MismatchTransactionData ¶
type MismatchTransactionData struct{}
MismatchTransactionData represents a mismatched inventory transaction's data object.
func (*MismatchTransactionData) Marshal ¶
func (*MismatchTransactionData) Marshal(*protocol.Writer)
Marshal ...
func (*MismatchTransactionData) Unmarshal ¶
func (*MismatchTransactionData) Unmarshal(*protocol.Reader)
Unmarshal ...
type NormalTransactionData ¶
type NormalTransactionData struct{}
NormalTransactionData represents an inventory transaction data object for normal transactions, such as crafting. It has no content.
func (*NormalTransactionData) Marshal ¶
func (*NormalTransactionData) Marshal(*protocol.Writer)
Marshal ...
func (*NormalTransactionData) Unmarshal ¶
func (*NormalTransactionData) Unmarshal(*protocol.Reader)
Unmarshal ...
type ReleaseItemTransactionData ¶
type ReleaseItemTransactionData struct { // ActionType is the type of the ReleaseItem inventory transaction. It is one of the action types found // in the constants above, and specifies the way the item was released. ActionType uint32 // HotBarSlot is the hot bar slot that the player was holding while releasing the item. It should be used // to ensure that the hot bar slot and held item are correctly synchronised with the server. HotBarSlot int32 // HeldItem is the item that was released. The server should check if this item is actually present in the // HotBarSlot. HeldItem ItemStack // HeadPosition is the position of the player's head at the time of releasing the item. This is used // mainly for purposes such as spawning eating particles at that position. HeadPosition mgl32.Vec3 }
ReleaseItemTransactionData represents an inventory transaction data object sent when the client releases the item it was using, for example when stopping while eating or stopping the charging of a bow.
func (*ReleaseItemTransactionData) Marshal ¶
func (data *ReleaseItemTransactionData) Marshal(w *protocol.Writer)
Marshal ...
func (*ReleaseItemTransactionData) Unmarshal ¶
func (data *ReleaseItemTransactionData) Unmarshal(r *protocol.Reader)
Unmarshal ...
type ResourcePackInfo ¶
type ResourcePackInfo struct { // UUID is the UUID of the resource pack. Each resource pack downloaded must have a different UUID in // order for the client to be able to handle them properly. UUID string // Version is the version of the resource pack. The client will cache resource packs sent by the server as // long as they carry the same version. Sending a resource pack with a different version than previously // will force the client to re-download it. Version string // Size is the total size in bytes that the resource pack occupies. This is the size of the compressed // archive (zip) of the resource pack. Size uint64 // ContentKey is the key used to decrypt the resource pack if it is encrypted. This is generally the case // for marketplace resource packs. ContentKey string // SubPackName ... SubPackName string // ContentIdentity ... ContentIdentity string // HasScripts specifies if the resource packs has any scripts in it. A client will only download the // resource pack if it supports scripts, which, up to 1.11, only includes Windows 10. HasScripts bool }
ResourcePackInfo represents a texture pack's info sent over network. It holds information about the texture pack such as its name, description and version.
func (*ResourcePackInfo) Marshal ¶
func (x *ResourcePackInfo) Marshal(r protocol.IO)
Marshal encodes/decodes a ResourcePackInfo.
type StackResourcePack ¶
type StackResourcePack struct { // UUID is the UUID of the resource pack. Each resource pack downloaded must have a different UUID in // order for the client to be able to handle them properly. UUID string // Version is the version of the resource pack. The client will cache resource packs sent by the server as // long as they carry the same version. Sending a resource pack with a different version than previously // will force the client to re-download it. Version string // SubPackName ... SubPackName string }
StackResourcePack represents a resource pack sent on the stack of the client. When sent, the client will apply them in the order of the stack sent.
func (*StackResourcePack) Marshal ¶
func (x *StackResourcePack) Marshal(r protocol.IO)
Marshal encodes/decodes a StackResourcePack.
type UseItemOnEntityTransactionData ¶
type UseItemOnEntityTransactionData struct { // TargetEntityRuntimeID is the entity runtime ID of the target that was clicked. It is the runtime ID // that was assigned to it in the AddEntity packet. TargetEntityRuntimeID uint64 // ActionType is the type of the UseItemOnEntity inventory transaction. It is one of the action types // found in the constants above, and specifies the way the player interacted with the entity. ActionType uint32 // HotBarSlot is the hot bar slot that the player was holding while clicking the entity. It should be used // to ensure that the hot bar slot and held item are correctly synchronised with the server. HotBarSlot int32 // HeldItem is the item that was held to interact with the entity. The server should check if this item // is actually present in the HotBarSlot. HeldItem ItemStack // Position is the position of the player at the time of clicking the entity. Position mgl32.Vec3 // ClickedPosition is the position that was clicked relative to the entity's base coordinate. It can be // used to find out exactly where a player clicked the entity. ClickedPosition mgl32.Vec3 }
UseItemOnEntityTransactionData represents an inventory transaction data object sent when the client uses an item on an entity.
func (*UseItemOnEntityTransactionData) Marshal ¶
func (data *UseItemOnEntityTransactionData) Marshal(w *protocol.Writer)
Marshal ...
func (*UseItemOnEntityTransactionData) Unmarshal ¶
func (data *UseItemOnEntityTransactionData) Unmarshal(r *protocol.Reader)
Unmarshal ...
type UseItemTransactionData ¶
type UseItemTransactionData struct { // ActionType is the type of the UseItem inventory transaction. It is one of the action types found above, // and specifies the way the player interacted with the block. ActionType uint32 // BlockPosition is the position of the block that was interacted with. This is only really a correct // block position if ActionType is not UseItemActionClickAir. BlockPosition protocol.BlockPos // BlockFace is the face of the block that was interacted with. When clicking the block, it is the face // clicked. When breaking the block, it is the face that was last being hit until the block broke. BlockFace int32 // HotBarSlot is the hot bar slot that the player was holding while clicking the block. It should be used // to ensure that the hot bar slot and held item are correctly synchronised with the server. HotBarSlot int32 // HeldItem is the item that was held to interact with the block. The server should check if this item // is actually present in the HotBarSlot. HeldItem ItemStack // Position is the position of the player at the time of interaction. For clicking a block, this is the // position at that time, whereas for breaking the block it is the position at the time of breaking. Position mgl32.Vec3 // ClickedPosition is the position that was clicked relative to the block's base coordinate. It can be // used to find out exactly where a player clicked the block. ClickedPosition mgl32.Vec3 // BlockRuntimeID is the runtime ID of the block that was clicked. It may be used by the server to verify // that the player's world client-side is synchronised with the server's. BlockRuntimeID uint32 }
UseItemTransactionData represents an inventory transaction data object sent when the client uses an item on a block.
func (*UseItemTransactionData) Marshal ¶
func (data *UseItemTransactionData) Marshal(w *protocol.Writer)
Marshal ...
func (*UseItemTransactionData) Unmarshal ¶
func (data *UseItemTransactionData) Unmarshal(r *protocol.Reader)
Unmarshal ...