From f759fd5059366a10b3460f3fc8def1591e11dab1 Mon Sep 17 00:00:00 2001 From: Maxicarlos08 Date: Fri, 26 Jan 2024 00:57:21 +0100 Subject: [PATCH 1/2] don't remove blocks when applying changes for new chunks --- server/src/terrain_persistence.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/server/src/terrain_persistence.rs b/server/src/terrain_persistence.rs index 9d3b1af9ee..25414ccf59 100644 --- a/server/src/terrain_persistence.rs +++ b/server/src/terrain_persistence.rs @@ -74,15 +74,11 @@ impl TerrainPersistence { } } - let removed = resets.len(); - // Reset any unchanged blocks (this is an optimisation only) for rpos in resets { loaded_chunk.chunk.reset_block(rpos); loaded_chunk.modified = true; } - - self.cached_chunks.limiter_mut().remove_blocks(removed); } /// Maintain terrain persistence (writing changes changes back to @@ -314,10 +310,6 @@ impl ByBlockLimiter { /// This function should only be used when it is guaranteed that a block has /// been added fn add_block(&mut self) { self.counted_blocks += 1; } - - /// This function should only be used when it is guaranteed that this number - /// of blocks has been removed - fn remove_blocks(&mut self, removed: usize) { self.counted_blocks -= removed; } } /// # Adding a new chunk format version From 47a909e94ddb13866e1aca58d2944b33fa28b454 Mon Sep 17 00:00:00 2001 From: Maxicarlos08 Date: Fri, 26 Jan 2024 02:15:14 +0100 Subject: [PATCH 2/2] fix the *actual* crash --- common/src/terrain/block.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index e04c195396..1160c6877e 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -672,10 +672,12 @@ impl Block { #[must_use] pub fn from_u32(x: u32) -> Option { let [bk, r, g, b] = x.to_le_bytes(); - Some(Self { + let block = Self { kind: BlockKind::from_u8(bk)?, data: [r, g, b], - }) + }; + + (block.kind.is_filled() || SpriteKind::from_block(block).is_some()).then_some(block) } #[inline]