diff --git a/CHANGELOG.md b/CHANGELOG.md index 8916bbad62..09d62fa4d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Location names are now also correct after editing and creating characters - NPC's wont pick up recently dropped items (if not hostile towards you) - Fixed "low fps" of different shaders caused by low floating point precision when using time. +- Fixed bug where airship captains would mass generate after using /reload_chunks ## [0.15.0] - 2023-07-01 diff --git a/server/src/cmd.rs b/server/src/cmd.rs index b8b0d3ca63..f5b1093a93 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -3489,6 +3489,12 @@ fn handle_reload_chunks( _args: Vec, _action: &ServerChatCommand, ) -> CmdResult<()> { + #[cfg(feature = "persistent_world")] + server + .state + .ecs() + .write_resource::() + .unload_all(); server.state.clear_terrain(); Ok(()) diff --git a/server/src/lib.rs b/server/src/lib.rs index 218bb13d08..985959cacc 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -811,6 +811,15 @@ impl Server { run_now::(self.state.ecs_mut()); } + // Hook rtsim chunk unloads + #[cfg(feature = "worldgen")] + { + let mut rtsim = self.state.ecs().write_resource::(); + for chunk in &self.state.terrain_changes().removed_chunks { + rtsim.hook_unload_chunk(*chunk); + } + } + // Prevent anchor entity chains which are not currently supported let anchors = self.state.ecs().read_storage::(); let anchored_anchor_entities: Vec = ( diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index 9386b898a4..fd8ca57589 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -380,11 +380,13 @@ impl<'a> System<'a> for Sys { chunk_generator.cancel_if_pending(key); + // If you want to trigger any behaivour on unload, do it in `Server::tick` by + // reading `TerrainChanges::removed_chunks` since chunks can also be removed + // using eg. /reload_chunks + // TODO: code duplication for chunk insertion between here and state.rs terrain.remove(key).map(|chunk| { terrain_changes.removed_chunks.insert(key); - #[cfg(feature = "worldgen")] - rtsim.hook_unload_chunk(key); chunk }) })