diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index 0a64f0269b..dcc0fa2f5b 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -156,8 +156,19 @@ impl<'a> System<'a> for Sys { }, }; - for (key, block) in terrain_persistence.load_chunk(key).blocks() { - chunk.set(key, block); + // Terrain persistence + let mut resets = Vec::new(); + for (rpos, new_block) in terrain_persistence.load_chunk(key).blocks() { + chunk.map(rpos, |block| { + if block == new_block { + resets.push(rpos); + } + new_block + }); + } + // Reset any unchanged blocks + for rpos in resets { + terrain_persistence.reset_block(key, rpos); } // Arcify the chunk diff --git a/server/src/terrain_persistence.rs b/server/src/terrain_persistence.rs index 67769c1b1b..91df2b4625 100644 --- a/server/src/terrain_persistence.rs +++ b/server/src/terrain_persistence.rs @@ -103,6 +103,10 @@ impl TerrainPersistence { let key = pos.xy().map2(TerrainChunk::RECT_SIZE, |e, sz| e.div_euclid(sz as i32)); self.load_chunk(key).blocks.insert(pos - key * TerrainChunk::RECT_SIZE.map(|e| e as i32), block); } + + pub fn reset_block(&mut self, key: Vec2, rpos: Vec3) { + self.load_chunk(key).blocks.remove(&rpos); + } } #[derive(Default, Serialize, Deserialize)]