Add 1.21.70 support

This commit is contained in:
AkmalFairuz
2025-03-26 16:05:51 +07:00
parent c2e97e366d
commit 01dc76ffeb
16 changed files with 9435 additions and 33 deletions

17
legacyver/all.go Normal file
View File

@@ -0,0 +1,17 @@
package legacyver
import "github.com/sandertv/gophertunnel/minecraft"
// All returns a slice of all legacy protocol versions that are supported.
func All() []minecraft.Protocol {
return []minecraft.Protocol{
New776(),
New766(),
New748(),
New729(),
New712(),
New686(),
New685(),
New671(),
}
}

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -520,7 +520,7 @@ func (t *DefaultItemTranslator) DowngradeLegacyItemRegistry(entries []proto.Lega
panic(itemType)
}
} else {
t.latest.RegisterEntryRID(entry.Name, int32(entry.RuntimeID), 2)
t.latest.RegisterEntryRID(entry.Name, int32(entry.RuntimeID), 2, nil)
entry.RuntimeID = int16(t.mapping.RegisterEntry(entry.Name))
}
entries[i] = entry
@@ -550,7 +550,7 @@ func (t *DefaultItemTranslator) UpgradeLegacyItemRegistry(entries []proto.Legacy
panic(itemType)
}
} else {
t.latest.RegisterEntryRID(entry.Name, int32(entry.RuntimeID), 2)
t.latest.RegisterEntryRID(entry.Name, int32(entry.RuntimeID), 2, nil)
entry.RuntimeID = int16(t.mapping.RegisterEntry(entry.Name))
}
entries[i] = entry
@@ -583,8 +583,16 @@ func (t *DefaultItemTranslator) DowngradeItemEntries(entries []proto.ItemEntry)
if entry.Name, ok = t.mapping.ItemRuntimeIDToName(int32(entry.RuntimeID)); !ok {
panic(entry)
}
entryVer, ok := t.mapping.ItemRuntimeIDToVersion(int32(entry.RuntimeID))
if ok {
entry.Version = int32(entryVer)
}
entryData, ok := t.mapping.ItemRuntimeIDToData(int32(entry.RuntimeID))
if ok {
entry.Data = entryData
}
} else {
t.latest.RegisterEntryRID(entry.Name, int32(entry.RuntimeID), 2)
t.latest.RegisterEntryRID(entry.Name, int32(entry.RuntimeID), 2, entry.Data)
entry.RuntimeID = int16(t.mapping.RegisterEntry(entry.Name))
}
entries[i] = entry
@@ -613,8 +621,18 @@ func (t *DefaultItemTranslator) UpgradeItemEntries(entries []proto.ItemEntry) []
if entry.Name, ok = t.latest.ItemRuntimeIDToName(int32(entry.RuntimeID)); !ok {
panic(entry)
}
entryVer, ok := t.mapping.ItemRuntimeIDToVersion(int32(entry.RuntimeID))
if ok {
entry.Version = int32(entryVer)
}
entryData, ok := t.mapping.ItemRuntimeIDToData(int32(entry.RuntimeID))
if ok {
entry.Data = entryData
}
} else {
t.latest.RegisterEntryRID(entry.Name, int32(entry.RuntimeID), 2)
t.latest.RegisterEntryRID(entry.Name, int32(entry.RuntimeID), 2, entry.Data)
entry.RuntimeID = int16(t.mapping.RegisterEntry(entry.Name))
}
entries[i] = entry

View File

