refactor chunk version handling; improve logging in equality checks and storage import logic
This commit is contained in:
@@ -22,6 +22,7 @@ const McPrefix = "minecraft:"
|
|||||||
func (c Chunk) ToStorage(version string) (toChunk *level.Chunk, err error) {
|
func (c Chunk) ToStorage(version string) (toChunk *level.Chunk, err error) {
|
||||||
f := level.MakeBlockFormat(version)
|
f := level.MakeBlockFormat(version)
|
||||||
toChunk = new(level.Chunk)
|
toChunk = new(level.Chunk)
|
||||||
|
toChunk.Version = version
|
||||||
|
|
||||||
toChunk.Sections = make([]level.Section, len(c.Sections))
|
toChunk.Sections = make([]level.Section, len(c.Sections))
|
||||||
for i, s := range c.Sections {
|
for i, s := range c.Sections {
|
||||||
|
|||||||
+9
-4
@@ -1,15 +1,18 @@
|
|||||||
package level
|
package level
|
||||||
|
|
||||||
import "io"
|
import (
|
||||||
|
"io"
|
||||||
|
"log/slog"
|
||||||
|
)
|
||||||
|
|
||||||
type Chunk struct {
|
type Chunk struct {
|
||||||
Sections []Section
|
Sections []Section
|
||||||
version string
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadChunkFromChunkPacketData(r io.Reader, version string, worldHeight int) (c *Chunk, err error) {
|
func ReadChunkFromChunkPacketData(r io.Reader, version string, worldHeight int) (c *Chunk, err error) {
|
||||||
c = &Chunk{}
|
c = &Chunk{}
|
||||||
c.version = version
|
c.Version = version
|
||||||
nSections := worldHeight / ChunkWidth
|
nSections := worldHeight / ChunkWidth
|
||||||
|
|
||||||
c.Sections = make([]Section, nSections)
|
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 {
|
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
|
return false
|
||||||
}
|
}
|
||||||
if len(c.Sections) != len(other.Sections) {
|
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
|
return false
|
||||||
}
|
}
|
||||||
for i, s := range c.Sections {
|
for i, s := range c.Sections {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ type StorageFormat struct {
|
|||||||
Len int32
|
Len int32
|
||||||
}
|
}
|
||||||
|
|
||||||
var BpeNotAvailableErr = errors.New("bpe not available")
|
|
||||||
var OutOfBoundsErr = errors.New("out of bounds")
|
var OutOfBoundsErr = errors.New("out of bounds")
|
||||||
var AvailableBpeMustBeLenOneErr = errors.New("available bpe must be 1")
|
var AvailableBpeMustBeLenOneErr = errors.New("available bpe must be 1")
|
||||||
var NoAvailableBpeErr = errors.New("no available bpe")
|
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) {
|
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
|
var longs []uint64
|
||||||
if bpe == 0 {
|
if bpe == 0 {
|
||||||
return r.Import(longs, bpe, palette)
|
return r.Import(longs, bpe, palette)
|
||||||
|
|||||||
Reference in New Issue
Block a user