From 6a5c749f7cfebcb800dd17c0c2cffb01fcc9d7cd Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 24 Oct 2026 11:13:27 +0200 Subject: [PATCH] Aim extra knockback with Mth's sine table Player.causeExtraKnockback pushes along Mth.sin/Mth.cos of the attacker's yaw, which come from vanilla's 65536-entry table: facing east, the push has no z at all. Horizon took f32 sin/cos, which left -4.4e-8 of z per block of push (a sprinting or Knockback hit, on mobs and players). Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/enchant_effects.rs | 10 ++++++---- tools/test_server_knockback_parity.py | 5 ----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/crates/horizon-client/src/game/enchant_effects.rs b/crates/horizon-client/src/game/enchant_effects.rs index 8593e2b98..aa9f75e06 100644 --- a/crates/horizon-client/src/game/enchant_effects.rs +++ b/crates/horizon-client/src/game/enchant_effects.rs @@ -121,11 +121,13 @@ impl Game<'_> { let bonus = if knockback_attack { 0.5 } else { 0.0 }; (enchanted / 2.0 + bonus, knockback_attack) } - /// `causeExtraKnockback`'s direction, `(sin yRot, -cos yRot)`: the target - /// flies where the attacker looks, not away from it. + /// `causeExtraKnockback`'s direction, `(sin yRot, -cos yRot)` from Mth's + /// sine table: the target flies where the attacker looks, not away from + /// it (straight along an axis when the attacker faces one). pub(super) fn extra_knockback_direction(&self) -> (f64, f64) { - let yaw = self.yaw.to_radians(); - (f64::from(yaw.sin()), -f64::from(yaw.cos())) + use horizon_core::geometry::trig; + let yaw = f64::from(self.yaw * trig::DEG_TO_RAD); + (f64::from(trig::sin(yaw)), -f64::from(trig::cos(yaw))) } /// The attacker's side of `causeExtraKnockback` as the attacking client /// sees it: the server's player stops sprinting, and its flag reaches the diff --git a/tools/test_server_knockback_parity.py b/tools/test_server_knockback_parity.py index c6c634c0f..d7fbaeba1 100644 --- a/tools/test_server_knockback_parity.py +++ b/tools/test_server_knockback_parity.py @@ -56,12 +56,7 @@ PROPERTIES = { 'pause-when-empty-seconds': '-1', } # Cases Horizon still gets wrong, and why. -YAW = "the extra knockback's direction comes from f32 sin/cos, not Mth's sine table (z is -2e-8 a block, not 0)" KNOWN = { - 'cow-sprint': YAW, - 'cow-knockback-2': YAW, - 'zombie-sprint': YAW, - 'zombie-knockback-2': YAW, 'pvp-mace': "a smash on a player runs none of MaceItem.hurtEnemy (the attacker's fall goes on)", }