add block.get_field(...), block.set_field(...)

This commit is contained in:
MihailRis
2024-09-30 18:55:01 +03:00
parent 8d89e06ac5
commit fc99343fb5
5 changed files with 169 additions and 28 deletions
+8
View File
@@ -6,6 +6,7 @@
#include <algorithm>
#include <vector>
#include "data/StructLayout.hpp"
#include "coders/byte_utils.hpp"
#include "coders/json.hpp"
#include "content/Content.hpp"
@@ -370,6 +371,7 @@ void Chunks::set(
}
int lx = x - cx * CHUNK_W;
int lz = z - cz * CHUNK_D;
size_t index = vox_index(lx, y, lz);
// block finalization
voxel& vox = chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx];
@@ -380,6 +382,9 @@ void Chunks::set(
if (prevdef.rt.extended && !vox.state.segment) {
eraseSegments(prevdef, vox.state, gx, y, gz);
}
if (prevdef.dataStruct) {
chunk->blocksMetadata.free(chunk->blocksMetadata.find(index));
}
// block initialization
const auto& newdef = indices->blocks.require(id);
@@ -389,6 +394,9 @@ void Chunks::set(
if (!state.segment && newdef.rt.extended) {
repairSegments(newdef, state, gx, y, gz);
}
if (newdef.dataStruct) {
chunk->blocksMetadata.allocate(index, newdef.dataStruct->size());
}
if (y < chunk->bottom)
chunk->bottom = y;