From cf66c4be100c898c64d57f9b92f31f809764dc2e Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 6 Mar 2025 04:11:05 +0000 Subject: fix despawning entities on dimension change --- azalea-client/src/plugins/packet/game/mod.rs | 47 +++++++++++++++++++--------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'azalea-client/src/plugins/packet') diff --git a/azalea-client/src/plugins/packet/game/mod.rs b/azalea-client/src/plugins/packet/game/mod.rs index c3381e59..a13f1490 100644 --- a/azalea-client/src/plugins/packet/game/mod.rs +++ b/azalea-client/src/plugins/packet/game/mod.rs @@ -207,18 +207,22 @@ impl GamePacketHandler<'_> { as_system::<( Commands, - Query<( - &GameProfileComponent, - &ClientInformation, - Option<&mut InstanceName>, - Option<&mut LoadedBy>, - &mut EntityIdIndex, - &mut InstanceHolder, - )>, + Query< + ( + &GameProfileComponent, + &ClientInformation, + Option<&mut InstanceName>, + Option<&mut LoadedBy>, + &mut EntityIdIndex, + &mut InstanceHolder, + ), + With, + >, EventWriter, ResMut, ResMut, EventWriter, + Query<&mut LoadedBy, Without>, )>( self.ecs, |( @@ -228,6 +232,7 @@ impl GamePacketHandler<'_> { mut instance_container, mut entity_uuid_index, mut send_packet_events, + mut loaded_by_query, )| { let ( game_profile, @@ -317,6 +322,11 @@ impl GamePacketHandler<'_> { &mut instance_holder.instance.write(), ); + // every entity is now unloaded by this player + for mut loaded_by in &mut loaded_by_query.iter_mut() { + loaded_by.remove(&self.player); + } + // update or insert loaded_by if let Some(mut loaded_by) = loaded_by { loaded_by.insert(self.player); @@ -1413,16 +1423,20 @@ impl GamePacketHandler<'_> { as_system::<( Commands, - Query<( - &mut InstanceHolder, - &GameProfileComponent, - &ClientInformation, - )>, + Query< + ( + &mut InstanceHolder, + &GameProfileComponent, + &ClientInformation, + ), + With, + >, EventWriter<_>, ResMut, + Query<&mut LoadedBy, Without>, )>( self.ecs, - |(mut commands, mut query, mut events, mut instance_container)| { + |(mut commands, mut query, mut events, mut instance_container, mut loaded_by_query)| { let (mut instance_holder, game_profile, client_information) = query.get_mut(self.player).unwrap(); @@ -1461,6 +1475,11 @@ impl GamePacketHandler<'_> { ); instance_holder.instance = weak_instance; + // every entity is now unloaded by this player + for mut loaded_by in &mut loaded_by_query.iter_mut() { + loaded_by.remove(&self.player); + } + // this resets a bunch of our components like physics and stuff let entity_bundle = EntityBundle::new( game_profile.uuid, -- cgit v1.2.3