Fix incorrect invulnerability damage reduction
Fixes incorrect spigot handling of the invulnerability damage reduction applied when an already invulnerable entity is damaged with a larger damage amount than the initial damage. Vanilla still damages entities even if invulnerable if the damage to be applied is larger than the previous damage taken. In that case, vanilla applies the difference between the previous damage taken and the proposed damage. Spigot's damage modifier API takes over the computation of damage reducing effects, however spigot invokes this handling with the initial damage before computing the difference to the previous damage amount. This leads to the reduction values to generally be larger than expected, as they are computed on the not-yet-reduced value. Spigot applies these reductions after calling the EntityDamageEvent and *then* subtracts the previous damage point, leading to the final damage amount being smaller than expected. This patch cannot simply call the EntityDamageEvent with the reduced damage, as that would lead to EntityDamageEvent#getDamage() returning the already reduced damage, which breaks its method contract. Instead, this patch makes use of the DamageModifier API, implementing the last-damage-reduction as a DamageModifier.
This commit is contained in:
@@ -1218,6 +1218,11 @@ public class CraftEventFactory {
|
||||
private static final Function<? super Double, Double> ZERO = Functions.constant(-0.0);
|
||||
|
||||
public static EntityDamageEvent handleLivingEntityDamageEvent(Entity damagee, DamageSource source, double rawDamage, double freezingModifier, double hardHatModifier, double blockingModifier, double armorModifier, double resistanceModifier, double magicModifier, double absorptionModifier, Function<Double, Double> freezing, Function<Double, Double> hardHat, Function<Double, Double> blocking, Function<Double, Double> armor, Function<Double, Double> resistance, Function<Double, Double> magic, Function<Double, Double> absorption) {
|
||||
// Paper start - fix invulnerability reduction in EntityDamageEvent
|
||||
return handleLivingEntityDamageEvent(damagee, source, rawDamage, freezingModifier, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, freezing, hardHat, blocking, armor, resistance, magic, absorption, null);
|
||||
}
|
||||
public static EntityDamageEvent handleLivingEntityDamageEvent(Entity damagee, DamageSource source, double rawDamage, double freezingModifier, double hardHatModifier, double blockingModifier, double armorModifier, double resistanceModifier, double magicModifier, double absorptionModifier, Function<Double, Double> freezing, Function<Double, Double> hardHat, Function<Double, Double> blocking, Function<Double, Double> armor, Function<Double, Double> resistance, Function<Double, Double> magic, Function<Double, Double> absorption, java.util.function.BiConsumer<Map<DamageModifier, Double>, Map<DamageModifier, Function<? super Double, Double>>> callback) {
|
||||
// Paper end - fix invulnerability reduction in EntityDamageEvent
|
||||
Map<DamageModifier, Double> modifiers = new EnumMap<>(DamageModifier.class);
|
||||
Map<DamageModifier, Function<? super Double, Double>> modifierFunctions = new EnumMap<>(DamageModifier.class);
|
||||
modifiers.put(DamageModifier.BASE, rawDamage);
|
||||
@@ -1242,6 +1247,7 @@ public class CraftEventFactory {
|
||||
modifierFunctions.put(DamageModifier.MAGIC, magic);
|
||||
modifiers.put(DamageModifier.ABSORPTION, absorptionModifier);
|
||||
modifierFunctions.put(DamageModifier.ABSORPTION, absorption);
|
||||
if (callback != null) callback.accept(modifiers, modifierFunctions); // Paper - fix invulnerability reduction in EntityDamageEvent
|
||||
return CraftEventFactory.handleEntityDamageEvent(damagee, source, modifiers, modifierFunctions);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user