mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Don't despawn entities so eagerly
This commit is contained in:
parent
87edbf02ab
commit
bb6ca9fcba
@ -54,6 +54,7 @@ use common::{
|
||||
},
|
||||
outcome::Outcome,
|
||||
recipe::default_recipe_book,
|
||||
spiral::Spiral2d,
|
||||
state::{State, TimeOfDay},
|
||||
sync::WorldSyncExt,
|
||||
terrain::TerrainChunkSize,
|
||||
@ -525,7 +526,14 @@ impl Server {
|
||||
!&self.state.ecs().read_storage::<comp::Player>(),
|
||||
)
|
||||
.join()
|
||||
.filter(|(_, pos, _)| terrain.get(pos.0.map(|e| e.floor() as i32)).is_err())
|
||||
.filter(|(_, pos, _)| {
|
||||
let chunk_key = terrain.pos_key(pos.0.map(|e| e.floor() as i32));
|
||||
// Check not only this chunk, but also all neighbours to avoid immediate
|
||||
// despawning if the entity walks outside of a valid chunk
|
||||
// briefly. If the entity isn't even near a loaded chunk then we get
|
||||
// rid of it.
|
||||
Spiral2d::new().all(|offs| terrain.get_key(chunk_key + offs).is_none())
|
||||
})
|
||||
.map(|(entity, _, _)| entity)
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user