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 <id>.<level>, 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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(),
|
||||
));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user