Merge pull request #1101 from ludovic111/fix/explosion-knockback-resistance

🤖 Agent: merged. Verify passes. Local integration of #1101–#1107 on main caeffffb: parity --changed 302/304, and the two failures (block_particles, entity_model) fail identically on plain main. CI parity's secure_chat failure on #1101 logged 'transcripts identical' (flaky).
This commit is contained in:
Ludovic Marie
2026-10-22 00:17:41 +02:00
committed by GitHub
3 changed files with 26 additions and 10 deletions
+1 -1
View File
@@ -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(),
));
@@ -448,10 +448,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;
+18 -7
View File
@@ -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,