From 9c31f8033f006d5f505ce97e359638d6c1136859 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 25 Aug 2023 00:35:16 -0500 Subject: fix panic when entity goes out of render distance and then back in render distance --- azalea-entity/src/plugin/indexing.rs | 17 +++++++++++++++-- 1 file 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, instance_container: Res, - query: Query<(Entity, &EntityUuid, &Position, &InstanceName, &LoadedBy), Changed>, + query: Query< + ( + Entity, + &EntityUuid, + &MinecraftEntityId, + &Position, + &InstanceName, + &LoadedBy, + ), + Changed, + >, ) { - 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."); -- cgit v1.2.3