From e623818c60e1f2e13c1cf281e22e3920f8e1ec86 Mon Sep 17 00:00:00 2001 From: ethaniccc Date: Tue, 30 Dec 2025 14:22:21 -0500 Subject: [PATCH] more changes for latest gophertunnel support --- legacyver/legacypacket/text.go | 2 +- legacyver/proto/id.go | 1 + legacyver/protocol.go | 56 +++++++++++++++++++++++++++++----- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/legacyver/legacypacket/text.go b/legacyver/legacypacket/text.go index fe79cfb..e962eea 100644 --- a/legacyver/legacypacket/text.go +++ b/legacyver/legacypacket/text.go @@ -72,7 +72,7 @@ func (pk *Text) Marshal(io protocol.IO) { } else { categoryType = packet.TextCategoryMessageWithParameters } - io.TextCategory(&categoryType) + io.Uint8(&categoryType) io.Uint8(&pk.TextType) } switch pk.TextType { diff --git a/legacyver/proto/id.go b/legacyver/proto/id.go index eb6abd7..0641678 100644 --- a/legacyver/proto/id.go +++ b/legacyver/proto/id.go @@ -4,6 +4,7 @@ import "github.com/sandertv/gophertunnel/minecraft/protocol" const ( ID898 = 898 // v1.21.130 + ID860 = 860 // v1.21.124 ID859 = 859 // v1.21.120 ID844 = 844 // v1.21.110 ID827 = 827 // v1.21.100 diff --git a/legacyver/protocol.go b/legacyver/protocol.go index 6740196..0f26ff0 100644 --- a/legacyver/protocol.go +++ b/legacyver/protocol.go @@ -430,6 +430,7 @@ func (p *Protocol) downgradePackets(pks []packet.Packet, conn *minecraft.Conn) [ OnGround: pk.OnGround, Tick: pk.Tick, } + return nil case *packet.Disconnect: pks[pkIndex] = &legacypacket.Disconnect{ Reason: pk.Reason, @@ -622,7 +623,6 @@ func (p *Protocol) downgradePackets(pks []packet.Packet, conn *minecraft.Conn) [ for i, it := range pk.Items { items[i] = (&proto.ItemEntry{}).FromLatest(it) } - items = p.itemTranslator.DowngradeItemEntries(items) if p.ID() < proto.ID776 { @@ -634,10 +634,7 @@ func (p *Protocol) downgradePackets(pks []packet.Packet, conn *minecraft.Conn) [ return []packet.Packet{} } } - - pks[pkIndex] = &legacypacket.ItemRegistry{ - Items: items, - } + pks[pkIndex] = &legacypacket.ItemRegistry{Items: items} case *packet.StructureBlockUpdate: pks[pkIndex] = &legacypacket.StructureBlockUpdate{ Position: pk.Position, @@ -770,7 +767,7 @@ func (p *Protocol) downgradePackets(pks []packet.Packet, conn *minecraft.Conn) [ ActionType: pk.ActionType, EntityRuntimeID: pk.EntityRuntimeID, Data: pk.Data, - SwingSource: pk.SwingSource, + SwingSource: protocol.Option(swingSourceToString(pk.SwingSource)), } case *packet.AvailableCommands: commands := make([]proto.Command, len(pk.Commands)) @@ -1371,11 +1368,31 @@ func (p *Protocol) upgradePackets(pks []packet.Packet, conn *minecraft.Conn) []p GameRules: pk.GameRules, } case *legacypacket.Animate: + newSwingSource := packet.AnimateSwingSourceNone + source, _ := pk.SwingSource.Value() + switch source { + case "build": + newSwingSource = packet.AnimateSwingSourceBuild + case "mine": + newSwingSource = packet.AnimateSwingSourceMine + case "interact": + newSwingSource = packet.AnimateSwingSourceInteract + case "attack": + newSwingSource = packet.AnimateSwingSourceAttack + case "useitem": + newSwingSource = packet.AnimateSwingSourceUseItem + case "throwitem": + newSwingSource = packet.AnimateSwingSourceThrowItem + case "dropitem": + newSwingSource = packet.AnimateSwingSourceDropItem + case "event": + newSwingSource = packet.AnimateSwingSourceEvent + } pks[pkIndex] = &packet.Animate{ ActionType: pk.ActionType, EntityRuntimeID: pk.EntityRuntimeID, Data: pk.Data, - SwingSource: pk.SwingSource, + SwingSource: uint8(newSwingSource), } case *legacypacket.AvailableCommands: enums := make([]protocol.CommandEnum, len(pk.Enums)) @@ -1435,3 +1452,28 @@ func (p *Protocol) upgradePackets(pks []packet.Packet, conn *minecraft.Conn) []p } return pks } + +func swingSourceToString(x uint8) string { + switch x { + case packet.AnimateSwingSourceNone: + return "none" + case packet.AnimateSwingSourceBuild: + return "build" + case packet.AnimateSwingSourceMine: + return "mine" + case packet.AnimateSwingSourceInteract: + return "interact" + case packet.AnimateSwingSourceAttack: + return "attack" + case packet.AnimateSwingSourceUseItem: + return "useitem" + case packet.AnimateSwingSourceThrowItem: + return "throwitem" + case packet.AnimateSwingSourceDropItem: + return "dropitem" + case packet.AnimateSwingSourceEvent: + return "event" + default: + return "unknown" + } +}