Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.
Rust differential-testinggame-enginegamedevlinuxminecraftminecraft-javareimplementationrustvoxelvulkanwgpu
The native knockback hook runs on the raw strength, before the knockback resistance
Federico Taglianic305aac57a04
diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rsindex f585397b5..c03463fbf 100644--- a/crates/horizon-client/src/game/creatures.rs+++ b/crates/horizon-client/src/game/creatures.rs@@ -6835,8 +6835,10 @@ fn knock_back(source: HurtSource<'_>,) {let resistance = p.attribute("minecraft:knockback_resistance").unwrap_or(0.0);+ // The native hook runs first, on the raw strength (`LivingKnockBackEvent`), then the+ // resistance scales what it left.let mut knock = Knock {- strength: power * (1.0 - resistance),+ strength: power,x: xd,z: zd,};@@ -6848,6 +6850,7 @@ fn knock_back(x: mut xd,z: mut zd,} = knock;+ let power = power * (1.0 - resistance);if power <= 0.0 {return;}diff --git a/crates/horizon-client/src/health.rs b/crates/horizon-client/src/health.rsindex e4be44d09..6b6349302 100644--- a/crates/horizon-client/src/health.rs+++ b/crates/horizon-client/src/health.rs@@ -64,8 +64,9 @@ pub struct Knock {pub z: f64,}/// The game's native knockback hook (`native_living_knockback`), set once by-/// the game: `LivingEntity.knockback`, after the knockback resistance and-/// before the motion changes. It may change the [`Knock`]; true cancels it.+/// the game: `LivingEntity.knockback`, at its start (`LivingKnockBackEvent`), on the raw strength+/// and before the knockback resistance and the motion change. It may change the [`Knock`]; true+/// cancels it.pub static KNOCKBACK: OnceLock<fn(Hurting<'_>, &mut Knock) -> bool> = OnceLock::new();/// Whether [`KNOCKBACK`] canceled the knockback (never while it is unset). A/// value it leaves that is not a finite number is put back as it was.diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rsindex d1d9b541b..8fd5bc23b 100644--- a/crates/horizon-client/src/mobs.rs+++ b/crates/horizon-client/src/mobs.rs@@ -3052,8 +3052,10 @@ impl Mob {if creaking::is_creaking(self) && !creaking::can_move(self) {return;}+ // The native hook runs first, on the raw strength (NeoForge's `LivingKnockBackEvent` fires+ // at the start of `LivingEntity.knockback`), then the resistance scales what it left.let mut knock = crate::health::Knock {- strength: power * (1.0 - self.attrs.knockback_resistance),+ strength: power,x: xd,z: zd,};@@ -3066,6 +3068,7 @@ impl Mob {x: mut xd,z: mut zd,} = knock;+ let power = power * (1.0 - self.attrs.knockback_resistance);if power <= 0.0 {return;}