diff --git a/common/src/rtsim.rs b/common/src/rtsim.rs index e6d13d8533..aee3d932a0 100644 --- a/common/src/rtsim.rs +++ b/common/src/rtsim.rs @@ -233,7 +233,7 @@ pub enum NpcAction { // Note: the `serde(name = "...")` is to minimise the length of field // identifiers for the sake of rtsim persistence -#[derive(Copy, Clone, Debug, Serialize, Deserialize, enum_map::Enum)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, enum_map::Enum)] pub enum ChunkResource { #[serde(rename = "0")] Grass, diff --git a/server/src/lib.rs b/server/src/lib.rs index e47d3e412f..e108015a27 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -700,9 +700,10 @@ impl Server { fn on_block_update(ecs: &specs::World, changes: Vec) { // When a resource block updates, inform rtsim - if changes.iter().any(|c| { - c.old.get_rtsim_resource().is_some() || c.new.get_rtsim_resource().is_some() - }) { + if changes + .iter() + .any(|c| c.old.get_rtsim_resource() != c.new.get_rtsim_resource()) + { ecs.write_resource::().hook_block_update( &ecs.read_resource::>(), ecs.read_resource::().as_index_ref(), diff --git a/server/src/rtsim/mod.rs b/server/src/rtsim/mod.rs index 27ad649538..ed807d9f4e 100644 --- a/server/src/rtsim/mod.rs +++ b/server/src/rtsim/mod.rs @@ -159,6 +159,8 @@ impl RtSim { } } + // Note that this hook only needs to be invoked if the block change results in a + // change to the rtsim resource produced by [`Block::get_rtsim_resource`]. pub fn hook_block_update(&mut self, world: &World, index: IndexRef, changes: Vec) { self.state .emit(event::OnBlockChange { changes }, world, index);