feat(save): 存档系统——region 文件(zstd+CRC32+原子替换)、level.dat、区块序列化、世界存取(含测试)

This commit is contained in:
NianGao Dev
2026-08-15 22:59:31 +08:00
parent ba187f6f85
commit 509c6f228c
12 changed files with 1360 additions and 12 deletions

View File

@@ -114,3 +114,23 @@ func (c *Chunk) Snapshot() []block.State {
copy(out, c.blocks)
return out
}
// LightBytes 复制天空光/方块光原始字节(存档序列化用)。
func (c *Chunk) LightBytes() (sky, blockLt []byte) {
c.mu.RLock()
defer c.mu.RUnlock()
sky = make([]byte, len(c.sky))
bl := make([]byte, len(c.blockLt))
copy(sky, c.sky)
copy(bl, c.blockLt)
return sky, bl
}
// SetAll 整体覆盖方块与光照数据(存档载入用;不标脏——载入即当前状态)。
func (c *Chunk) SetAll(blocks []block.State, sky, blockLt []byte) {
c.mu.Lock()
copy(c.blocks, blocks)
copy(c.sky, sky)
copy(c.blockLt, blockLt)
c.mu.Unlock()
}