diff options
| author | mat <git@matdoes.dev> | 2025-03-06 04:11:05 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-03-06 04:11:19 +0000 |
| commit | cf66c4be100c898c64d57f9b92f31f809764dc2e (patch) | |
| tree | 9c093621b36e6372a094fc0e128a758bf76e25c7 /azalea-client/src | |
| parent | c9022e8f671b5838f4d4ab446013c42191b07f37 (diff) | |
| download | azalea-drasl-cf66c4be100c898c64d57f9b92f31f809764dc2e.tar.xz | |
fix despawning entities on dimension change
Diffstat (limited to 'azalea-client/src')
| -rw-r--r-- | azalea-client/src/plugins/packet/game/mod.rs | 47 |
1 files changed, 33 insertions, 14 deletions
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<LocalEntity>, + >, EventWriter<InstanceLoadedEvent>, ResMut<InstanceContainer>, ResMut<EntityUuidIndex>, EventWriter<SendPacketEvent>, + Query<&mut LoadedBy, Without<LocalEntity>>, )>( 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<LocalEntity>, + >, EventWriter<_>, ResMut<InstanceContainer>, + Query<&mut LoadedBy, Without<LocalEntity>>, )>( 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, |
