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

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