@@ -0,0 +1,66 @@
package legacypacket
import (
"github.com/akmalfairuz/legacy-version/legacyver/proto"
"github.com/sandertv/gophertunnel/minecraft/protocol"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
)
const ClientMovementPredictionSyncBitsetSize = 123
// ClientMovementPredictionSync is sent by the client to the server periodically if the client has received
// movement corrections from the server, containing information about client-predictions that are relevant
// to movement.
type ClientMovementPredictionSync struct {
// ActorFlags is a bitset of all the flags that are currently set for the client.
ActorFlags protocol.Bitset
// BoundingBoxScale is the scale of the client's bounding box.
BoundingBoxScale float32
// BoundingBoxWidth is the width of the client's bounding box.
BoundingBoxWidth float32
// BoundingBoxHeight is the height of the client's bounding box.
BoundingBoxHeight float32
// MovementSpeed is the movement speed attribute or 0 if not set.
MovementSpeed float32
// UnderwaterMovementSpeed is the underwater movement speed attribute or 0 if not set.
UnderwaterMovementSpeed float32
// LavaMovementSpeed is the lava movement speed attribute or 0 if not set.
LavaMovementSpeed float32
// JumpStrength is the jump strength attribute or 0 if not set.
JumpStrength float32
// Health is the health attribute or 0 if not set.
Health float32
// Hunger is the hunger attribute or 0 if not set.
Hunger float32
// EntityUniqueID is the unique ID of the entity. The unique ID is a value that remains consistent across
// different sessions of the same world.
EntityUniqueID int64
// Flying specifies if the client is currently flying.
Flying bool
}
// ID ...
func (*ClientMovementPredictionSync) ID() uint32 {
return packet.IDClientMovementPredictionSync
}
func (pk *ClientMovementPredictionSync) Marshal(io protocol.IO) {
if proto.IsProtoGTE(io, proto.ID786) {
io.Bitset(&pk.ActorFlags, ClientMovementPredictionSyncBitsetSize)
} else {
io.Bitset(&pk.ActorFlags, 120)
}
io.Float32(&pk.BoundingBoxScale)
io.Float32(&pk.BoundingBoxWidth)
io.Float32(&pk.BoundingBoxHeight)
io.Float32(&pk.MovementSpeed)
io.Float32(&pk.UnderwaterMovementSpeed)
io.Float32(&pk.LavaMovementSpeed)
io.Float32(&pk.JumpStrength)
io.Float32(&pk.Health)
io.Float32(&pk.Hunger)
io.Varint64(&pk.EntityUniqueID)
if proto.IsProtoGTE(io, proto.ID786) {
io.Bool(&pk.Flying)
}
}

View File

@@ -0,0 +1,55 @@
package legacypacket
import (
"github.com/akmalfairuz/legacy-version/legacyver/proto"
"github.com/go-gl/mathgl/mgl32"
"github.com/sandertv/gophertunnel/minecraft/protocol"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
)
// LevelSoundEvent is sent by the server to make any kind of built-in sound heard to a player. It is sent to,
// for example, play a stepping sound or a shear sound. The packet is also sent by the client, in which case
// it could be forwarded by the server to the other players online. If possible, the packets from the client
// should be ignored however, and the server should play them on its own accord.
type LevelSoundEvent struct {
// SoundType is the type of the sound to play. It is one of the constants above. Some of the sound types
// require additional data, which is set in the EventData field.
SoundType uint32
// Position is the position of the sound event. The player will be able to hear the direction of the sound
// based on what position is sent here.
Position mgl32.Vec3
// ExtraData is a packed integer that some sound types use to provide extra data. An example of this is
// the note sound, which is composed of a pitch and an instrument type.
ExtraData int32
// EntityType is the string entity type of the entity that emitted the sound, for example
// 'minecraft:skeleton'. Some sound types use this entity type for additional data.
EntityType string
// BabyMob specifies if the sound should be that of a baby mob. It is most notably used for parrot
// imitations, which will change based on if this field is set to true or not.
BabyMob bool
// DisableRelativeVolume specifies if the sound should be played relatively or not. If set to true, the
// sound will have full volume, regardless of where the Position is, whereas if set to false, the sound's
// volume will be based on the distance to Position.
DisableRelativeVolume bool
// EntityUniqueID is the unique ID of a source entity. The unique ID is a value that remains consistent across
// different sessions of the same world, but most servers simply fill the runtime ID of the entity out for
// this field.
EntityUniqueID int64
}
// ID ...
func (*LevelSoundEvent) ID() uint32 {
return packet.IDLevelSoundEvent
}
func (pk *LevelSoundEvent) Marshal(io protocol.IO) {
io.Varuint32(&pk.SoundType)
io.Vec3(&pk.Position)
io.Varint32(&pk.ExtraData)
io.String(&pk.EntityType)
io.Bool(&pk.BabyMob)
io.Bool(&pk.DisableRelativeVolume)
if proto.IsProtoGTE(io, proto.ID786) {
io.Int64(&pk.EntityUniqueID)
}
}

