place blocks

This commit is contained in:
2022-02-24 20:20:33 +08:00
parent 9195dd7c3f
commit 32b06810e2
17 changed files with 309 additions and 55 deletions

View File

@@ -4,6 +4,8 @@ import (
"encoding/gob"
"io"
"log"
"edgaru089.ml/go/gl01/internal/util/itype"
)
const (
@@ -40,6 +42,27 @@ func (c *Chunk) SetBlock(x, y, z int, id, aux int) {
c.Id[x][y][z] = uint16(id)
c.Aux[x][y][z] = uint16(aux)
c.renderChanged = true
switch x {
case 0:
if cb, ok := c.world.Chunks[itype.Vec2i{c.X - 1, c.Z}]; ok {
cb.InvalidateRender()
}
case ChunkSizeX - 1:
if cb, ok := c.world.Chunks[itype.Vec2i{c.X + 1, c.Z}]; ok {
cb.InvalidateRender()
}
}
switch z {
case 0:
if cb, ok := c.world.Chunks[itype.Vec2i{c.X, c.Z - 1}]; ok {
cb.InvalidateRender()
}
case ChunkSizeZ - 1:
if cb, ok := c.world.Chunks[itype.Vec2i{c.X, c.Z + 1}]; ok {
cb.InvalidateRender()
}
}
}
// InvalidateRender should be called if a block inside the chunk has changed