From 1131a2910ddc732a65011d789875cf6d25497090 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Tue, 27 Oct 2026 06:24:43 +0100 Subject: [PATCH] Apply Haste and Mining Fatigue to the attack speed --- crates/horizon-client/src/game.rs | 3 +-- crates/horizon-client/src/game/dragon.rs | 11 ++++------- crates/horizon-client/src/game/hand.rs | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 7699e83d7..30c8e5b41 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -7863,8 +7863,7 @@ impl Game<'_> { } /// `Player.getAttackStrengthScale(0.5)`. fn attack_strength_scale(&self) -> f32 { - let speed = self.attack_item_info().map_or(0.0, |i| i.attack_speed); - let delay = 20.0 / (4.0 + speed).max(0.1); + let delay = horizon_client::attack_strength::delay(self.main_hand_attack_speed()); ((self.attack_ticks as f32 + 0.5) / delay).clamp(0.0, 1.0) } /// `Player.isSweepAttack`: a charged, grounded sword hit below the movement limit. diff --git a/crates/horizon-client/src/game/dragon.rs b/crates/horizon-client/src/game/dragon.rs index 8f3fdb224..5d8208f5a 100644 --- a/crates/horizon-client/src/game/dragon.rs +++ b/crates/horizon-client/src/game/dragon.rs @@ -1031,14 +1031,11 @@ impl Game<'_> { if !self.before_block(d) || self.mob_hit().is_some_and(|m| m.1 < d) { return false; } - let modifiers = self - .attack_item_info() - .map(|i| (i.attack_damage, i.attack_speed)) - .unwrap_or((0.0, 0.0)); - let speed = (4.0 + modifiers.1).max(0.1); - let scale = ((self.attack_ticks as f32 + 0.5) / (20.0 / speed)).clamp(0.0, 1.0); + let hand_damage = self.attack_item_info().map_or(0.0, |i| i.attack_damage); + let delay = horizon_client::attack_strength::delay(self.main_hand_attack_speed()); + let scale = ((self.attack_ticks as f32 + 0.5) / delay).clamp(0.0, 1.0); let mut amount = - (1.0 + modifiers.0 + self.effect_attack_bonus()) * (0.2 + scale * scale * 0.8); + (1.0 + hand_damage + self.effect_attack_bonus()) * (0.2 + scale * scale * 0.8); let falling = self .player .as_ref() diff --git a/crates/horizon-client/src/game/hand.rs b/crates/horizon-client/src/game/hand.rs index d91d3b979..210e62ac5 100644 --- a/crates/horizon-client/src/game/hand.rs +++ b/crates/horizon-client/src/game/hand.rs @@ -289,12 +289,21 @@ impl Game<'_> { // Only alive mobs are hit, so a picked living entity is alive. Some(true) } - /// `Attributes.ATTACK_SPEED` with the main-hand item's modifier. + /// `Attributes.ATTACK_SPEED` with the main-hand item's modifier and the + /// Haste and Mining Fatigue modifiers (`ADD_MULTIPLIED_TOTAL`), clamped to + /// the attribute's range. pub(super) fn main_hand_attack_speed(&self) -> f64 { - horizon_client::attack_strength::BASE_ATTACK_SPEED + let value = horizon_client::attack_strength::BASE_ATTACK_SPEED + self .attack_item_info() - .map_or(0.0, |i| f64::from(i.attack_speed)) + .map_or(0.0, |i| f64::from(i.attack_speed)); + self.potions + .effects + .modifiers() + .into_iter() + .filter(|m| m.0 == "minecraft:attack_speed") + .fold(value, |v, m| v * (1.0 + m.2)) + .clamp(0.0, 1024.0) } /// The item whose attack damage and speed modifiers the player has (`attack_item`). pub(super) fn attack_item_info(&self) -> Option<&horizon_client::items::ItemInfo> {