more changes for latest gophertunnel support

This commit is contained in:
ethaniccc
2025-12-30 14:22:21 -05:00
parent ff3fed5671
commit e623818c60
3 changed files with 51 additions and 8 deletions

View File

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

View File

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

View File

@@ -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"
}
}