aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-client/src')
-rw-r--r--azalea-client/src/attack.rs8
-rw-r--r--azalea-client/src/entity_query.rs22
2 files changed, 21 insertions, 9 deletions
diff --git a/azalea-client/src/attack.rs b/azalea-client/src/attack.rs
index ca2ff312..644af5de 100644
--- a/azalea-client/src/attack.rs
+++ b/azalea-client/src/attack.rs
@@ -53,7 +53,13 @@ impl Client {
/// Whether the player has an attack cooldown.
pub fn has_attack_cooldown(&self) -> bool {
- let ticks_since_last_attack = *self.component::<AttackStrengthScale>();
+ let Some(AttackStrengthScale(ticks_since_last_attack)) =
+ self.get_component::<AttackStrengthScale>()
+ else {
+ // they don't even have an AttackStrengthScale so they probably can't attack
+ // lmao, just return false
+ return false;
+ };
ticks_since_last_attack < 1.0
}
}
diff --git a/azalea-client/src/entity_query.rs b/azalea-client/src/entity_query.rs
index 7b140825..484da6f8 100644
--- a/azalea-client/src/entity_query.rs
+++ b/azalea-client/src/entity_query.rs
@@ -23,10 +23,14 @@ impl Client {
/// # }
/// ```
pub fn query<'w, Q: WorldQuery>(&self, ecs: &'w mut World) -> <Q as WorldQuery>::Item<'w> {
- ecs.query::<Q>().get_mut(ecs, self.entity).expect(&format!(
- "Our client is missing a required component {:?}",
- std::any::type_name::<Q>()
- ))
+ ecs.query::<Q>()
+ .get_mut(ecs, self.entity)
+ .unwrap_or_else(|_| {
+ panic!(
+ "Our client is missing a required component {:?}",
+ std::any::type_name::<Q>()
+ )
+ })
}
/// Return a lightweight [`Entity`] for the entity that matches the given
@@ -67,10 +71,12 @@ impl Client {
pub fn entity_component<Q: Component + Clone>(&mut self, entity: Entity) -> Q {
let mut ecs = self.ecs.lock();
let mut q = ecs.query::<&Q>();
- let components = q.get(&ecs, entity).expect(&format!(
- "Entity is missing a required component {:?}",
- std::any::type_name::<Q>()
- ));
+ let components = q.get(&ecs, entity).unwrap_or_else(|_| {
+ panic!(
+ "Entity is missing a required component {:?}",
+ std::any::type_name::<Q>()
+ )
+ });
components.clone()
}