Merge pull request #2329 from kacpherek/fix/punch-knockback-resistance

🤖 Agent: Proven in union R1 (branch union/cg19-r1, main + 83 of kacpherek's PRs): the 98 harnesses it can affect, clippy -D warnings, tests, lan_e2e in-frame and on the server thread.
This commit is contained in:
Ludovic Marie
2026-10-27 13:32:19 +01:00
committed by GitHub
+17 -3
View File
@@ -2622,10 +2622,24 @@ impl Game<'_> {
hurt
}
};
// doKnockback: Punch pushes along the flight.
// doKnockback: Punch pushes along the flight, less the target's
// knockback resistance.
let flight = (p.velocity.x * p.velocity.x + p.velocity.z * p.velocity.z).sqrt();
if hurt && p.bonus.punch > 0 && flight > 1e-6 {
let k = f64::from(p.bonus.punch) * 0.6 / flight;
let resistance = match who {
Who::Player => self
.player
.as_mut()
.and_then(|pl| pl.attribute("minecraft:knockback_resistance").ok())
.unwrap_or(0.0),
Who::Mob(id) => self
.mobs
.iter()
.find(|m| m.id == id)
.map_or(0.0, |m| m.attrs.knockback_resistance),
};
let push = f64::from(p.bonus.punch) * 0.6 * (1.0 - resistance).max(0.0);
if hurt && push > 0.0 && flight > 1e-6 {
let k = push / flight;
self.handle_mob_events(vec![MobEvent::Push {
target: who,
velocity: [p.velocity.x * k, 0.1, p.velocity.z * k],