aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/plugins
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-11 02:55:30 -0530
committermat <git@matdoes.dev>2025-06-11 02:55:30 -0530
commitab05e7bdae43de3595718fee877c0fbcc6368555 (patch)
treed9f4312eeb4c1401d4772c901338ba57bf733838 /azalea-client/src/plugins
parent9b0bd29db4faa9d94df0cec472346b814e7efcb9 (diff)
downloadazalea-drasl-ab05e7bdae43de3595718fee877c0fbcc6368555.tar.xz
add Client::attack_cooldown_remaining_ticks
Diffstat (limited to 'azalea-client/src/plugins')
-rw-r--r--azalea-client/src/plugins/attack.rs30
1 files changed, 24 insertions, 6 deletions
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::<AttackStrengthScale>()
- 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::<AttackStrengthScale>() 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
}
}