Skip to content

Commit

Permalink
protocol/command.go: Do not include dynamic enum values in enumValues()
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Jul 11, 2023
1 parent 2667b2d commit afc1983
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 5 deletions.
38 changes: 37 additions & 1 deletion minecraft/protocol/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ type Command struct {
// 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
// AliasOffset is the offset to a CommandEnum that holds the values that
// AliasesOffset is the offset to a CommandEnum that holds the values that
// should be used as aliases for this command.
AliasesOffset uint32
// ChainedSubcommandOffsets is a slice of offsets that all point to a different ChainedSubcommand from the
// ChainedSubcommands slice in the AvailableCommands packet.
ChainedSubcommandOffsets []uint16
// 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
Expand All @@ -34,19 +37,23 @@ func (c *Command) Marshal(r IO) {
r.Uint16(&c.Flags)
r.Uint8(&c.PermissionLevel)
r.Uint32(&c.AliasesOffset)
FuncSlice(r, &c.ChainedSubcommandOffsets, r.Uint16)
Slice(r, &c.Overloads)
}

// 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 CommandOverload struct {
// Chaining determines if the parameters use chained subcommands or not.
Chaining bool
// 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
}

func (c *CommandOverload) Marshal(r IO) {
r.Bool(&c.Chaining)
Slice(r, &c.Parameters)
}

Expand Down Expand Up @@ -159,6 +166,35 @@ func (ctx CommandEnumContext) enumOption(r IO, opt *uint) {
}
}

// ChainedSubcommand represents a subcommand that can have chained commands, such as /execute which allows you to run
// another command as another entity or at a different position etc.
type ChainedSubcommand struct {
// Name is the name of the chained subcommand and shows up in the list as a regular subcommand enum.
Name string
// Values contains the index and parameter type of the chained subcommand.
Values []ChainedSubcommandValue
}

func (x *ChainedSubcommand) Marshal(r IO) {
r.String(&x.Name)
Slice(r, &x.Values)
}

// ChainedSubcommandValue represents the value for a chained subcommand argument.
type ChainedSubcommandValue struct {
// Index is the index of the argument in the ChainedSubcommandValues slice from the AvailableCommands packet. This is
// then used to set the type specified by the Value field below.
Index uint16
// Value is a combination of the flags above and specified the type of argument. Unlike regular parameter types,
// this should NOT contain any of the special flags (valid, enum, suffixed or soft enum) but only the basic types.
Value uint16
}

func (x *ChainedSubcommandValue) Marshal(r IO) {
r.Uint16(&x.Index)
r.Uint16(&x.Value)
}

