Refactor sub-chunk structure and align PlayerMovementSettings with proto package. Update gophertunnel dependency to v1.47.3.

This commit is contained in:
AkmalFairuz
2025-06-20 01:37:14 +07:00
parent e0d4fa4c48
commit 10608d39cf
6 changed files with 50 additions and 15 deletions

View File

@@ -189,7 +189,7 @@ type StartGame struct {
// on the world.
Trial bool
// PlayerMovementSettings ...
PlayerMovementSettings protocol.PlayerMovementSettings
PlayerMovementSettings proto.PlayerMovementSettings
// Time is the total time that has elapsed since the start of the world.
Time int64
// EnchantmentSeed is the seed used to seed the random used to produce enchantments in the enchantment
@@ -319,7 +319,7 @@ func (pk *StartGame) Marshal(io protocol.IO) {
io.String(&pk.WorldName)
io.String(&pk.TemplateContentIdentity)
io.Bool(&pk.Trial)
protocol.PlayerMoveSettings(io, &pk.PlayerMovementSettings)
proto.PlayerMoveSettings(io, &pk.PlayerMovementSettings)
io.Int64(&pk.Time)
io.Varint32(&pk.EnchantmentSeed)
protocol.Slice(io, &pk.Blocks)

View File

@@ -95,3 +95,41 @@ func (x *PlayerListEntry) ToLatest() protocol.PlayerListEntry {
func PlayerListRemoveEntry(r protocol.IO, x *PlayerListEntry) {
r.UUID(&x.UUID)
}
// PlayerMovementSettings represents the different server authoritative movement settings. These control how
// the client will provide input to the server.
type PlayerMovementSettings struct {
// MovementType ...
MovementType int32
// RewindHistorySize is the amount of history to keep at maximum.
RewindHistorySize int32
// ServerAuthoritativeBlockBreaking specifies if block breaking should be sent through
// packet.PlayerAuthInput or not.
ServerAuthoritativeBlockBreaking bool
}
func (p *PlayerMovementSettings) FromLatest(x protocol.PlayerMovementSettings) PlayerMovementSettings {
p.MovementType = 1
if p.RewindHistorySize > 0 {
p.MovementType = 2
}
p.RewindHistorySize = x.RewindHistorySize
p.ServerAuthoritativeBlockBreaking = x.ServerAuthoritativeBlockBreaking
return *p
}
func (p *PlayerMovementSettings) ToLatest() protocol.PlayerMovementSettings {
return protocol.PlayerMovementSettings{
RewindHistorySize: p.RewindHistorySize,
ServerAuthoritativeBlockBreaking: p.ServerAuthoritativeBlockBreaking,
}
}
// PlayerMoveSettings reads/writes PlayerMovementSettings x to/from IO r.
func PlayerMoveSettings(r protocol.IO, x *PlayerMovementSettings) {
if IsProtoLT(r, ID818) {
r.Varint32(&x.MovementType)
}
r.Varint32(&x.RewindHistorySize)
r.Bool(&x.ServerAuthoritativeBlockBreaking)
}

View File

@@ -15,14 +15,12 @@ type SubChunkEntry struct {
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
// BlobHash is the hash of the blob.
BlobHash uint64
}
// ToLatest ...
@@ -33,10 +31,9 @@ func (x *SubChunkEntry) ToLatest() protocol.SubChunkEntry {
RawPayload: x.RawPayload,
HeightMapType: x.HeightMapType,
HeightMapData: x.HeightMapData,
BlobHash: x.BlobHash,
RenderHeightMapType: x.RenderHeightMapType,
RenderHeightMapData: x.RenderHeightMapData,
RenderBlobHash: x.RenderBlobHash,
BlobHash: x.BlobHash,
}
}
@@ -47,10 +44,9 @@ func (x *SubChunkEntry) FromLatest(y protocol.SubChunkEntry) SubChunkEntry {
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
x.BlobHash = y.BlobHash
return *x
}
@@ -65,14 +61,13 @@ func (x *SubChunkEntry) Marshal(r protocol.IO) {
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)
}
r.Uint64(&x.BlobHash)
}
// SubChunkEntryNoCache encodes/decodes a SubChunkEntry assuming the blob cache is not enabled.

View File

@@ -572,7 +572,7 @@ func (p *Protocol) downgradePackets(pks []packet.Packet, conn *minecraft.Conn) [
WorldName: pk.WorldName,
TemplateContentIdentity: pk.TemplateContentIdentity,
Trial: pk.Trial,
PlayerMovementSettings: pk.PlayerMovementSettings,
PlayerMovementSettings: (&proto.PlayerMovementSettings{}).FromLatest(pk.PlayerMovementSettings),
Time: pk.Time,
EnchantmentSeed: pk.EnchantmentSeed,
Blocks: pk.Blocks,
@@ -1130,7 +1130,7 @@ func (p *Protocol) upgradePackets(pks []packet.Packet, conn *minecraft.Conn) []p
WorldName: pk.WorldName,
TemplateContentIdentity: pk.TemplateContentIdentity,
Trial: pk.Trial,
PlayerMovementSettings: pk.PlayerMovementSettings,
PlayerMovementSettings: pk.PlayerMovementSettings.ToLatest(),
Time: pk.Time,
EnchantmentSeed: pk.EnchantmentSeed,
Blocks: pk.Blocks,