Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
lynxplay committed Nov 11, 2024
1 parent f6620d5 commit aec70d4
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ Subject: [PATCH] Fix invulnerability reduction in EntityDamageEvent


diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index e86314de8d908a0c3e9f17d3e163c11180cf3f59..84d84687c32ad6580c2fcd0730c597fc8ce90b9f 100644
index e86314de8d908a0c3e9f17d3e163c11180cf3f59..c3d50a8448e95e3eccb494d8a678554d52f6ec72 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -1505,12 +1505,12 @@ public abstract class LivingEntity extends Entity implements Attackable {
}

// Paper start - only call damage event when actuallyHurt will be called - move call logic down
- event = this.handleEntityDamage(source, amount);
+ event = this.handleEntityDamage(source, amount, this.lastHurt); // Paper - fix invulnerability reduction in EntityDamageEvent
+ event = this.handleEntityDamage(source, amount, this.lastHurt); // Paper - fix invulnerability reduction in EntityDamageEvent - pass lastDamage reduction
amount = computeAmountFromEntityDamageEvent(event);
// Paper end - only call damage event when actuallyHurt will be called - move call logic down

// CraftBukkit start
- if (!this.actuallyHurt(world, source, (float) event.getFinalDamage() - this.lastHurt, event)) {
+ if (!this.actuallyHurt(world, source, (float) event.getFinalDamage(), event)) {
+ if (!this.actuallyHurt(world, source, (float) event.getFinalDamage(), event)) { // Paper - fix invulnerability reduction in EntityDamageEvent - no longer subtract lastHurt, that is part of the damage event calc now
return false;
}
if (this instanceof ServerPlayer && event.getDamage() == 0 && originalAmount == 0) return false; // Paper - revert to vanilla damage - players are not affected by damage that is 0 - skip damage if the vanilla damage is 0 and was not modified by plugins in the event.
Expand All @@ -28,7 +28,7 @@ index e86314de8d908a0c3e9f17d3e163c11180cf3f59..84d84687c32ad6580c2fcd0730c597fc
} else {
// Paper start - only call damage event when actuallyHurt will be called - move call logic down
- event = this.handleEntityDamage(source, amount);
+ event = this.handleEntityDamage(source, amount, 0); // Paper - fix invulnerability reduction in EntityDamageEvent
+ event = this.handleEntityDamage(source, amount, 0); // Paper - fix invulnerability reduction in EntityDamageEvent - pass lastDamage reduction (none in this branch)
amount = computeAmountFromEntityDamageEvent(event);
// Paper end - only call damage event when actuallyHurt will be called - move call logic down
// CraftBukkit start
Expand All @@ -40,14 +40,14 @@ index e86314de8d908a0c3e9f17d3e163c11180cf3f59..84d84687c32ad6580c2fcd0730c597fc
+ private EntityDamageEvent handleEntityDamage(final DamageSource damagesource, float f, final float invulnerabilityRelatedLastDamage) { // Paper - fix invulnerability reduction in EntityDamageEvent
float originalDamage = f;
+ // Paper start - fix invulnerability reduction in EntityDamageEvent
+ final com.google.common.base.Function<Double, Double> invulnerabilityReductionFormular = d -> {
+ final com.google.common.base.Function<Double, Double> invulnerabilityReductionEquation = d -> {
+ 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;
+ return (double) -invulnerabilityRelatedLastDamage;
+ };
+ final float originalInvulnerabilityReduction = invulnerabilityReductionFormular.apply((double) f).floatValue();
+ final float originalInvulnerabilityReduction = invulnerabilityReductionEquation.apply((double) f).floatValue();
+ f += originalInvulnerabilityReduction;
+ // Paper end - fix invulnerability reduction in EntityDamageEvent

Expand All @@ -60,7 +60,7 @@ index e86314de8d908a0c3e9f17d3e163c11180cf3f59..84d84687c32ad6580c2fcd0730c597fc
- return CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, freezingModifier, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, freezing, hardHat, blocking, armor, resistance, magic, absorption);
+ // Paper start - fix invulnerability reduction in EntityDamageEvent
+ return CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, freezingModifier, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, freezing, hardHat, blocking, armor, resistance, magic, absorption, (damageModifierDoubleMap, damageModifierFunctionMap) -> {
+ damageModifierFunctionMap.put(DamageModifier.INVULNERABILITY_REDUCTION, invulnerabilityReductionFormular);
+ damageModifierFunctionMap.put(DamageModifier.INVULNERABILITY_REDUCTION, invulnerabilityReductionEquation);
+ damageModifierDoubleMap.put(DamageModifier.INVULNERABILITY_REDUCTION, (double) originalInvulnerabilityReduction);
+ });
+ // Paper end - fix invulnerability reduction in EntityDamageEvent
Expand Down

0 comments on commit aec70d4

Please sign in to comment.