aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity/src/plugin
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-08-25 00:35:16 -0500
committermat <git@matdoes.dev>2023-08-25 00:35:16 -0500
commit9c31f8033f006d5f505ce97e359638d6c1136859 (patch)
tree843f0074fef4c8d5c2d71ccbb529c55394350cb9 /azalea-entity/src/plugin
parent11d14c74c53c07231c8ca33b622380df99bf9a59 (diff)
downloadazalea-drasl-9c31f8033f006d5f505ce97e359638d6c1136859.tar.xz
fix panic when entity goes out of render distance and then back in render distance
Diffstat (limited to 'azalea-entity/src/plugin')
-rw-r--r--azalea-entity/src/plugin/indexing.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/azalea-entity/src/plugin/indexing.rs b/azalea-entity/src/plugin/indexing.rs
index 0f6232fa..23f53c5f 100644
--- a/azalea-entity/src/plugin/indexing.rs
+++ b/azalea-entity/src/plugin/indexing.rs
@@ -233,9 +233,19 @@ pub fn remove_despawned_entities_from_indexes(
mut commands: Commands,
mut entity_infos: ResMut<EntityUuidIndex>,
instance_container: Res<InstanceContainer>,
- query: Query<(Entity, &EntityUuid, &Position, &InstanceName, &LoadedBy), Changed<LoadedBy>>,
+ query: Query<
+ (
+ Entity,
+ &EntityUuid,
+ &MinecraftEntityId,
+ &Position,
+ &InstanceName,
+ &LoadedBy,
+ ),
+ Changed<LoadedBy>,
+ >,
) {
- for (entity, uuid, position, world_name, loaded_by) in &query {
+ for (entity, uuid, minecraft_id, position, world_name, loaded_by) in &query {
let Some(instance_lock) = instance_container.get(world_name) else {
// the instance isn't even loaded by us, so we can safely delete the entity
debug!(
@@ -277,6 +287,9 @@ pub fn remove_despawned_entities_from_indexes(
if entity_infos.entity_by_uuid.remove(uuid).is_none() {
warn!("Tried to remove entity {entity:?} from the uuid index but it was not there.");
}
+ if instance.entity_by_id.remove(minecraft_id).is_none() {
+ warn!("Tried to remove entity {entity:?} from the id index but it was not there.");
+ }
// and now remove the entity from the ecs
commands.entity(entity).despawn();
debug!("Despawned entity {entity:?} because it was not loaded by anything.");