Skip to content

Commit 220b57a

Browse files
authored
Fixs and Improvements for EndermanEscapeEvent (#12570)
1 parent 7774243 commit 220b57a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

paper-api/src/main/java/com/destroystokyo/paper/event/entity/EndermanEscapeEvent.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public Enderman getEntity() {
2727
}
2828

2929
/**
30-
* @return The reason the enderman is trying to escape
30+
* Gets the reason the enderman is trying to escape.
31+
*
32+
* @return The reason
3133
*/
3234
public Reason getReason() {
3335
return this.reason;
@@ -42,7 +44,8 @@ public boolean isCancelled() {
4244
* Cancels the escape.
4345
* <p>
4446
* If this escape normally had resulted in damage avoidance such as indirect,
45-
* the enderman will now take damage.
47+
* the enderman will now take damage. However, this does not change the Enderman's
48+
* innate immunities or damage behavior like arrows where the damage never happens.
4649
*/
4750
@Override
4851
public void setCancelled(final boolean cancel) {
@@ -76,7 +79,7 @@ public enum Reason {
7679
*/
7780
STARE,
7881
/**
79-
* Specific case for {@link #CRITICAL_HIT} where the enderman is taking rain damage
82+
* Specific case for {@link #CRITICAL_HIT} where the enderman is taking damage by drowning (ex: rain)
8083
*/
8184
DROWN
8285
}

paper-server/patches/sources/net/minecraft/world/entity/monster/EnderMan.java.patch

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,20 @@
5656
this.setTarget(null);
5757
this.teleport();
5858
}
59-
@@ -369,11 +_,13 @@
59+
@@ -359,21 +_,25 @@
60+
AbstractThrownPotion abstractThrownPotion1 = damageSource.getDirectEntity() instanceof AbstractThrownPotion abstractThrownPotion
61+
? abstractThrownPotion
62+
: null;
63+
- if (!damageSource.is(DamageTypeTags.IS_PROJECTILE) && abstractThrownPotion1 == null) {
64+
+ if (!damageSource.is(DamageTypeTags.IS_PROJECTILE) && abstractThrownPotion1 == null) { // Paper - EndermanEscapeEvent - diff on change - below logic relies on this path covering non-projectile damage.
65+
boolean flag = super.hurtServer(level, damageSource, amount);
66+
if (!(damageSource.getEntity() instanceof LivingEntity) && this.random.nextInt(10) != 0) {
67+
+ if (this.tryEscape(damageSource.is(net.minecraft.tags.DamageTypeTags.IS_DROWNING) ? com.destroystokyo.paper.event.entity.EndermanEscapeEvent.Reason.DROWN : com.destroystokyo.paper.event.entity.EndermanEscapeEvent.Reason.CRITICAL_HIT)) { // Paper - EndermanEscapeEvent
68+
this.teleport();
69+
+ } // Paper - EndermanEscapeEvent
70+
}
71+
72+
return flag;
6073
} else {
6174
boolean flag = abstractThrownPotion1 != null && this.hurtWithCleanWater(level, damageSource, abstractThrownPotion1, amount);
6275

0 commit comments

Comments
 (0)