chunk temp
Some checks failed
CodeQL / Analyze (go) (push) Has been cancelled
Go / Test (1.22) (push) Has been cancelled
Go / Test (^1.22) (push) Has been cancelled

This commit is contained in:
2025-08-26 21:53:16 +08:00
parent b9763dbf8c
commit 7b60edc248

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"math/bits"
"strconv" "strconv"
"git.konjactw.dev/falloutBot/go-mc/level/block" "git.konjactw.dev/falloutBot/go-mc/level/block"
@ -56,14 +55,7 @@ func EmptyChunk(secs int) *Chunk {
} }
return &Chunk{ return &Chunk{
Sections: sections, Sections: sections,
HeightMaps: HeightMaps{ HeightMaps: HeightMaps{},
WorldSurfaceWG: NewBitStorage(bits.Len(uint(secs)*16+1), 16*16, nil),
WorldSurface: NewBitStorage(bits.Len(uint(secs)*16+1), 16*16, nil),
OceanFloorWG: NewBitStorage(bits.Len(uint(secs)*16+1), 16*16, nil),
OceanFloor: NewBitStorage(bits.Len(uint(secs)*16+1), 16*16, nil),
MotionBlocking: NewBitStorage(bits.Len(uint(secs)*16+1), 16*16, nil),
MotionBlockingNoLeaves: NewBitStorage(bits.Len(uint(secs)*16+1), 16*16, nil),
},
Status: StatusEmpty, Status: StatusEmpty,
} }
} }
@ -110,17 +102,10 @@ func ChunkFromSave(c *save.Chunk) (*Chunk, error) {
blockEntities[i].Type = block.EntityTypes[tmp.ID] blockEntities[i].Type = block.EntityTypes[tmp.ID]
} }
bitsForHeight := bits.Len( /* chunk height in blocks */ uint(secs)*16 + 1) // bitsForHeight := bits.Len( /* chunk height in blocks */ uint(secs)*16 + 1)
return &Chunk{ return &Chunk{
Sections: sections, Sections: sections,
HeightMaps: HeightMaps{ HeightMaps: HeightMaps{},
WorldSurface: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["WORLD_SURFACE_WG"]),
WorldSurfaceWG: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["WORLD_SURFACE"]),
OceanFloorWG: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["OCEAN_FLOOR_WG"]),
OceanFloor: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["OCEAN_FLOOR"]),
MotionBlocking: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["MOTION_BLOCKING"]),
MotionBlockingNoLeaves: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["MOTION_BLOCKING_NO_LEAVES"]),
},
BlockEntity: blockEntities, BlockEntity: blockEntities,
Status: ChunkStatus(c.Status), Status: ChunkStatus(c.Status),
}, nil }, nil
@ -193,12 +178,12 @@ func ChunkToSave(c *Chunk, dst *save.Chunk) (err error) {
if dst.Heightmaps == nil { if dst.Heightmaps == nil {
dst.Heightmaps = make(map[string][]uint64) dst.Heightmaps = make(map[string][]uint64)
} }
dst.Heightmaps["WORLD_SURFACE_WG"] = c.HeightMaps.WorldSurfaceWG.Raw() // dst.Heightmaps["WORLD_SURFACE_WG"] = c.HeightMaps.WorldSurfaceWG.Raw()
dst.Heightmaps["WORLD_SURFACE"] = c.HeightMaps.WorldSurface.Raw() // dst.Heightmaps["WORLD_SURFACE"] = c.HeightMaps.WorldSurface.Raw()
dst.Heightmaps["OCEAN_FLOOR_WG"] = c.HeightMaps.OceanFloorWG.Raw() // dst.Heightmaps["OCEAN_FLOOR_WG"] = c.HeightMaps.OceanFloorWG.Raw()
dst.Heightmaps["OCEAN_FLOOR"] = c.HeightMaps.OceanFloor.Raw() // dst.Heightmaps["OCEAN_FLOOR"] = c.HeightMaps.OceanFloor.Raw()
dst.Heightmaps["MOTION_BLOCKING"] = c.HeightMaps.MotionBlocking.Raw() // dst.Heightmaps["MOTION_BLOCKING"] = c.HeightMaps.MotionBlocking.Raw()
dst.Heightmaps["MOTION_BLOCKING_NO_LEAVES"] = c.HeightMaps.MotionBlockingNoLeaves.Raw() // dst.Heightmaps["MOTION_BLOCKING_NO_LEAVES"] = c.HeightMaps.MotionBlockingNoLeaves.Raw()
dst.Status = string(c.Status) dst.Status = string(c.Status)
return return
} }
@ -269,46 +254,50 @@ func (c *Chunk) WriteTo(w io.Writer) (int64, error) {
} }
return pk.Tuple{ return pk.Tuple{
// Heightmaps // Heightmaps
pk.NBT(struct { c.HeightMaps,
MotionBlocking []uint64 `nbt:"MOTION_BLOCKING"`
WorldSurface []uint64 `nbt:"WORLD_SURFACE"`
}{
MotionBlocking: c.HeightMaps.MotionBlocking.Raw(),
WorldSurface: c.HeightMaps.WorldSurface.Raw(),
}),
pk.ByteArray(data), pk.ByteArray(data),
pk.Array(c.BlockEntity), pk.Array(c.BlockEntity),
&light, &light,
}.WriteTo(w) }.WriteTo(w)
} }
func (c *Chunk) ReadFrom(r io.Reader) (int64, error) { type HeightMap struct {
Type int32
Data []pk.Long
}
func (h *HeightMap) ReadFrom(r io.Reader) (int64, error) {
var ( var (
heightmaps struct { heightmaps struct {
MotionBlocking []uint64 `nbt:"MOTION_BLOCKING"` Type pk.VarInt
WorldSurface []uint64 `nbt:"WORLD_SURFACE"` Data []pk.Long
} }
data pk.ByteArray
) )
n, err := pk.Tuple{ n, err := pk.Tuple{
pk.NBT(&heightmaps), &heightmaps.Type,
&data, pk.Array(&heightmaps.Data),
pk.Array(&c.BlockEntity),
&LightData{
SkyLightMask: make(pk.BitSet, (16*16*16-1)>>6+1),
BlockLightMask: make(pk.BitSet, (16*16*16-1)>>6+1),
SkyLight: []pk.ByteArray{},
BlockLight: []pk.ByteArray{},
},
}.ReadFrom(r) }.ReadFrom(r)
if err != nil { if err != nil {
return n, err return n, err
} }
h.Type = int32(heightmaps.Type)
h.Data = heightmaps.Data
return n, nil
}
bitsForHeight := bits.Len( /* chunk height in blocks */ uint(len(c.Sections))*16 + 1) func (c *Chunk) ReadFrom(r io.Reader) (int64, error) {
c.HeightMaps.MotionBlocking = NewBitStorage(bitsForHeight, 16*16, heightmaps.MotionBlocking) var (
c.HeightMaps.WorldSurface = NewBitStorage(bitsForHeight, 16*16, heightmaps.WorldSurface) heightmaps []HeightMap
data pk.ByteArray
)
n, err := pk.Tuple{
pk.Array(&heightmaps),
&data,
}.ReadFrom(r)
if err != nil {
return n, err
}
err = c.PutData(data) err = c.PutData(data)
return n, err return n, err
@ -340,13 +329,14 @@ func (c *Chunk) PutData(data []byte) error {
return nil return nil
} }
type HeightMaps struct { type HeightMaps []HeightMap
WorldSurfaceWG *BitStorage // test = NOT_AIR
WorldSurface *BitStorage // test = NOT_AIR func (h *HeightMaps) ReadFrom(r io.Reader) (int64, error) {
OceanFloorWG *BitStorage // test = MATERIAL_MOTION_BLOCKING n, err := pk.Array(&h).ReadFrom(r)
OceanFloor *BitStorage // test = MATERIAL_MOTION_BLOCKING if err != nil {
MotionBlocking *BitStorage // test = BlocksMotion or isFluid return n, err
MotionBlockingNoLeaves *BitStorage // test = BlocksMotion or isFluid }
return n, nil
} }
type BlockEntity struct { type BlockEntity struct {