From 9d96bb6ec7352a885889b88e7a4922092d5e9b69 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Wed, 21 Oct 2026 20:13:42 +0200 Subject: [PATCH] Explosions: knockback reads explosion_knockback_resistance; armor enchantment modifiers stack per slot Two Blast Protection pieces now cancel explosion knockback (#1049): - ServerExplosion.hurtEntities scales knockback by EXPLOSION_KNOCKBACK_RESISTANCE for living entities. The player's knockback ignored it, and mobs used KNOCKBACK_RESISTANCE (iron golems were never pushed; vanilla pushes them, every type's explosion resistance base is 0). - EnchantmentAttributeEffect.idForSlot: the modifier id ends with the slot, so the same enchantment on two armor pieces adds up. The id was ., so the second piece replaced the first. - hitPlayers skips creative players who are flying: no knockback for them. Fixes #1049 Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/enchant.rs | 2 +- .../src/game/enchant_effects.rs | 9 +++++-- crates/horizon-client/src/game/explosion.rs | 25 +++++++++++++------ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/crates/horizon-client/src/enchant.rs b/crates/horizon-client/src/enchant.rs index 86bdbe562..a988eeb55 100644 --- a/crates/horizon-client/src/enchant.rs +++ b/crates/horizon-client/src/enchant.rs @@ -536,7 +536,7 @@ impl Enchantments { { out.push(( a["attribute"].as_str().unwrap_or("").to_owned(), - format!("{}.{}", a["id"].as_str().unwrap_or(""), level), + a["id"].as_str().unwrap_or("").to_owned(), f64::from(level_value(&a["amount"], *level)), a["operation"].as_str().unwrap_or("add_value").to_owned(), )); diff --git a/crates/horizon-client/src/game/enchant_effects.rs b/crates/horizon-client/src/game/enchant_effects.rs index 0aa3138f6..36f7ad783 100644 --- a/crates/horizon-client/src/game/enchant_effects.rs +++ b/crates/horizon-client/src/game/enchant_effects.rs @@ -433,10 +433,15 @@ impl Game<'_> { ignite } /// Enchantment attribute modifiers of worn armor (respiration, depth strider...). + /// Each piece's modifier id ends with its slot (`EnchantmentAttributeEffect.idForSlot`), + /// so the same enchantment on two pieces stacks instead of replacing itself. pub(super) fn apply_enchantment_attributes(&mut self) { let mut wanted: Vec<(String, String, f64, String)> = Vec::new(); - for stack in self.armor.iter().flatten() { - wanted.extend(self.res.stations().enchantments.attributes(stack)); + for (stack, slot) in self.armor.iter().zip(["head", "chest", "legs", "feet"]) { + let Some(stack) = stack else { continue }; + for (attr, id, amount, op) in self.res.stations().enchantments.attributes(stack) { + wanted.push((attr, format!("{id}/{slot}"), amount, op)); + } } let Some(p) = self.player.as_mut() else { return; diff --git a/crates/horizon-client/src/game/explosion.rs b/crates/horizon-client/src/game/explosion.rs index c6df8d9e2..55babd9af 100644 --- a/crates/horizon-client/src/game/explosion.rs +++ b/crates/horizon-client/src/game/explosion.rs @@ -281,7 +281,6 @@ impl Game<'_> { ); let amount = damage(dist, exposure); let dir = direction(eye); - let power = (1.0 - dist) * f64::from(exposure); let mut hurt = false; let creative = self.creative; if let Some(p) = self.player.as_mut() @@ -293,11 +292,21 @@ impl Game<'_> { .hurt(&self.motion.health, self.world.health_rules, id, amount) .unwrap_or(false); } - p.velocity = Vec3::new( - p.velocity.x + dir[0] * power, - p.velocity.y + dir[1] * power, - p.velocity.z + dir[2] * power, - ); + // Blast protection: `EXPLOSION_KNOCKBACK_RESISTANCE` (0.15 per + // level and piece, so two Blast Protection IV pieces cancel it). + let resistance = p + .attribute("minecraft:explosion_knockback_resistance") + .unwrap_or(0.0); + let power = (1.0 - dist) * f64::from(exposure) * (1.0 - resistance); + // `hitPlayers` skips creative players who are flying: the + // client gets no knockback in the explode packet. + if !(creative && p.flying) { + p.velocity = Vec3::new( + p.velocity.x + dir[0] * power, + p.velocity.y + dir[1] * power, + p.velocity.z + dir[2] * power, + ); + } } if hurt && !self.creative { self.hurt_armor(amount); @@ -328,8 +337,10 @@ impl Game<'_> { if hurtable && !m.damage(damage(dist, exposure), source) { continue; } + // `EXPLOSION_KNOCKBACK_RESISTANCE`, not `KNOCKBACK_RESISTANCE`: its + // base is 0 for every mob type, so iron golems and ravagers are pushed. let dir = direction(eye); - let power = (1.0 - dist) * f64::from(exposure) * (1.0 - m.kind.knockback_resistance); + let power = (1.0 - dist) * f64::from(exposure); m.velocity = Vec3::new( m.velocity.x + dir[0] * power, m.velocity.y + dir[1] * power,