// DynamicEnum is an enum variant that can have its options changed during runtime,
// without sending a new AvailableCommands packet.
type DynamicEnum struct {
Expand Down
2 changes: 2 additions & 0 deletions minecraft/protocol/entity_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const (
EntityDataKeyPlayerLastDeathPosition
EntityDataKeyPlayerLastDeathDimension
EntityDataKeyPlayerHasDied
EntityDataKeyCollisionBox
)

const (
Expand Down Expand Up @@ -248,6 +249,7 @@ const (
EntityDataFlagRising
EntityDataFlagFeelingHappy
EntityDataFlagSearching
EntityDataFlagCrawling
)

const (
Expand Down
4 changes: 2 additions & 2 deletions minecraft/protocol/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package protocol

const (
// CurrentProtocol is the current protocol version for the version below.
CurrentProtocol = 589
CurrentProtocol = 594
// CurrentVersion is the current version of Minecraft as supported by the `packet` package.
CurrentVersion = "1.20.0"
CurrentVersion = "1.20.10"
)
2 changes: 2 additions & 0 deletions minecraft/protocol/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const (
DeviceWin10
DeviceWin32
DeviceDedicated
// Deprecated: DeviceTVOS is deprecated as of 1.20.10.
DeviceTVOS
DeviceOrbis // PlayStation
DeviceNX
DeviceXBOX
// Deprecated: DeviceWP is deprecated as of 1.20.10.
DeviceWP // Windows Phone
DeviceLinux
)
2 changes: 1 addition & 1 deletion minecraft/protocol/packet/actor_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const (
ActorEventBalloonPop
ActorEventTreasureHunt
ActorEventSummonAgent
ActorEventFinishedChargingCrossbow
ActorEventFinishedChargingItem
ActorEventLandedOnGround
ActorEventActorGrowUp
ActorEventVibrationDetected
Expand Down
25 changes: 25 additions & 0 deletions minecraft/protocol/packet/agent_animation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package packet

import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
)

// AgentAnimation is an Education Edition packet sent from the server to the client to make an agent perform an animation.
type AgentAnimation struct {
// Animation is the ID of the animation that the agent should perform. As of its implementation, there are no IDs
// that can be used in the regular client.
Animation byte
// EntityRuntimeID is the runtime ID of the entity. The runtime ID is unique for each world session, and
// entities are generally identified in packets using this runtime ID.
EntityRuntimeID uint64
}

// ID ...
func (*AgentAnimation) ID() uint32 {
return IDAgentAnimation
}

func (pk *AgentAnimation) Marshal(io protocol.IO) {
io.Uint8(&pk.Animation)
io.Varuint64(&pk.EntityRuntimeID)W

Check failure on line 24 in minecraft/protocol/packet/agent_animation.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected W at end of statement
}
8 changes: 8 additions & 0 deletions minecraft/protocol/packet/available_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ type AvailableCommands struct {
// possible value only once. Enums are built by pointing to entries in this
// slice.
EnumValues []string
// ChainedSubcommandValues is a slice of all chained subcommand names. ChainedSubcommandValues generally should
//contain each possible value only once. ChainedSubCommands are built by pointing to entries in this slice.
ChainedSubcommandValues []string
// Suffixes, like EnumValues, is a slice of all suffix values of any command
// parameter in the AvailableCommands packet.
Suffixes []string
// Enums is a slice of all (fixed) command enums present in any of the
// commands.
Enums []protocol.CommandEnum
// ChainedSubcommands is a slice of all subcommands that are followed by a chained command. An example usage of this
// is /execute which allows you to run another command as another entity or at a different position etc.
ChainedSubcommands []protocol.ChainedSubcommand
// Commands is a list of all commands that the client should show
// client-side. The AvailableCommands packet replaces any commands sent
// before. It does not only add the commands that are sent in it.
Expand All @@ -41,8 +47,10 @@ func (*AvailableCommands) ID() uint32 {

func (pk *AvailableCommands) Marshal(io protocol.IO) {
protocol.FuncSlice(io, &pk.EnumValues, io.String)
protocol.FuncSlice(io, &pk.ChainedSubcommandValues, io.String)
protocol.FuncSlice(io, &pk.Suffixes, io.String)
protocol.FuncIOSlice(io, &pk.Enums, protocol.CommandEnumContext{EnumValues: pk.EnumValues}.Marshal)
protocol.Slice(io, &pk.ChainedSubcommands)
protocol.Slice(io, &pk.Commands)
protocol.Slice(io, &pk.DynamicEnums)
protocol.Slice(io, &pk.Constraints)
Expand Down
1 change: 1 addition & 0 deletions minecraft/protocol/packet/client_cheat_ability.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

// ClientCheatAbility functions the same as UpdateAbilities. It is unclear why these two are separated.
// Deprecated: ClientCheatAbility is deprecated as of 1.20.10.
type ClientCheatAbility struct {
// AbilityData represents various data about the abilities of a player, such as ability layers or permissions.
AbilityData protocol.AbilityData
Expand Down
1 change: 1 addition & 0 deletions minecraft/protocol/packet/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,5 @@ const (
IDCompressedBiomeDefinitionList
IDTrimData
IDOpenSign
IDAgentAnimation
)
3 changes: 3 additions & 0 deletions minecraft/protocol/packet/player_auth_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const (
InputFlagPerformItemStackRequest
InputFlagHandledTeleport
InputFlagEmoting
InputFlagMissedSwing
InputFlagStartCrawling
InputFlagStopCrawling
)

const (
Expand Down
1 change: 1 addition & 0 deletions minecraft/protocol/packet/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ func init() {
IDCompressedBiomeDefinitionList: func() Packet { return &CompressedBiomeDefinitionList{} },
IDTrimData: func() Packet { return &TrimData{} },
IDOpenSign: func() Packet { return &OpenSign{} },
IDAgentAnimation: func() Packet { return &AgentAnimation{} },
}
for id, pk := range serverOriginating {
RegisterPacketFromServer(id, pk)
Expand Down
2 changes: 1 addition & 1 deletion minecraft/protocol/packet/script_custom_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

// ScriptCustomEvent is sent by both the client and the server. It is a way to let scripts communicate with
// the server, so that the client can let the server know it triggered an event, or the other way around.
// It is essentially an RPC kind of system.
// Deprecated: ScriptCustomEvent is deprecated as of 1.20.10.
type ScriptCustomEvent struct {
// EventName is the name of the event. The script and the server will use this event name to identify the
// data that is sent.
Expand Down
3 changes: 3 additions & 0 deletions minecraft/protocol/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const (
PlayerActionStartItemUseOn
PlayerActionStopItemUseOn
PlayerActionHandledTeleport
PlayerActionMissedSwing
PlayerActionStartCrawling
PlayerActionStopCrawling
)

const (
Expand Down

0 comments on commit afc1983

Please sign in to comment.