diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs index 0d5a6afe3..4d1d9e100 100644 --- a/azalea-client/src/packet_handling/game.rs +++ b/azalea-client/src/packet_handling/game.rs @@ -727,7 +727,7 @@ pub fn process_packet_events(ecs: &mut World) { let (mut commands, mut query, entity_kind_query) = system_state.get_mut(ecs); let (entity_id_index, instance_holder) = query.get_mut(player_entity).unwrap(); - let entity = entity_id_index.get(&MinecraftEntityId(p.id)); + let entity = entity_id_index.get(MinecraftEntityId(p.id)); let Some(entity) = entity else { warn!("Server sent an entity data packet for an entity id ({}) that we don't know about", p.id); @@ -773,8 +773,11 @@ pub fn process_packet_events(ecs: &mut World) { let (mut commands, mut query) = system_state.get_mut(ecs); let (entity_id_index, instance_holder) = query.get_mut(player_entity).unwrap(); - let Some(entity) = entity_id_index.get(&MinecraftEntityId(p.id)) else { - warn!( + let Some(entity) = entity_id_index.get(MinecraftEntityId(p.id)) else { + // note that this log (and some other ones like the one in RemoveEntities) + // sometimes happens when killing mobs. it seems to be a vanilla bug, which is + // why it's a debug log instead of a warning + debug!( "Got set entity motion packet for unknown entity id {}", p.id ); @@ -839,7 +842,7 @@ pub fn process_packet_events(ecs: &mut World) { let (mut commands, mut query) = system_state.get_mut(ecs); let (entity_id_index, instance_holder) = query.get_mut(player_entity).unwrap(); - let Some(entity) = entity_id_index.get(&MinecraftEntityId(p.id)) else { + let Some(entity) = entity_id_index.get(MinecraftEntityId(p.id)) else { warn!("Got teleport entity packet for unknown entity id {}", p.id); continue; }; @@ -885,8 +888,8 @@ pub fn process_packet_events(ecs: &mut World) { debug!("Got move entity pos packet {p:?}"); - let Some(entity) = entity_id_index.get(&MinecraftEntityId(p.entity_id)) else { - warn!( + let Some(entity) = entity_id_index.get(MinecraftEntityId(p.entity_id)) else { + debug!( "Got move entity pos packet for unknown entity id {}", p.entity_id ); @@ -926,7 +929,7 @@ pub fn process_packet_events(ecs: &mut World) { debug!("Got move entity pos rot packet {p:?}"); - let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id)); + let entity = entity_id_index.get(MinecraftEntityId(p.entity_id)); if let Some(entity) = entity { let new_delta = p.delta.clone(); @@ -978,7 +981,7 @@ pub fn process_packet_events(ecs: &mut World) { let (mut commands, mut query) = system_state.get_mut(ecs); let (entity_id_index, instance_holder) = query.get_mut(player_entity).unwrap(); - let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id)); + let entity = entity_id_index.get(MinecraftEntityId(p.entity_id)); if let Some(entity) = entity { let new_look_direction = LookDirection { @@ -1027,7 +1030,7 @@ pub fn process_packet_events(ecs: &mut World) { )); } ClientboundGamePacket::RemoveEntities(p) => { - debug!("Got remove entities packet {:?}", p); + debug!("Got remove entities packet {p:?}"); let mut system_state: SystemState<( Query<&mut EntityIdIndex>, @@ -1041,8 +1044,8 @@ pub fn process_packet_events(ecs: &mut World) { }; for &id in &p.entity_ids { - let Some(entity) = entity_id_index.remove(&MinecraftEntityId(id)) else { - warn!("There is no entity with id {id:?}"); + let Some(entity) = entity_id_index.remove(MinecraftEntityId(id)) else { + debug!("Tried to remove entity with id {id} but it wasn't in the EntityIdIndex"); continue; }; let Ok(mut loaded_by) = entity_query.get_mut(entity) else { @@ -1480,8 +1483,8 @@ pub fn process_packet_events(ecs: &mut World) { let (mut commands, mut query) = system_state.get_mut(ecs); let (entity_id_index, instance_holder) = query.get_mut(player_entity).unwrap(); - let Some(entity) = entity_id_index.get(&MinecraftEntityId(p.id)) else { - warn!("Got teleport entity packet for unknown entity id {}", p.id); + let Some(entity) = entity_id_index.get(MinecraftEntityId(p.id)) else { + debug!("Got teleport entity packet for unknown entity id {}", p.id); continue; }; diff --git a/azalea-entity/src/plugin/indexing.rs b/azalea-entity/src/plugin/indexing.rs index c4879c4f0..f1105d89d 100644 --- a/azalea-entity/src/plugin/indexing.rs +++ b/azalea-entity/src/plugin/indexing.rs @@ -61,20 +61,20 @@ impl EntityUuidIndex { } impl EntityIdIndex { - pub fn get(&self, id: &MinecraftEntityId) -> Option { - self.entity_by_id.get(id).copied() + pub fn get(&self, id: MinecraftEntityId) -> Option { + self.entity_by_id.get(&id).copied() } - pub fn contains_key(&self, id: &MinecraftEntityId) -> bool { - self.entity_by_id.contains_key(id) + pub fn contains_key(&self, id: MinecraftEntityId) -> bool { + self.entity_by_id.contains_key(&id) } pub fn insert(&mut self, id: MinecraftEntityId, entity: Entity) { self.entity_by_id.insert(id, entity); } - pub fn remove(&mut self, id: &MinecraftEntityId) -> Option { - self.entity_by_id.remove(id) + pub fn remove(&mut self, id: MinecraftEntityId) -> Option { + self.entity_by_id.remove(&id) } }