From 4e5c551d650ad3233f9653aaad07b216191ec5b2 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 28 Mar 2025 00:54:17 +0000 Subject: fix entity deindexing happening at the wrong time --- azalea-client/src/plugins/packet/game/mod.rs | 22 ++++++++++++++-------- azalea-client/src/plugins/packet/mod.rs | 6 ++---- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'azalea-client/src/plugins') diff --git a/azalea-client/src/plugins/packet/game/mod.rs b/azalea-client/src/plugins/packet/game/mod.rs index 6bb93178..ae1f3deb 100644 --- a/azalea-client/src/plugins/packet/game/mod.rs +++ b/azalea-client/src/plugins/packet/game/mod.rs @@ -703,7 +703,10 @@ impl GamePacketHandler<'_> { let mut spawned = commands.spawn((entity_id, LoadedBy(HashSet::from([self.player])), bundle)); let ecs_entity: Entity = spawned.id(); - debug!("spawned entity {ecs_entity:?} with id {entity_id:?}"); + debug!( + "spawned entity {ecs_entity:?} with id {entity_id:?} at {pos:?}", + pos = p.position + ); azalea_entity::indexing::add_entity_to_indexes( entity_id, @@ -918,11 +921,9 @@ impl GamePacketHandler<'_> { debug!("Got move entity pos packet {p:?}"); - let Some(entity) = entity_id_index.get(p.entity_id) else { - debug!( - "Got move entity pos packet for unknown entity id {}", - p.entity_id - ); + let entity_id = p.entity_id; + let Some(entity) = entity_id_index.get(entity_id) else { + debug!("Got move entity pos packet for unknown entity id {entity_id}"); return; }; @@ -944,6 +945,11 @@ impl GamePacketHandler<'_> { if new_pos != **position { **position = new_pos; } + + trace!( + "Applied movement update for {entity_id} / {entity}", + entity = entity_mut.id() + ); }, )); }, @@ -1071,7 +1077,7 @@ impl GamePacketHandler<'_> { for &id in &p.entity_ids { let Some(entity) = entity_id_index.remove(id) else { debug!( - "Tried to remove entity with id {id} but it wasn't in the EntityIdIndex" + "Tried to remove entity with id {id} but it wasn't in the EntityIdIndex. This may be expected on certain server setups (like if they're using VeryManyPlayers)." ); continue; }; @@ -1082,7 +1088,7 @@ impl GamePacketHandler<'_> { continue; }; - // the [`remove_despawned_entities_from_indexes`] system will despawn the entity + // the `remove_despawned_entities_from_indexes` system will despawn the entity // if it's not loaded by anything anymore // also we can't just ecs.despawn because if we're in a swarm then the entity diff --git a/azalea-client/src/plugins/packet/mod.rs b/azalea-client/src/plugins/packet/mod.rs index 05f64e19..362154cc 100644 --- a/azalea-client/src/plugins/packet/mod.rs +++ b/azalea-client/src/plugins/packet/mod.rs @@ -1,4 +1,4 @@ -use azalea_entity::{EntityUpdateSet, metadata::Health}; +use azalea_entity::metadata::Health; use bevy_app::{App, First, Plugin, PreUpdate, Update}; use bevy_ecs::{ prelude::*, @@ -46,9 +46,7 @@ impl Plugin for PacketPlugin { .add_systems( PreUpdate, ( - game::process_packet_events - // we want to index and deindex right after - .before(EntityUpdateSet::Deindex), + game::process_packet_events, config::process_packet_events, login::handle_send_packet_event, login::process_packet_events, -- cgit v1.2.3