Include equipment modifiers in a mob's knockback resistance for the sonic boom push
This commit is contained in:
@@ -993,7 +993,7 @@ impl Game<'_> {
|
||||
.mobs
|
||||
.iter()
|
||||
.find(|m| m.id == id)
|
||||
.map_or(0.0, |m| m.attrs.knockback_resistance);
|
||||
.map_or(0.0, |m| self.mob_knockback_resistance(m));
|
||||
(hurt, resistance)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -24,6 +24,37 @@ fn slot_in_group(group: &str, slot: &str) -> bool {
|
||||
}
|
||||
|
||||
impl Game<'_> {
|
||||
/// `getAttributeValue(KNOCKBACK_RESISTANCE)` of a mob: its own value plus
|
||||
/// the modifiers of the items it wears or holds in matching slots.
|
||||
pub(super) fn mob_knockback_resistance(&self, m: &Mob) -> f64 {
|
||||
let e = &m.extra;
|
||||
let slots = [
|
||||
("mainhand", &e.main_hand),
|
||||
("offhand", &e.off_hand),
|
||||
("feet", &e.feet),
|
||||
("legs", &e.legs),
|
||||
("chest", &e.chest),
|
||||
("head", &e.head),
|
||||
];
|
||||
let mut extra = Vec::new();
|
||||
for (slot, item) in slots {
|
||||
let Some(info) = item.as_ref().and_then(|i| self.res.items().get(i)) else {
|
||||
continue;
|
||||
};
|
||||
for (attribute, _, amount, op, group) in &info.modifiers {
|
||||
if attribute == "minecraft:knockback_resistance" && slot_in_group(group, slot) {
|
||||
let op = match operation_named(op) {
|
||||
1 => Op::AddMultipliedBase,
|
||||
2 => Op::AddMultipliedTotal,
|
||||
_ => Op::AddValue,
|
||||
};
|
||||
extra.push((*amount, op));
|
||||
}
|
||||
}
|
||||
}
|
||||
finalize::value_with(m, Attr::KnockbackResistance, &extra)
|
||||
}
|
||||
|
||||
/// The registry id of a client-syncable attribute the entity type has
|
||||
/// (`AttributeMap.getInstance` is null for the others), by name.
|
||||
fn synced_attribute(&self, entity: &str, name: &str) -> Option<i32> {
|
||||
|
||||
@@ -516,9 +516,13 @@ fn effect_modifiers(m: &Mob, a: Attr) -> impl Iterator<Item = (f64, Op)> + '_ {
|
||||
}
|
||||
/// `AttributeInstance.getValue`: the base, then the modifiers by operation.
|
||||
pub fn value(m: &Mob, a: Attr) -> f64 {
|
||||
compute(m, a, true)
|
||||
compute(m, a, true, &[])
|
||||
}
|
||||
fn compute(m: &Mob, a: Attr, with_transient: bool) -> f64 {
|
||||
/// `value` with more modifiers, such as the ones worn equipment grants.
|
||||
pub fn value_with(m: &Mob, a: Attr, extra: &[(f64, Op)]) -> f64 {
|
||||
compute(m, a, true, extra)
|
||||
}
|
||||
fn compute(m: &Mob, a: Attr, with_transient: bool, extra: &[(f64, Op)]) -> f64 {
|
||||
let mut base = base_value(m, a);
|
||||
let empty = Vec::new();
|
||||
let mods = m.extra.attributes.as_ref().map_or(&empty, |s| &s.modifiers);
|
||||
@@ -531,6 +535,7 @@ fn compute(m: &Mob, a: Attr, with_transient: bool) -> f64 {
|
||||
ops.extend(transient(m, a));
|
||||
ops.extend(effect_modifiers(m, a));
|
||||
}
|
||||
ops.extend(extra.iter().copied());
|
||||
for (amount, op) in &ops {
|
||||
if *op == Op::AddValue {
|
||||
base += amount;
|
||||
@@ -573,7 +578,7 @@ fn refresh(m: &mut Mob, a: Attr) {
|
||||
/// The value without the transient baby modifier (`speed_bonus` applies
|
||||
/// that one to movement speed).
|
||||
fn base_with_modifiers(m: &Mob, a: Attr) -> f64 {
|
||||
compute(m, a, false)
|
||||
compute(m, a, false, &[])
|
||||
}
|
||||
/// `AttributeInstance.setBaseValue`.
|
||||
pub fn set_base(m: &mut Mob, a: Attr, v: f64) {
|
||||
|
||||
Reference in New Issue
Block a user