View File

@@ -0,0 +1,45 @@
package legacypacket
import (
"github.com/akmalfairuz/legacy-version/legacyver/proto"
"github.com/sandertv/gophertunnel/minecraft/protocol"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
)
// SetHud is sent by the server to set the visibility of individual HUD elements on the client. It is
// important to note that the client does not reset the state of the HUD elements after it leaves a server,
// meaning they can leak into sessions on different servers. To be safe, you should reset the visibility of
// all HUD elements when a player connects.
type SetHud struct {
// Elements is a list of HUD elements that are being modified. The values can be any of the HudElement
// constants above.
Elements []int32
// Visibility represents the new visibility of the specified Elements. It can be any of the HudVisibility
// constants above.
Visibility int32
}
// ID ...
func (*SetHud) ID() uint32 {
return packet.IDSetHud
}
func (pk *SetHud) Marshal(io protocol.IO) {
if proto.IsProtoGTE(io, proto.ID786) {
protocol.FuncSlice(io, &pk.Elements, io.Varint32)
io.Varint32(&pk.Visibility)
} else {
elements := make([]uint8, len(pk.Elements))
for i, v := range pk.Elements {
elements[i] = uint8(v)
}
protocol.FuncSlice(io, &elements, io.Uint8)
for i, v := range elements {
pk.Elements[i] = int32(v)
}
visibility := uint8(pk.Visibility)
io.Uint8(&visibility)
pk.Visibility = int32(visibility)
}
}

View File

@@ -3,6 +3,7 @@ package proto
import "github.com/sandertv/gophertunnel/minecraft/protocol"
const (
ID786 = 786 // v1.21.70
ID776 = 776 // v1.21.60
ID766 = 766 // v1.21.50
ID748 = 748 // v1.21.40

View File

@@ -106,6 +106,12 @@ func convertPacketFunc(pid uint32, cur func() packet.Packet) func() packet.Packe
return func() packet.Packet { return &legacypacket.UpdateAbilities{} }
case packet.IDClientCheatAbility:
return func() packet.Packet { return &legacypacket.ClientCheatAbility{} }
case packet.IDClientMovementPredictionSync:
return func() packet.Packet { return &legacypacket.ClientMovementPredictionSync{} }
case packet.IDLevelSoundEvent:
return func() packet.Packet { return &legacypacket.LevelSoundEvent{} }
case packet.IDSetHud:
return func() packet.Packet { return &legacypacket.SetHud{} }
default:
return cur
}
@@ -629,6 +635,40 @@ func (p *Protocol) downgradePackets(pks []packet.Packet, conn *minecraft.Conn) [
}
case *packet.PlayerSkin:
pk.Skin.GeometryDataEngineVersion = []byte(p.Ver())
case *packet.ClientMovementPredictionSync:
actorFlags := pk.ActorFlags
if p.ID() < proto.ID786 {
actorFlags = fitBitset(actorFlags, 120)
}
pks[pkIndex] = &legacypacket.ClientMovementPredictionSync{
ActorFlags: actorFlags,
BoundingBoxScale: pk.BoundingBoxScale,
BoundingBoxWidth: pk.BoundingBoxWidth,
BoundingBoxHeight: pk.BoundingBoxHeight,
MovementSpeed: pk.MovementSpeed,
UnderwaterMovementSpeed: pk.UnderwaterMovementSpeed,
LavaMovementSpeed: pk.LavaMovementSpeed,
JumpStrength: pk.JumpStrength,
Health: pk.Health,
Hunger: pk.Hunger,
EntityUniqueID: pk.EntityUniqueID,
Flying: pk.Flying,
}
case *packet.LevelSoundEvent:
pks[pkIndex] = &legacypacket.LevelSoundEvent{
SoundType: pk.SoundType,
Position: pk.Position,
ExtraData: pk.ExtraData,
EntityType: pk.EntityType,
BabyMob: pk.BabyMob,
DisableRelativeVolume: pk.DisableRelativeVolume,
EntityUniqueID: pk.EntityUniqueID,
}
case *packet.SetHud:
pks[pkIndex] = &legacypacket.SetHud{
Elements: pk.Elements,
Visibility: pk.Visibility,
}
}
}
@@ -1082,6 +1122,36 @@ func (p *Protocol) upgradePackets(pks []packet.Packet, conn *minecraft.Conn) []p
}
case *legacypacket.UpdateAbilities:
pks[pkIndex] = &packet.UpdateAbilities{AbilityData: pk.AbilityData.ToLatest()}
case *legacypacket.ClientMovementPredictionSync:
pks[pkIndex] = &packet.ClientMovementPredictionSync{
ActorFlags: fitBitset(pk.ActorFlags, packet.ClientMovementPredictionSyncBitsetSize),
BoundingBoxScale: pk.BoundingBoxScale,
BoundingBoxWidth: pk.BoundingBoxWidth,
BoundingBoxHeight: pk.BoundingBoxHeight,
MovementSpeed: pk.MovementSpeed,
UnderwaterMovementSpeed: pk.UnderwaterMovementSpeed,
LavaMovementSpeed: pk.LavaMovementSpeed,
JumpStrength: pk.JumpStrength,
Health: pk.Health,
Hunger: pk.Hunger,
EntityUniqueID: pk.EntityUniqueID,
Flying: pk.Flying,
}
case *legacypacket.LevelSoundEvent:
pks[pkIndex] = &packet.LevelSoundEvent{
SoundType: pk.SoundType,
Position: pk.Position,
ExtraData: pk.ExtraData,
EntityType: pk.EntityType,
BabyMob: pk.BabyMob,
DisableRelativeVolume: pk.DisableRelativeVolume,
EntityUniqueID: pk.EntityUniqueID,
}
case *legacypacket.SetHud:
pks[pkIndex] = &packet.SetHud{
Elements: pk.Elements,
Visibility: pk.Visibility,
}
}
}
return pks

