Update legacy protocol support to v1.21.90

This commit is contained in:
AkmalFairuz
2025-06-18 23:54:54 +07:00
parent 8a209b75bf
commit fd5e43eea7
13 changed files with 9376 additions and 9 deletions

10
go.mod
View File

@@ -12,7 +12,7 @@ require (
github.com/pelletier/go-toml v1.9.5
github.com/rogpeppe/go-internal v1.14.1
github.com/samber/lo v1.49.1
github.com/sandertv/gophertunnel v1.46.1-0.20250511074107-85599aa3447c
github.com/sandertv/gophertunnel v1.47.2-0.20250618150444-d66380c4a00b
github.com/segmentio/fasthash v1.0.3
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394
golang.org/x/image v0.25.0
@@ -27,8 +27,8 @@ require (
github.com/klauspost/compress v1.18.0 // indirect
github.com/muhammadmuzzammil1998/jsonc v1.0.0 // indirect
github.com/sandertv/go-raknet v1.14.3-0.20250305181847-6af3e95113d6 // indirect
golang.org/x/crypto v0.38.0 // indirect
golang.org/x/mod v0.24.0 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/text v0.25.0 // indirect
golang.org/x/crypto v0.39.0 // indirect
golang.org/x/mod v0.25.0 // indirect
golang.org/x/net v0.41.0 // indirect
golang.org/x/text v0.26.0 // indirect
)

10
go.sum
View File

@@ -56,6 +56,8 @@ github.com/sandertv/gophertunnel v1.45.1 h1:mQCEG1Rv1RR9UTRyTu0+XZ/cr3lyWvo/RX0D
github.com/sandertv/gophertunnel v1.45.1/go.mod h1:lvzOdyb2fkoo3uySe++hy4UKq0I649oUFJKkro2ZHpY=
github.com/sandertv/gophertunnel v1.46.1-0.20250511074107-85599aa3447c h1:cZlIS07gnBMXJlwJPxGMTPytg2kBXZcYCasxlqPX480=
github.com/sandertv/gophertunnel v1.46.1-0.20250511074107-85599aa3447c/go.mod h1:lvzOdyb2fkoo3uySe++hy4UKq0I649oUFJKkro2ZHpY=
github.com/sandertv/gophertunnel v1.47.2-0.20250618150444-d66380c4a00b h1:/kNTXzMPTigd+ctGH3c4xVOnzxqyVCB11vikFPhvZqY=
github.com/sandertv/gophertunnel v1.47.2-0.20250618150444-d66380c4a00b/go.mod h1:lvzOdyb2fkoo3uySe++hy4UKq0I649oUFJKkro2ZHpY=
github.com/segmentio/fasthash v1.0.3 h1:EI9+KE1EwvMLBWwjpRDc+fEM+prwxDYbslddQGtrmhM=
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
@@ -64,6 +66,8 @@ golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo=
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw=
@@ -76,11 +80,15 @@ golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc=
golang.org/x/oauth2 v0.28.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
@@ -95,6 +103,8 @@ golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=

View File

@@ -1,10 +1,13 @@
package legacyver
import "github.com/sandertv/gophertunnel/minecraft"
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{
New800(),
New786(),
New776(),
New766(),

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -20,6 +20,9 @@ type ResourcePacksInfo struct {
// HasScripts specifies if any of the resource packs contain scripts in them. If set to true, only clients
// that support scripts will be able to download them.
HasScripts bool
// ForceDisableVibrantVisuals specifies if the vibrant visuals feature should be forcibly disabled on the server.Add commentMore actions
// If set to true, the server will ensure that vibrant visuals are not enabled, regardless of the client's settings.
ForceDisableVibrantVisuals bool
// WorldTemplateUUID is the UUID of the template that has been used to generate the world. Templates can
// be downloaded from the marketplace or installed via '.mctemplate' files. If the world was not generated
// from a template, this field is empty.
@@ -52,6 +55,9 @@ func (pk *ResourcePacksInfo) Marshal(io protocol.IO) {
}
io.Bool(&pk.HasScripts)
if proto.IsProtoGTE(io, proto.ID766) {
if proto.IsProtoGTE(io, proto.ID818) {
io.Bool(&pk.ForceDisableVibrantVisuals)
}
io.UUID(&pk.WorldTemplateUUID)
io.String(&pk.WorldTemplateVersion)
}

View File

@@ -232,6 +232,8 @@ type StartGame struct {
WorldID string
// ScenarioID is always empty in vanilla and its usage is currently unknown.
ScenarioID string
// OwnerID is always empty in vanilla and its usage is currently unknown.
OwnerID string
// UseBlockNetworkIDHashes is true if the client should use the hash of a block's name as its network ID rather than
// its index in the expected block palette. This is useful for servers that wish to support multiple protocol versions
// and custom blocks, but it will result in extra bytes being written for every block in a sub chunk palette.
@@ -309,6 +311,9 @@ func (pk *StartGame) Marshal(io protocol.IO) {
io.String(&pk.ServerID)
io.String(&pk.WorldID)
io.String(&pk.ScenarioID)
if proto.IsProtoGTE(io, proto.ID818) {
io.String(&pk.OwnerID)
}
}
io.String(&pk.LevelID)
io.String(&pk.WorldName)

View File

@@ -0,0 +1,35 @@
package legacypacket
import (
"github.com/akmalfairuz/legacy-version/legacyver/proto"
"github.com/sandertv/gophertunnel/minecraft/protocol"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
)
// SubChunk sends data about multiple sub-chunks around a center point.
type SubChunk struct {
// CacheEnabled is whether the sub-chunk caching is enabled or not.
CacheEnabled bool
// Dimension is the dimension the sub-chunks are in.
Dimension int32
// Position is an absolute sub-chunk center point that every SubChunkRequest uses as a reference.
Position protocol.SubChunkPos
// SubChunkEntries contains sub-chunk entries relative to the center point.
SubChunkEntries []proto.SubChunkEntry
}
// ID ...
func (*SubChunk) ID() uint32 {
return packet.IDSubChunk
}
func (pk *SubChunk) Marshal(io protocol.IO) {
io.Bool(&pk.CacheEnabled)
io.Varint32(&pk.Dimension)
io.SubChunkPos(&pk.Position)
if pk.CacheEnabled {
protocol.SliceUint32Length(io, &pk.SubChunkEntries)
} else {
protocol.FuncIOSliceUint32Length(io, &pk.SubChunkEntries, proto.SubChunkEntryNoCache)
}
}

View File

@@ -3,6 +3,7 @@ package proto
import "github.com/sandertv/gophertunnel/minecraft/protocol"
const (
ID818 = 818 // v1.21.90
ID800 = 800 // v1.21.80
ID786 = 786 // v1.21.70
ID776 = 776 // v1.21.60

View File

@@ -0,0 +1,93 @@
package proto
import "github.com/sandertv/gophertunnel/minecraft/protocol"
// SubChunkEntry contains the data of a sub-chunk entry relative to a center sub chunk position, used for the sub-chunk
// requesting system introduced in v1.18.10.
type SubChunkEntry struct {
// Offset contains the offset between the sub-chunk position and the center position.
Offset protocol.SubChunkOffset
// Result is always one of the constants defined in the SubChunkResult constants.
Result byte
// RawPayload contains the serialized sub-chunk data.
RawPayload []byte
// HeightMapType is always one of the constants defined in the HeightMapData constants.
HeightMapType byte
// HeightMapData is the data for the height map.
HeightMapData []int8
// BlobHash is the hash of the blob.
BlobHash uint64
// RenderHeightMapType is always one of the constants defined in the HeightMapData constants.
RenderHeightMapType byte
// RenderHeightMapData is the data for the render height map.
RenderHeightMapData []int8
// RenderBlobHash is the hash of the render blob.
RenderBlobHash uint64
}
// ToLatest ...
func (x *SubChunkEntry) ToLatest() protocol.SubChunkEntry {
return protocol.SubChunkEntry{
Offset: x.Offset,
Result: x.Result,
RawPayload: x.RawPayload,
HeightMapType: x.HeightMapType,
HeightMapData: x.HeightMapData,
BlobHash: x.BlobHash,
RenderHeightMapType: x.RenderHeightMapType,
RenderHeightMapData: x.RenderHeightMapData,
RenderBlobHash: x.RenderBlobHash,
}
}
// FromLatest converts a protocol.SubChunkEntry to a SubChunkEntry. It is used to convert the latest
func (x *SubChunkEntry) FromLatest(y protocol.SubChunkEntry) SubChunkEntry {
x.Offset = y.Offset
x.Result = y.Result
x.RawPayload = y.RawPayload
x.HeightMapType = y.HeightMapType
x.HeightMapData = y.HeightMapData
x.BlobHash = y.BlobHash
x.RenderHeightMapType = y.RenderHeightMapType
x.RenderHeightMapData = y.RenderHeightMapData
x.RenderBlobHash = y.RenderBlobHash
return *x
}
// Marshal encodes/decodes a SubChunkEntry assuming the blob cache is enabled.
func (x *SubChunkEntry) Marshal(r protocol.IO) {
protocol.Single(r, &x.Offset)
r.Uint8(&x.Result)
if x.Result != protocol.SubChunkResultSuccessAllAir {
r.ByteSlice(&x.RawPayload)
}
r.Uint8(&x.HeightMapType)
if x.HeightMapType == protocol.HeightMapDataHasData {
protocol.FuncSliceOfLen(r, 256, &x.HeightMapData, r.Int8)
}
r.Uint64(&x.BlobHash)
if IsProtoGTE(r, ID818) {
r.Uint8(&x.RenderHeightMapType)
if x.RenderHeightMapType == protocol.HeightMapDataHasData {
protocol.FuncSliceOfLen(r, 256, &x.RenderHeightMapData, r.Int8)
}
r.Uint64(&x.RenderBlobHash)
}
}
// SubChunkEntryNoCache encodes/decodes a SubChunkEntry assuming the blob cache is not enabled.
func SubChunkEntryNoCache(r protocol.IO, x *SubChunkEntry) {
protocol.Single(r, &x.Offset)
r.Uint8(&x.Result)
r.ByteSlice(&x.RawPayload)
r.Uint8(&x.HeightMapType)
if IsProtoGTE(r, ID818) {
if x.HeightMapType == protocol.HeightMapDataHasData {
protocol.FuncSliceOfLen(r, 256, &x.HeightMapData, r.Int8)
}
r.Uint8(&x.RenderHeightMapType)
if x.RenderHeightMapType == protocol.HeightMapDataHasData {
protocol.FuncSliceOfLen(r, 256, &x.RenderHeightMapData, r.Int8)
}
}
}

View File

@@ -124,6 +124,8 @@ func convertPacketFunc(pid uint32, cur func() packet.Packet) func() packet.Packe
return func() packet.Packet { return &legacypacket.BiomeDefinitionList{} }
case packet.IDPlayerList:
return func() packet.Packet { return &legacypacket.PlayerList{} }
case packet.IDSubChunk:
return func() packet.Packet { return &legacypacket.SubChunk{} }
default:
return cur
}
@@ -726,6 +728,17 @@ func (p *Protocol) downgradePackets(pks []packet.Packet, conn *minecraft.Conn) [
ActionType: pk.ActionType,
Entries: entries,
}
case *packet.SubChunk:
entries := make([]proto.SubChunkEntry, len(pk.SubChunkEntries))
for i, e := range pk.SubChunkEntries {
entries[i] = (&proto.SubChunkEntry{}).FromLatest(e)
}
pks[pkIndex] = &legacypacket.SubChunk{
CacheEnabled: pk.CacheEnabled,
Dimension: pk.Dimension,
Position: pk.Position,
SubChunkEntries: entries,
}
}
}
@@ -1203,7 +1216,7 @@ func (p *Protocol) upgradePackets(pks []packet.Packet, conn *minecraft.Conn) []p
pks[pkIndex] = &packet.UpdateAbilities{AbilityData: pk.AbilityData.ToLatest()}
case *legacypacket.ClientMovementPredictionSync:
pks[pkIndex] = &packet.ClientMovementPredictionSync{
ActorFlags: fitBitset(pk.ActorFlags, packet.ClientMovementPredictionSyncBitsetSize),
ActorFlags: fitBitset(pk.ActorFlags, protocol.EntityDataFlagCount),
BoundingBoxScale: pk.BoundingBoxScale,
BoundingBoxWidth: pk.BoundingBoxWidth,
BoundingBoxHeight: pk.BoundingBoxHeight,
@@ -1245,6 +1258,17 @@ func (p *Protocol) upgradePackets(pks []packet.Packet, conn *minecraft.Conn) []p
ActionType: pk.ActionType,
Entries: entries,
}
case *legacypacket.SubChunk:
entries := make([]protocol.SubChunkEntry, len(pk.SubChunkEntries))
for i, e := range pk.SubChunkEntries {
entries[i] = e.ToLatest()
}
pks[pkIndex] = &packet.SubChunk{
CacheEnabled: pk.CacheEnabled,
Dimension: pk.Dimension,
Position: pk.Position,
SubChunkEntries: entries,
}
}
}
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"
)
@@ -18,6 +20,15 @@ var (
//go:embed data/block_states_800.nbt
blockStateData800 []byte
itemMappingLatest = mapping.NewItemMapping(requiredItemList800, ItemVersion800)
blockMappingLatest = mapping.NewBlockMapping(blockStateData800)
itemMapping800 = mapping.NewItemMapping(requiredItemList800, ItemVersion800)
blockMapping800 = mapping.NewBlockMapping(blockStateData800)
)
func New800() *Protocol {
return &Protocol{
ver: "1.21.80",
id: proto.ID800,
blockTranslator: NewBlockTranslator(blockMapping800, blockMappingLatest, chunk.NewNetworkPersistentEncoding(blockMapping800, BlockVersion800), chunk.NewBlockPaletteEncoding(blockMapping800, BlockVersion800), false),
itemTranslator: NewItemTranslator(itemMapping800, itemMappingLatest, blockMapping800, blockMappingLatest),
}
}

23
legacyver/v818.go Normal file
View File

@@ -0,0 +1,23 @@
package legacyver
import (
_ "embed"
"github.com/akmalfairuz/legacy-version/mapping"
)
const (
// ItemVersion818 ...
ItemVersion818 = 261
// BlockVersion818 ...
BlockVersion818 int32 = (1 << 24) | (21 << 16) | (90 << 8)
)
var (
//go:embed data/required_item_list_818.json
requiredItemList818 []byte
//go:embed data/block_states_818.nbt
blockStateData818 []byte
itemMappingLatest = mapping.NewItemMapping(requiredItemList818, ItemVersion818)
blockMappingLatest = mapping.NewBlockMapping(blockStateData818)
)