Fix invulnerability damage and armour (#12190)

This commit is contained in:
okx-code
2025-02-26 13:06:42 +00:00
committed by GitHub
parent 9421f22372
commit 0a6e7435b3
2 changed files with 14 additions and 7 deletions

View File

@@ -971,7 +971,7 @@
int i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5;
int i1 = 25 - i;
float f = damageAmount * i1;
@@ -1768,24 +_,212 @@
@@ -1768,24 +_,219 @@
}
}
@@ -984,7 +984,11 @@
+ if (invulnerabilityRelatedLastDamage == 0) return 0D; // no last damage, no reduction
+ // last damage existed, this means the reduction *technically* is (new damage - last damage).
+ // If the event damage was changed to something less than invul damage, hard lock it at 0.
+ if (d < invulnerabilityRelatedLastDamage) return 0D;
+ //
+ // Cast the passed in double down to a float as double -> float -> double is lossy.
+ // If last damage is a (float) 3.2D (since the events use doubles), we cannot compare
+ // the new damage value of this damage instance by upcasting it again to a double as 3.2D != (double) (float) 3.2D.
+ if (d.floatValue() < invulnerabilityRelatedLastDamage) return 0D;
+ return (double) -invulnerabilityRelatedLastDamage;
+ };
+ final float originalInvulnerabilityReduction = invulnerabilityReductionEquation.apply((double) amount).floatValue();
@@ -1118,7 +1122,10 @@
+
+ // Apply damage to armor
+ if (!damageSource.is(DamageTypeTags.BYPASSES_ARMOR)) {
+ float armorDamage = (float) (event.getDamage() + event.getDamage(DamageModifier.BLOCKING) + event.getDamage(DamageModifier.HARD_HAT));
+ float armorDamage = (float) event.getDamage();
+ armorDamage += (float) event.getDamage(DamageModifier.INVULNERABILITY_REDUCTION);
+ armorDamage += (float) event.getDamage(DamageModifier.BLOCKING);
+ armorDamage += (float) event.getDamage(DamageModifier.HARD_HAT);
+ this.hurtArmor(damageSource, armorDamage);
+ }
+