From 748203e1a72f967da7f1fded9d1d51276fb2667c Mon Sep 17 00:00:00 2001 From: Tal Date: Tue, 25 Oct 2022 10:52:20 -0500 Subject: [PATCH] Initial v1.19.40 support (#156) --- minecraft/protocol/ability.go | 1 + minecraft/protocol/entity_properties.go | 44 +++++++++++++++++++ minecraft/protocol/info.go | 4 +- minecraft/protocol/item_stack.go | 1 + minecraft/protocol/login/data.go | 5 +-- minecraft/protocol/packet/add_actor.go | 5 +++ minecraft/protocol/packet/add_player.go | 5 +++ .../protocol/packet/level_sound_event.go | 7 ++- minecraft/protocol/packet/set_actor_data.go | 5 +++ 9 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 minecraft/protocol/entity_properties.go diff --git a/minecraft/protocol/ability.go b/minecraft/protocol/ability.go index ceaa7d5e..20b8adaa 100644 --- a/minecraft/protocol/ability.go +++ b/minecraft/protocol/ability.go @@ -27,6 +27,7 @@ const ( AbilityLayerTypeBase AbilityLayerTypeSpectator AbilityLayerTypeCommands + AbilityLayerTypeEditor ) const ( diff --git a/minecraft/protocol/entity_properties.go b/minecraft/protocol/entity_properties.go new file mode 100644 index 00000000..2653eaff --- /dev/null +++ b/minecraft/protocol/entity_properties.go @@ -0,0 +1,44 @@ +package protocol + +// EntityProperties holds lists of entity properties that define specific attributes of an entity. As of v1.19.40, the +// vanilla server does not use these properties, however they are still supported by the protocol. +type EntityProperties struct { + // IntegerProperties is a list of entity properties that contain integer values. + IntegerProperties []IntegerEntityProperty + // FloatProperties is a list of entity properties that contain float values. + FloatProperties []FloatEntityProperty +} + +// Marshal ... +func (e EntityProperties) Marshal(r IO) { + Slice(r, &e.IntegerProperties) + Slice(r, &e.FloatProperties) +} + +// IntegerEntityProperty is an entity property that contains an integer value. +type IntegerEntityProperty struct { + // Index represents the index of the property. It is unclear what the exact purpose of this is. + Index uint32 + // Value is the value of the property. + Value int32 +} + +// Marshal ... +func (i IntegerEntityProperty) Marshal(r IO) { + r.Varuint32(&i.Index) + r.Varint32(&i.Value) +} + +// FloatEntityProperty is an entity property that contains a float value. +type FloatEntityProperty struct { + // Index represents the index of the property. It is unclear what the exact purpose of this is. + Index uint32 + // Value is the value of the property. + Value float32 +} + +// Marshal ... +func (f FloatEntityProperty) Marshal(r IO) { + r.Varuint32(&f.Index) + r.Float32(&f.Value) +} diff --git a/minecraft/protocol/info.go b/minecraft/protocol/info.go index 457a0138..902795c0 100644 --- a/minecraft/protocol/info.go +++ b/minecraft/protocol/info.go @@ -2,7 +2,7 @@ package protocol const ( // CurrentProtocol is the current protocol version for the version below. - CurrentProtocol = 554 + CurrentProtocol = 557 // CurrentVersion is the current version of Minecraft as supported by the `packet` package. - CurrentVersion = "1.19.30" + CurrentVersion = "1.19.40" ) diff --git a/minecraft/protocol/item_stack.go b/minecraft/protocol/item_stack.go index c96981c8..e1854e24 100644 --- a/minecraft/protocol/item_stack.go +++ b/minecraft/protocol/item_stack.go @@ -16,6 +16,7 @@ const ( FilterCauseLeaveEventText FilterCauseSlashCommandChat FilterCauseCartographyText + FilterCauseSlashCommandNonChat ) // ItemStackRequest represents a single request present in an ItemStackRequest packet sent by the client to diff --git a/minecraft/protocol/login/data.go b/minecraft/protocol/login/data.go index a5ae6711..0cbc5889 100644 --- a/minecraft/protocol/login/data.go +++ b/minecraft/protocol/login/data.go @@ -321,10 +321,9 @@ func (data ClientData) Validate() error { if data.SkinID == "" { return fmt.Errorf("SkinID must not be an empty string") } - if data.UIProfile != 0 && data.UIProfile != 1 { - return fmt.Errorf("UIProfile must be either 0 or 1, but got %v", data.UIProfile) + if data.UIProfile < 0 || data.UIProfile > 2 { + return fmt.Errorf("UIProfile must be between 0-2, but got %v", data.UIProfile) } - return nil } diff --git a/minecraft/protocol/packet/add_actor.go b/minecraft/protocol/packet/add_actor.go index a7f75f95..05e05b4e 100644 --- a/minecraft/protocol/packet/add_actor.go +++ b/minecraft/protocol/packet/add_actor.go @@ -43,6 +43,9 @@ type AddActor struct { // particular the way the entity looks. Flags include ones such as 'on fire' and 'sprinting'. // The metadata values are indexed by their property key. EntityMetadata map[uint32]any + // EntityProperties is a list of properties that the entity inhibits. These properties define and alter specific + // attributes of the entity. + EntityProperties protocol.EntityProperties // EntityLinks is a list of entity links that are currently active on the entity. These links alter the // way the entity shows up when first spawned in terms of it shown as riding an entity. Setting these // links is important for new viewers to see the entity is riding another entity. @@ -67,6 +70,7 @@ func (pk *AddActor) Marshal(w *protocol.Writer) { w.Float32(&pk.BodyYaw) protocol.Slice(w, &pk.Attributes) w.EntityMetadata(&pk.EntityMetadata) + protocol.Single(w, &pk.EntityProperties) protocol.Slice(w, &pk.EntityLinks) } @@ -83,5 +87,6 @@ func (pk *AddActor) Unmarshal(r *protocol.Reader) { r.Float32(&pk.BodyYaw) protocol.Slice(r, &pk.Attributes) r.EntityMetadata(&pk.EntityMetadata) + protocol.Single(r, &pk.EntityProperties) protocol.Slice(r, &pk.EntityLinks) } diff --git a/minecraft/protocol/packet/add_player.go b/minecraft/protocol/packet/add_player.go index 7fa402f5..f4e4762d 100644 --- a/minecraft/protocol/packet/add_player.go +++ b/minecraft/protocol/packet/add_player.go @@ -47,6 +47,9 @@ type AddPlayer struct { // particular the way the player looks. Flags include ones such as 'on fire' and 'sprinting'. // The metadata values are indexed by their property key. EntityMetadata map[uint32]any + // EntityProperties is a list of properties that the entity inhibits. These properties define and alter specific + // attributes of the entity. + EntityProperties protocol.EntityProperties // AbilityData represents various data about the abilities of a player, such as ability layers or permissions. AbilityData protocol.AbilityData // EntityLinks is a list of entity links that are currently active on the player. These links alter the @@ -80,6 +83,7 @@ func (pk *AddPlayer) Marshal(w *protocol.Writer) { w.ItemInstance(&pk.HeldItem) w.Varint32(&pk.GameType) w.EntityMetadata(&pk.EntityMetadata) + protocol.Single(w, &pk.EntityProperties) protocol.Single(w, &pk.AbilityData) protocol.Slice(w, &pk.EntityLinks) w.String(&pk.DeviceID) @@ -100,6 +104,7 @@ func (pk *AddPlayer) Unmarshal(r *protocol.Reader) { r.ItemInstance(&pk.HeldItem) r.Varint32(&pk.GameType) r.EntityMetadata(&pk.EntityMetadata) + protocol.Single(r, &pk.EntityProperties) protocol.Single(r, &pk.AbilityData) protocol.Slice(r, &pk.EntityLinks) r.String(&pk.DeviceID) diff --git a/minecraft/protocol/packet/level_sound_event.go b/minecraft/protocol/packet/level_sound_event.go index f442a772..ffd301e4 100644 --- a/minecraft/protocol/packet/level_sound_event.go +++ b/minecraft/protocol/packet/level_sound_event.go @@ -5,7 +5,7 @@ import ( "github.com/sandertv/gophertunnel/minecraft/protocol" ) -//noinspection SpellCheckingInspection +// noinspection SpellCheckingInspection const ( SoundEventItemUseOn = iota SoundEventHit @@ -450,6 +450,11 @@ const ( SoundEventConvertToFrog SoundEventRecordPlaying SoundEventEnchantingTableUse + _ + _ + SoundEventBundleDropContents + SoundEventBundleInsert + SoundEventBundleRemoveOne ) // LevelSoundEvent is sent by the server to make any kind of built-in sound heard to a player. It is sent to, diff --git a/minecraft/protocol/packet/set_actor_data.go b/minecraft/protocol/packet/set_actor_data.go index c6fc9964..f5b479e3 100644 --- a/minecraft/protocol/packet/set_actor_data.go +++ b/minecraft/protocol/packet/set_actor_data.go @@ -14,6 +14,9 @@ type SetActorData struct { // particular the way the entity looks. Flags include ones such as 'on fire' and 'sprinting'. // The metadata values are indexed by their property key. EntityMetadata map[uint32]any + // EntityProperties is a list of properties that the entity inhibits. These properties define and alter specific + // attributes of the entity. + EntityProperties protocol.EntityProperties // Tick is the server tick at which the packet was sent. It is used in relation to CorrectPlayerMovePrediction. Tick uint64 } @@ -27,6 +30,7 @@ func (*SetActorData) ID() uint32 { func (pk *SetActorData) Marshal(w *protocol.Writer) { w.Varuint64(&pk.EntityRuntimeID) w.EntityMetadata(&pk.EntityMetadata) + protocol.Single(w, &pk.EntityProperties) w.Varuint64(&pk.Tick) } @@ -34,5 +38,6 @@ func (pk *SetActorData) Marshal(w *protocol.Writer) { func (pk *SetActorData) Unmarshal(r *protocol.Reader) { r.Varuint64(&pk.EntityRuntimeID) r.EntityMetadata(&pk.EntityMetadata) + protocol.Single(r, &pk.EntityProperties) r.Varuint64(&pk.Tick) }