SkyLight and BlockLight
This commit is contained in:
@ -6,7 +6,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math/bits"
|
"math/bits"
|
||||||
"strings"
|
"strings"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/level/block"
|
"github.com/Tnze/go-mc/level/block"
|
||||||
"github.com/Tnze/go-mc/nbt"
|
"github.com/Tnze/go-mc/nbt"
|
||||||
@ -194,15 +193,23 @@ func ChunkFromSave(c *save.Chunk) *Chunk {
|
|||||||
sections := make([]Section, secs)
|
sections := make([]Section, secs)
|
||||||
for _, v := range c.Sections {
|
for _, v := range c.Sections {
|
||||||
i := int32(v.Y) - c.YPos
|
i := int32(v.Y) - c.YPos
|
||||||
// TODO: the error is ignored
|
var err error
|
||||||
sections[i].BlockCount, sections[i].States, _ = readStatesPalette(v.BlockStates.Palette, v.BlockStates.Data)
|
sections[i].BlockCount, sections[i].States, err = readStatesPalette(v.BlockStates.Palette, v.BlockStates.Data)
|
||||||
sections[i].Biomes, _ = readBiomesPalette(v.Biomes.Palette, v.Biomes.Data)
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
sections[i].Biomes, err = readBiomesPalette(v.Biomes.Palette, v.Biomes.Data)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
sections[i].SkyLight = v.SkyLight
|
||||||
|
sections[i].BlockLight = v.BlockLight
|
||||||
}
|
}
|
||||||
|
|
||||||
motionBlocking := *(*[]uint64)(unsafe.Pointer(&c.Heightmaps.MotionBlocking))
|
motionBlocking := c.Heightmaps.MotionBlocking
|
||||||
motionBlockingNoLeaves := *(*[]uint64)(unsafe.Pointer(&c.Heightmaps.MotionBlockingNoLeaves))
|
motionBlockingNoLeaves := c.Heightmaps.MotionBlockingNoLeaves
|
||||||
oceanFloor := *(*[]uint64)(unsafe.Pointer(&c.Heightmaps.OceanFloor))
|
oceanFloor := c.Heightmaps.OceanFloor
|
||||||
worldSurface := *(*[]uint64)(unsafe.Pointer(&c.Heightmaps.WorldSurface))
|
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{
|
||||||
@ -264,6 +271,8 @@ func ChunkToSave(c *Chunk, dst *save.Chunk) {
|
|||||||
s.Y = int8(int32(i) + dst.YPos)
|
s.Y = int8(int32(i) + dst.YPos)
|
||||||
states.Palette, states.Data = writeStatesPalette(v.States)
|
states.Palette, states.Data = writeStatesPalette(v.States)
|
||||||
biomes.Palette, biomes.Data = writeBiomesPalette(v.Biomes)
|
biomes.Palette, biomes.Data = writeBiomesPalette(v.Biomes)
|
||||||
|
s.SkyLight = v.SkyLight
|
||||||
|
s.BlockLight = v.BlockLight
|
||||||
}
|
}
|
||||||
dst.Sections = sections
|
dst.Sections = sections
|
||||||
//dst.Heightmaps.MotionBlocking = c.HeightMaps.MotionBlocking.Raw()
|
//dst.Heightmaps.MotionBlocking = c.HeightMaps.MotionBlocking.Raw()
|
||||||
@ -306,6 +315,22 @@ func (c *Chunk) WriteTo(w io.Writer) (int64, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
light := 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{},
|
||||||
|
}
|
||||||
|
for i, v := range c.Sections {
|
||||||
|
if v.SkyLight != nil {
|
||||||
|
light.SkyLightMask.Set(i, true)
|
||||||
|
light.SkyLight = append(light.SkyLight, v.SkyLight)
|
||||||
|
}
|
||||||
|
if v.BlockLight != nil {
|
||||||
|
light.BlockLightMask.Set(i, true)
|
||||||
|
light.BlockLight = append(light.BlockLight, v.BlockLight)
|
||||||
|
}
|
||||||
|
}
|
||||||
return pk.Tuple{
|
return pk.Tuple{
|
||||||
// Heightmaps
|
// Heightmaps
|
||||||
pk.NBT(struct {
|
pk.NBT(struct {
|
||||||
@ -317,12 +342,7 @@ func (c *Chunk) WriteTo(w io.Writer) (int64, error) {
|
|||||||
}),
|
}),
|
||||||
pk.ByteArray(data),
|
pk.ByteArray(data),
|
||||||
pk.Array(c.BlockEntity),
|
pk.Array(c.BlockEntity),
|
||||||
&lightData{
|
&light,
|
||||||
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{},
|
|
||||||
},
|
|
||||||
}.WriteTo(w)
|
}.WriteTo(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,6 +436,10 @@ type Section struct {
|
|||||||
BlockCount int16
|
BlockCount int16
|
||||||
States *PaletteContainer[BlocksState]
|
States *PaletteContainer[BlocksState]
|
||||||
Biomes *PaletteContainer[BiomesState]
|
Biomes *PaletteContainer[BiomesState]
|
||||||
|
// Half a byte per light value.
|
||||||
|
// Could be nil if not exist
|
||||||
|
SkyLight []byte // len() == 2048
|
||||||
|
BlockLight []byte // len() == 2048
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Section) GetBlock(i int) BlocksState {
|
func (s *Section) GetBlock(i int) BlocksState {
|
||||||
|
@ -45,8 +45,8 @@ type Section struct {
|
|||||||
Palette []string `nbt:"palette"`
|
Palette []string `nbt:"palette"`
|
||||||
Data []uint64 `nbt:"data"`
|
Data []uint64 `nbt:"data"`
|
||||||
} `nbt:"biomes"`
|
} `nbt:"biomes"`
|
||||||
SkyLight []int8
|
SkyLight []byte
|
||||||
BlockLight []int8
|
BlockLight []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type BlockState struct {
|
type BlockState struct {
|
||||||
|
Reference in New Issue
Block a user