diff --git a/azalea-client/src/plugins/attack.rs b/azalea-client/src/plugins/attack.rs index cac2a021..2409dacc 100644 --- a/azalea-client/src/plugins/attack.rs +++ b/azalea-client/src/plugins/attack.rs @@ -53,15 +53,33 @@ impl Client { } /// Whether the player has an attack cooldown. + /// + /// Also see [`Client::attack_cooldown_remaining_ticks`]. pub fn has_attack_cooldown(&self) -> bool { - let Some(AttackStrengthScale(ticks_since_last_attack)) = - self.get_component::() - else { - // they don't even have an AttackStrengthScale so they probably can't attack - // lmao, just return false + let Some(attack_strength_scale) = self.get_component::() else { + // they don't even have an AttackStrengthScale so they probably can't even + // attack? whatever, just return false return false; }; - ticks_since_last_attack < 1.0 + *attack_strength_scale < 1.0 + } + + /// Returns the number of ticks until we can attack at full strength again. + /// + /// Also see [`Client::has_attack_cooldown`]. + pub fn attack_cooldown_remaining_ticks(&self) -> usize { + let mut ecs = self.ecs.lock(); + let Ok((attributes, ticks_since_last_attack)) = ecs + .query::<(&Attributes, &TicksSinceLastAttack)>() + .get(&ecs, self.entity) + else { + return 0; + }; + + let attack_strength_delay = get_attack_strength_delay(attributes); + let remaining_ticks = attack_strength_delay - **ticks_since_last_attack as f32; + + remaining_ticks.max(0.).ceil() as usize } } diff --git a/azalea-entity/src/lib.rs b/azalea-entity/src/lib.rs index 7b971c27..0058708f 100644 --- a/azalea-entity/src/lib.rs +++ b/azalea-entity/src/lib.rs @@ -253,9 +253,11 @@ impl Eq for LookDirection {} /// bounding box. #[derive(Debug, Component, Clone, Default)] pub struct Physics { - /// How fast the entity is moving. + /// How fast the entity is moving. Sometimes referred to as the delta + /// movement. /// - /// Sometimes referred to as the delta movement. + /// Note that our Y velocity will be approximately -0.0784 when we're on the + /// ground due to how Minecraft applies gravity. pub velocity: Vec3, pub vec_delta_codec: VecDeltaCodec,