fix heightmaps sending error

This commit is contained in:
Tnze
2023-04-23 00:51:22 +08:00
parent 5f06fa6510
commit be42d0ec35

View File

@ -110,7 +110,7 @@ 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) bitsForHeight := bits.Len( /* chunk height in blocks */ uint(secs)*16 + 1)
return &Chunk{ return &Chunk{
Sections: sections, Sections: sections,
HeightMaps: HeightMaps{ HeightMaps: HeightMaps{
@ -271,7 +271,7 @@ func (c *Chunk) WriteTo(w io.Writer) (int64, error) {
WorldSurface []uint64 `nbt:"WORLD_SURFACE"` WorldSurface []uint64 `nbt:"WORLD_SURFACE"`
}{ }{
MotionBlocking: c.HeightMaps.MotionBlocking.Raw(), MotionBlocking: c.HeightMaps.MotionBlocking.Raw(),
WorldSurface: c.HeightMaps.MotionBlocking.Raw(), WorldSurface: c.HeightMaps.WorldSurface.Raw(),
}), }),
pk.ByteArray(data), pk.ByteArray(data),
pk.Array(c.BlockEntity), pk.Array(c.BlockEntity),
@ -303,6 +303,10 @@ func (c *Chunk) ReadFrom(r io.Reader) (int64, error) {
return n, err return n, err
} }
bitsForHeight := bits.Len( /* chunk height in blocks */ uint(len(c.Sections))*16 + 1)
c.HeightMaps.MotionBlocking = NewBitStorage(bitsForHeight, 16*16, heightmaps.MotionBlocking)
c.HeightMaps.WorldSurface = NewBitStorage(bitsForHeight, 16*16, heightmaps.WorldSurface)
err = c.PutData(data) err = c.PutData(data)
return n, err return n, err
} }