diff options
| author | mat <git@matdoes.dev> | 2025-02-21 22:50:19 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-02-21 22:50:39 +0000 |
| commit | 27945c8870c832970dfe15b9bf9f567c0ad96ea4 (patch) | |
| tree | 08c6598d52ac379505ec556ffb7d40aec5dcb3d8 /azalea-client/src | |
| parent | f5f15362f2cb48088eb8ccf80988f994fecd81c9 (diff) | |
| download | azalea-drasl-27945c8870c832970dfe15b9bf9f567c0ad96ea4.tar.xz | |
despawn entities when switching worlds and some testbot fixes
Diffstat (limited to 'azalea-client/src')
| -rw-r--r-- | azalea-client/src/client.rs | 5 | ||||
| -rw-r--r-- | azalea-client/src/disconnect.rs | 8 |
2 files changed, 13 insertions, 0 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index c81f6f28..131aef16 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -555,6 +555,11 @@ impl Client { self.query::<Option<&T>>(&mut self.ecs.lock()).cloned() } + /// Get a resource from the ECS. This will clone the resource and return it. + pub fn resource<T: Resource + Clone>(&self) -> T { + self.ecs.lock().resource::<T>().clone() + } + /// Get a required component for this client and call the given function. /// /// Similar to [`Self::component`], but doesn't clone the component since diff --git a/azalea-client/src/disconnect.rs b/azalea-client/src/disconnect.rs index a92423d7..c653e195 100644 --- a/azalea-client/src/disconnect.rs +++ b/azalea-client/src/disconnect.rs @@ -47,6 +47,7 @@ pub struct DisconnectEvent { pub fn remove_components_from_disconnected_players( mut commands: Commands, mut events: EventReader<DisconnectEvent>, + mut loaded_by_query: Query<&mut azalea_entity::LoadedBy>, ) { for DisconnectEvent { entity, .. } in events.read() { trace!("Got DisconnectEvent for {entity:?}"); @@ -62,6 +63,13 @@ pub fn remove_components_from_disconnected_players( .remove::<LocalPlayerEvents>(); // note that we don't remove the client from the ECS, so if they decide // to reconnect they'll keep their state + + // now we have to remove ourselves from the LoadedBy for every entity. + // in theory this could be inefficient if we have massive swarms... but in + // practice this is fine. + for mut loaded_by in &mut loaded_by_query.iter_mut() { + loaded_by.remove(entity); + } } } |
