fix: user bits and manually set rotation not saving

This commit is contained in:
MihailRis 2024-05-31 11:26:16 +03:00
parent 6d933ac263
commit 86dd6562de
4 changed files with 18 additions and 10 deletions

View File

@ -156,7 +156,7 @@ int l_set_block_rotation(lua_State* L) {
return 0;
}
vox->state.rotation = value;
scripting::level->chunks->getChunkByVoxel(x, y, z)->setModified(true);
scripting::level->chunks->getChunkByVoxel(x, y, z)->setModifiedAndUnsaved();
return 0;
}
@ -182,7 +182,7 @@ int l_set_block_states(lua_State* L) {
}
voxel* vox = scripting::level->chunks->get(x, y, z);
vox->state = int2blockstate(states);
chunk->setModified(true);
chunk->setModifiedAndUnsaved();
return 0;
}
@ -214,12 +214,17 @@ int l_set_block_user_bits(lua_State* L) {
size_t mask = ((1 << bits) - 1) << offset;
lua_Integer value = (lua_tointeger(L, 6) << offset) & mask;
Chunk* chunk = scripting::level->chunks->getChunkByVoxel(x, y, z);
if (chunk == nullptr) {
return 0;
}
voxel* vox = scripting::level->chunks->get(x, y, z);
if (vox == nullptr) {
return 0;
}
vox->state.userbits = (vox->state.userbits & (~mask)) | value;
return 0;
chunk->setModifiedAndUnsaved();
return 0;
}
int l_is_replaceable_at(lua_State* L) {

View File

@ -79,6 +79,11 @@ public:
inline void setModified(bool newState) {setFlags(ChunkFlag::MODIFIED, newState);}
inline void setModifiedAndUnsaved() {
setModified(true);
setUnsaved(true);
}
inline void setLoaded(bool newState) {setFlags(ChunkFlag::LOADED, newState);}
inline void setLoadedLights(bool newState) {setFlags(ChunkFlag::LOADED_LIGHTS, newState);}

View File

@ -179,9 +179,7 @@ void Chunks::set(int32_t x, int32_t y, int32_t z, uint32_t id, blockstate state)
chunk->removeBlockInventory(lx, y, lz);
vox.id = id;
vox.state = state;
chunk->setUnsaved(true);
chunk->setModified(true);
chunk->setModifiedAndUnsaved();
if (y < chunk->bottom) chunk->bottom = y;
else if (y + 1 > chunk->top) chunk->top = y + 1;

View File

@ -19,10 +19,10 @@ struct blockstate {
static_assert (sizeof(blockstate) == 2);
inline constexpr blockstate_t blockstate2int(blockstate b) {
return b.rotation |
(b.segment << 3) |
(b.reserved << 5) |
(b.userbits << 8);
return static_cast<blockstate_t>(b.rotation) |
static_cast<blockstate_t>(b.segment) << 3 |
static_cast<blockstate_t>(b.reserved) << 5 |
static_cast<blockstate_t>(b.userbits) << 8;
}
inline constexpr blockstate int2blockstate(blockstate_t i) {