diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-08-24 22:59:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-24 22:59:40 -0500 |
| commit | 11d14c74c53c07231c8ca33b622380df99bf9a59 (patch) | |
| tree | ea1d0c61a6d5f8af550a708ff3b71fbbaed5d122 /azalea-client/src/entity_query.rs | |
| parent | 57e5a0f0b96a38674bd18ac38d2d07e4f4ca2fd6 (diff) | |
| download | azalea-drasl-11d14c74c53c07231c8ca33b622380df99bf9a59.tar.xz | |
Support properly switching instances (#106)
* start implementing switching dimensions
* fix removeentity in shared worlds
* also store entity ids per local player
* uncomment a trace in pathfinder
* cleanup
---------
Co-authored-by: mat <git@matdoes.dev>
Diffstat (limited to 'azalea-client/src/entity_query.rs')
| -rw-r--r-- | azalea-client/src/entity_query.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/azalea-client/src/entity_query.rs b/azalea-client/src/entity_query.rs index d3fa522b..ca41c872 100644 --- a/azalea-client/src/entity_query.rs +++ b/azalea-client/src/entity_query.rs @@ -71,6 +71,16 @@ impl Client { .expect("Entity components must be present in Client::entity)components."); components.clone() } + + /// Get a component from an entity, if it exists. This is similar to + /// [`Self::entity_component`] but returns an `Option` instead of panicking + /// if the component isn't present. + pub fn get_entity_component<Q: Component + Clone>(&mut self, entity: Entity) -> Option<Q> { + let mut ecs = self.ecs.lock(); + let mut q = ecs.query::<&Q>(); + let components = q.get(&ecs, entity).ok(); + components.cloned() + } } pub trait EntityPredicate<Q: ReadOnlyWorldQuery, Filter: ReadOnlyWorldQuery> { |