View File

@@ -2,6 +2,8 @@ package legacyver
import (
_ "embed"
"github.com/akmalfairuz/legacy-version/internal/chunk"
"github.com/akmalfairuz/legacy-version/legacyver/proto"
"github.com/akmalfairuz/legacy-version/mapping"
)
@@ -20,6 +22,15 @@ var (
//go:embed data/block_states_776.nbt
blockStateData776 []byte
itemMappingLatest = mapping.NewItemMapping(itemRuntimeIDData776, requiredItemList776, ItemVersion776, false)
blockMappingLatest = mapping.NewBlockMapping(blockStateData776)
itemMapping776 = mapping.NewItemMapping(itemRuntimeIDData776, requiredItemList776, ItemVersion776, false)
blockMapping776 = mapping.NewBlockMapping(blockStateData776)
)
func New776() *Protocol {
return &Protocol{
ver: "1.21.60",
id: proto.ID776,
blockTranslator: NewBlockTranslator(blockMapping776, blockMappingLatest, chunk.NewNetworkPersistentEncoding(blockMapping776, BlockVersion776), chunk.NewBlockPaletteEncoding(blockMapping776, BlockVersion776), false),
itemTranslator: NewItemTranslator(itemMapping776, itemMappingLatest, blockMapping776, blockMappingLatest),
}
}

25
legacyver/v786.go Normal file
View File

@@ -0,0 +1,25 @@
package legacyver
import (
_ "embed"
"github.com/akmalfairuz/legacy-version/mapping"
)
const (
// ItemVersion786 ...
ItemVersion786 = 241
// BlockVersion786 ...
BlockVersion786 int32 = (1 << 24) | (21 << 16) | (70 << 8)
)
var (
//go:embed data/item_runtime_ids_786.nbt
itemRuntimeIDData786 []byte
//go:embed data/required_item_list_786.json
requiredItemList786 []byte
//go:embed data/block_states_786.nbt
blockStateData786 []byte
itemMappingLatest = mapping.NewItemMapping(itemRuntimeIDData786, requiredItemList786, ItemVersion786, false)
blockMappingLatest = mapping.NewBlockMapping(blockStateData786)
)