refactor chunk version handling; improve logging in equality checks and storage import logic

This commit is contained in:
adman
2026-05-05 13:30:21 +02:00
parent e5231dfdb6
commit 00ea02a529
3 changed files with 10 additions and 9 deletions
+1
View File
@@ -22,6 +22,7 @@ const McPrefix = "minecraft:"
func (c Chunk) ToStorage(version string) (toChunk *level.Chunk, err error) {
f := level.MakeBlockFormat(version)
toChunk = new(level.Chunk)
toChunk.Version = version
toChunk.Sections = make([]level.Section, len(c.Sections))
for i, s := range c.Sections {
+9 -4
View File
@@ -1,15 +1,18 @@
package level
import "io"
import (
"io"
"log/slog"
)
type Chunk struct {
Sections []Section
version string
Version string
}
func ReadChunkFromChunkPacketData(r io.Reader, version string, worldHeight int) (c *Chunk, err error) {
c = &Chunk{}
c.version = version
c.Version = version
nSections := worldHeight / ChunkWidth
c.Sections = make([]Section, nSections)
@@ -33,10 +36,12 @@ func (c *Chunk) WriteChunkData(w io.Writer) (err error) {
}
func (c *Chunk) Equals(other *Chunk) bool {
if c.version != other.version {
if c.Version != other.Version {
slog.Debug("Chunk versions don't match: ", "version 1", c.Version, "version2", other.Version)
return false
}
if len(c.Sections) != len(other.Sections) {
slog.Debug("Chunk section len does not match: ", "chunk1 len", len(c.Sections), "chunk 2 len", len(other.Sections))
return false
}
for i, s := range c.Sections {
-5
View File
@@ -14,7 +14,6 @@ type StorageFormat struct {
Len int32
}
var BpeNotAvailableErr = errors.New("bpe not available")
var OutOfBoundsErr = errors.New("out of bounds")
var AvailableBpeMustBeLenOneErr = errors.New("available bpe must be 1")
var NoAvailableBpeErr = errors.New("no available bpe")
@@ -73,10 +72,6 @@ func (r StorageFormat) ImportDataDirect(data []uint64) (s *Storage, err error) {
}
func (r StorageFormat) ImportFromReader(reader io.Reader, bpe uint8, palette []int32) (s *Storage, err error) {
if !slices.Contains(r.AvailableBpes, bpe) {
err = BpeNotAvailableErr
return
}
var longs []uint64
if bpe == 0 {
return r.Import(longs, bpe, palette)