Merge branch 'zesterer/fix-entity-despawning' into 'master'

Allow entities to despawn without a home chunk

See merge request veloren/veloren!1544
This commit is contained in:
Joshua Barretto 2020-11-23 16:14:13 +00:00
commit 4e8cce3dc8

View File

@ -524,7 +524,7 @@ impl Server {
&self.state.ecs().entities(), &self.state.ecs().entities(),
&self.state.ecs().read_storage::<comp::Pos>(), &self.state.ecs().read_storage::<comp::Pos>(),
!&self.state.ecs().read_storage::<comp::Player>(), !&self.state.ecs().read_storage::<comp::Player>(),
&self.state.ecs().read_storage::<comp::HomeChunk>(), self.state.ecs().read_storage::<comp::HomeChunk>().maybe(),
) )
.join() .join()
.filter(|(_, pos, _, home_chunk)| { .filter(|(_, pos, _, home_chunk)| {
@ -532,7 +532,8 @@ impl Server {
// Check if both this chunk and the NPCs `home_chunk` is unloaded. If so, // Check if both this chunk and the NPCs `home_chunk` is unloaded. If so,
// we delete them. We check for `home_chunk` in order to avoid duplicating // we delete them. We check for `home_chunk` in order to avoid duplicating
// the entity under some circumstances. // the entity under some circumstances.
terrain.get_key(chunk_key).is_none() && terrain.get_key(home_chunk.0).is_none() terrain.get_key(chunk_key).is_none()
&& home_chunk.map_or(true, |hc| terrain.get_key(hc.0).is_none())
}) })
.map(|(entity, _, _, _)| entity) .map(|(entity, _, _, _)| entity)
.collect::<Vec<_>>() .collect::<Vec<_>>()