Skip to content

Commit

Permalink
change some warnings to debug logs and improve some entity id index code
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Jan 13, 2025
1 parent 5721eaf commit a86d011
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
29 changes: 16 additions & 13 deletions azalea-client/src/packet_handling/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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>,
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
};

Expand Down
12 changes: 6 additions & 6 deletions azalea-entity/src/plugin/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ impl EntityUuidIndex {
}

impl EntityIdIndex {
pub fn get(&self, id: &MinecraftEntityId) -> Option<Entity> {
self.entity_by_id.get(id).copied()
pub fn get(&self, id: MinecraftEntityId) -> Option<Entity> {
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<Entity> {
self.entity_by_id.remove(id)
pub fn remove(&mut self, id: MinecraftEntityId) -> Option<Entity> {
self.entity_by_id.remove(&id)
}
}

Expand Down

0 comments on commit a86d011

Please sign in to comment.