Update level/chunk and heightmaps
This commit is contained in:
@ -47,13 +47,12 @@ func NewBitStorage(bits, length int, data []uint64) (b *BitStorage) {
|
|||||||
valuesPerLong: 64 / bits,
|
valuesPerLong: 64 / bits,
|
||||||
}
|
}
|
||||||
dataLen := calcBitStorageSize(bits, length)
|
dataLen := calcBitStorageSize(bits, length)
|
||||||
|
b.data = make([]uint64, dataLen)
|
||||||
if data != nil {
|
if data != nil {
|
||||||
if len(data) != dataLen {
|
if len(data) != dataLen {
|
||||||
panic(newBitStorageErr{ArrlLen: len(data), WantLen: dataLen})
|
panic(newBitStorageErr{ArrlLen: len(data), WantLen: dataLen})
|
||||||
}
|
}
|
||||||
b.data = data
|
copy(b.data, data)
|
||||||
} else {
|
|
||||||
b.data = make([]uint64, dataLen)
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -107,19 +107,16 @@ func ChunkFromSave(c *save.Chunk) (*Chunk, error) {
|
|||||||
blockEntities[i].Type = block.EntityTypes[tmp.ID]
|
blockEntities[i].Type = block.EntityTypes[tmp.ID]
|
||||||
}
|
}
|
||||||
|
|
||||||
motionBlocking := c.Heightmaps.MotionBlocking
|
|
||||||
motionBlockingNoLeaves := c.Heightmaps.MotionBlockingNoLeaves
|
|
||||||
oceanFloor := c.Heightmaps.OceanFloor
|
|
||||||
worldSurface := c.Heightmaps.WorldSurface
|
|
||||||
|
|
||||||
bitsForHeight := bits.Len( /* chunk height in blocks */ uint(secs) * 16)
|
bitsForHeight := bits.Len( /* chunk height in blocks */ uint(secs) * 16)
|
||||||
return &Chunk{
|
return &Chunk{
|
||||||
Sections: sections,
|
Sections: sections,
|
||||||
HeightMaps: HeightMaps{
|
HeightMaps: HeightMaps{
|
||||||
MotionBlocking: NewBitStorage(bitsForHeight, 16*16, motionBlocking),
|
WorldSurface: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["WORLD_SURFACE_WG"]),
|
||||||
MotionBlockingNoLeaves: NewBitStorage(bitsForHeight, 16*16, motionBlockingNoLeaves),
|
WorldSurfaceWG: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["WORLD_SURFACE"]),
|
||||||
OceanFloor: NewBitStorage(bitsForHeight, 16*16, oceanFloor),
|
OceanFloorWG: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["OCEAN_FLOOR_WG"]),
|
||||||
WorldSurface: NewBitStorage(bitsForHeight, 16*16, worldSurface),
|
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),
|
||||||
@ -188,7 +185,12 @@ func ChunkToSave(c *Chunk, dst *save.Chunk) (err error) {
|
|||||||
s.BlockLight = v.BlockLight
|
s.BlockLight = v.BlockLight
|
||||||
}
|
}
|
||||||
dst.Sections = sections
|
dst.Sections = sections
|
||||||
dst.Heightmaps.MotionBlocking = c.HeightMaps.MotionBlocking.Raw()
|
dst.Heightmaps["WORLD_SURFACE_WG"] = c.HeightMaps.WorldSurfaceWG.Raw()
|
||||||
|
dst.Heightmaps["WORLD_SURFACE"] = c.HeightMaps.WorldSurface.Raw()
|
||||||
|
dst.Heightmaps["OCEAN_FLOOR_WG"] = c.HeightMaps.OceanFloorWG.Raw()
|
||||||
|
dst.Heightmaps["OCEAN_FLOOR"] = c.HeightMaps.OceanFloor.Raw()
|
||||||
|
dst.Heightmaps["MOTION_BLOCKING"] = c.HeightMaps.MotionBlocking.Raw()
|
||||||
|
dst.Heightmaps["MOTION_BLOCKING_NO_LEAVES"] = c.HeightMaps.MotionBlockingNoLeaves.Raw()
|
||||||
dst.Status = string(c.Status)
|
dst.Status = string(c.Status)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -314,10 +316,12 @@ func (c *Chunk) PutData(data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type HeightMaps struct {
|
type HeightMaps struct {
|
||||||
MotionBlocking *BitStorage
|
WorldSurfaceWG *BitStorage // test = NOT_AIR
|
||||||
MotionBlockingNoLeaves *BitStorage
|
WorldSurface *BitStorage // test = NOT_AIR
|
||||||
OceanFloor *BitStorage
|
OceanFloorWG *BitStorage // test = MATERIAL_MOTION_BLOCKING
|
||||||
WorldSurface *BitStorage
|
OceanFloor *BitStorage // test = MATERIAL_MOTION_BLOCKING
|
||||||
|
MotionBlocking *BitStorage // test = BlocksMotion or isFluid
|
||||||
|
MotionBlockingNoLeaves *BitStorage // test = BlocksMotion or isFluid
|
||||||
}
|
}
|
||||||
|
|
||||||
type BlockEntity struct {
|
type BlockEntity struct {
|
||||||
|
@ -12,27 +12,24 @@ import (
|
|||||||
|
|
||||||
// Chunk is 16* chunk
|
// Chunk is 16* chunk
|
||||||
type Chunk struct {
|
type Chunk struct {
|
||||||
DataVersion int32
|
BlockEntities []nbt.RawMessage `nbt:"block_entities"`
|
||||||
XPos int32 `nbt:"xPos"`
|
BlockTicks nbt.RawMessage `nbt:"block_ticks"`
|
||||||
YPos int32 `nbt:"yPos"`
|
CarvingMasks map[string][]uint64
|
||||||
ZPos int32 `nbt:"zPos"`
|
DataVersion int32
|
||||||
BlockEntities []nbt.RawMessage `nbt:"block_entities"`
|
Entities []nbt.RawMessage `nbt:"entities"`
|
||||||
Structures nbt.RawMessage `nbt:"structures"`
|
FluidTicks nbt.RawMessage `nbt:"fluid_ticks"`
|
||||||
Heightmaps struct {
|
Heightmaps map[string][]uint64 // keys: "WORLD_SURFACE_WG", "WORLD_SURFACE", "WORLD_SURFACE_IGNORE_SNOW", "OCEAN_FLOOR_WG", "OCEAN_FLOOR", "MOTION_BLOCKING", "MOTION_BLOCKING_NO_LEAVES"
|
||||||
MotionBlocking []uint64 `nbt:"MOTION_BLOCKING"`
|
|
||||||
MotionBlockingNoLeaves []uint64 `nbt:"MOTION_BLOCKING_NO_LEAVES"`
|
|
||||||
OceanFloor []uint64 `nbt:"OCEAN_FLOOR"`
|
|
||||||
WorldSurface []uint64 `nbt:"WORLD_SURFACE"`
|
|
||||||
}
|
|
||||||
Sections []Section `nbt:"sections"`
|
|
||||||
|
|
||||||
BlockTicks nbt.RawMessage `nbt:"block_ticks"`
|
|
||||||
FluidTicks nbt.RawMessage `nbt:"fluid_ticks"`
|
|
||||||
PostProcessing nbt.RawMessage
|
|
||||||
InhabitedTime int64
|
InhabitedTime int64
|
||||||
IsLightOn byte `nbt:"isLightOn"`
|
IsLightOn byte `nbt:"isLightOn"`
|
||||||
LastUpdate int64
|
LastUpdate int64
|
||||||
|
Lights []nbt.RawMessage
|
||||||
|
PostProcessing nbt.RawMessage
|
||||||
|
Sections []Section `nbt:"sections"`
|
||||||
Status string
|
Status string
|
||||||
|
Structures nbt.RawMessage `nbt:"structures"`
|
||||||
|
XPos int32 `nbt:"xPos"`
|
||||||
|
YPos int32 `nbt:"yPos"`
|
||||||
|
ZPos int32 `nbt:"zPos"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Section struct {
|
type Section struct {
|
||||||
@ -68,12 +65,13 @@ func (c *Chunk) Load(data []byte) (err error) {
|
|||||||
case 3:
|
case 3:
|
||||||
// none compression
|
// none compression
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = nbt.NewDecoder(r).Decode(c)
|
d := nbt.NewDecoder(r)
|
||||||
|
//d.DisallowUnknownFields()
|
||||||
|
_, err = d.Decode(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,29 +1,47 @@
|
|||||||
package save
|
package save
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/save/region"
|
"github.com/Tnze/go-mc/save/region"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestColumn(t *testing.T) {
|
func TestColumn(t *testing.T) {
|
||||||
r, err := region.Open("testdata/region/r.0.0.mca")
|
files, err := filepath.Glob("testdata/region/r.*.*.mca")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
return
|
||||||
}
|
}
|
||||||
defer r.Close()
|
for _, filename := range files {
|
||||||
|
r, err := region.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
var c Chunk
|
for x := 0; x < 32; x++ {
|
||||||
data, err := r.ReadSector(0, 0)
|
for z := 0; z < 32; z++ {
|
||||||
if err != nil {
|
if !r.ExistSector(x, z) {
|
||||||
t.Fatal(err)
|
continue
|
||||||
}
|
}
|
||||||
err = c.Load(data)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Logf("%+v", c)
|
data, err := r.ReadSector(x, z)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("read %s sec (%d, %d) fail: %v", filepath.Base(filename), x, z, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var c Chunk
|
||||||
|
err = c.Load(data)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("read %s sec (%d, %d) fail: %v", filepath.Base(filename), x, z, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = r.Close()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkColumn_Load(b *testing.B) {
|
func BenchmarkColumn_Load(b *testing.B) {
|
||||||
|
@ -233,9 +233,9 @@ func (r *Region) ExistSector(x, z int) bool {
|
|||||||
return r.offsets[z][x] != 0
|
return r.offsets[z][x] != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// PadToFullSector writes zeros to the end of the file to make size a multiple of 4096
|
// PadToFullSector writes zeros to the end of the file to make size a multiple of 4096.
|
||||||
// Legacy versions of Minecraft require this
|
// Legacy versions of Minecraft require this.
|
||||||
// Need to be called right before Close
|
// Need to be called right before Close.
|
||||||
func (r *Region) PadToFullSector() error {
|
func (r *Region) PadToFullSector() error {
|
||||||
size, err := r.f.Seek(0, io.SeekEnd)
|
size, err := r.f.Seek(0, io.SeekEnd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user