diff options
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> { |
