2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-04-30 19:16:42 +02:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Mon, 30 Apr 2018 13:15:55 -0400
|
|
|
|
Subject: [PATCH] EndermanEscapeEvent
|
|
|
|
|
|
|
|
Fires an event anytime an enderman intends to teleport away from the player
|
|
|
|
|
|
|
|
You may cancel this, enabling ranged attacks to damage the enderman for example.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityEnderman.java b/src/main/java/net/minecraft/server/EntityEnderman.java
|
2020-06-25 16:09:55 +02:00
|
|
|
index 37a4bce1cd24e04b70367484c1ad3beae047ab08..888e66520548a47dbfa1c452b0d3fa5dcbe2002c 100644
|
2018-04-30 19:16:42 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityEnderman.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityEnderman.java
|
2019-04-29 05:14:31 +02:00
|
|
|
@@ -2,6 +2,7 @@ package net.minecraft.server;
|
2018-04-30 19:16:42 +02:00
|
|
|
|
2019-04-29 05:14:31 +02:00
|
|
|
import java.util.EnumSet;
|
2018-07-18 20:55:52 +02:00
|
|
|
import java.util.Optional;
|
2018-07-19 01:16:19 +02:00
|
|
|
+import com.destroystokyo.paper.event.entity.EndermanEscapeEvent; // Paper
|
2018-07-18 20:55:52 +02:00
|
|
|
import java.util.Random;
|
|
|
|
import java.util.UUID;
|
2019-04-29 05:14:31 +02:00
|
|
|
import java.util.function.Predicate;
|
2020-06-25 16:09:55 +02:00
|
|
|
@@ -56,6 +57,12 @@ public class EntityEnderman extends EntityMonster implements IEntityAngerable {
|
2018-07-18 20:55:52 +02:00
|
|
|
setGoalTarget(entityliving, org.bukkit.event.entity.EntityTargetEvent.TargetReason.UNKNOWN, true);
|
2018-04-30 19:16:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ private boolean tryEscape(EndermanEscapeEvent.Reason reason) {
|
|
|
|
+ return new EndermanEscapeEvent((org.bukkit.craftbukkit.entity.CraftEnderman) this.getBukkitEntity(), reason).callEvent();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
@Override
|
|
|
|
public boolean setGoalTarget(EntityLiving entityliving, org.bukkit.event.entity.EntityTargetEvent.TargetReason reason, boolean fireEvent) {
|
|
|
|
if (!super.setGoalTarget(entityliving, reason, fireEvent)) {
|
2020-06-25 16:09:55 +02:00
|
|
|
@@ -209,7 +216,7 @@ public class EntityEnderman extends EntityMonster implements IEntityAngerable {
|
|
|
|
if (this.world.isDay() && this.ticksLived >= this.bz + 600) {
|
|
|
|
float f = this.aO();
|
2018-04-30 19:16:42 +02:00
|
|
|
|
2020-06-25 16:09:55 +02:00
|
|
|
- if (f > 0.5F && this.world.f(this.getChunkCoordinates()) && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F) {
|
|
|
|
+ if (f > 0.5F && this.world.f(this.getChunkCoordinates()) && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && this.tryEscape(EndermanEscapeEvent.Reason.RUNAWAY)) { // Paper
|
2018-04-30 19:16:42 +02:00
|
|
|
this.setGoalTarget((EntityLiving) null);
|
2020-06-25 16:09:55 +02:00
|
|
|
this.eM();
|
2018-04-30 19:16:42 +02:00
|
|
|
}
|
2020-06-25 16:09:55 +02:00
|
|
|
@@ -307,17 +314,19 @@ public class EntityEnderman extends EntityMonster implements IEntityAngerable {
|
|
|
|
if (this.isInvulnerable(damagesource)) {
|
|
|
|
return false;
|
|
|
|
} else if (damagesource instanceof EntityDamageSourceIndirect) {
|
2019-04-29 05:14:31 +02:00
|
|
|
+ if (this.tryEscape(EndermanEscapeEvent.Reason.INDIRECT)) { // Paper start
|
|
|
|
for (int i = 0; i < 64; ++i) {
|
2020-06-25 16:09:55 +02:00
|
|
|
if (this.eM()) {
|
2019-04-29 05:14:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
2018-04-30 19:16:42 +02:00
|
|
|
}
|
2019-04-29 05:14:31 +02:00
|
|
|
+ } // Paper end
|
2018-04-30 19:16:42 +02:00
|
|
|
|
2019-04-29 05:14:31 +02:00
|
|
|
return false;
|
2020-06-25 16:09:55 +02:00
|
|
|
} else {
|
|
|
|
boolean flag = super.damageEntity(damagesource, f);
|
|
|
|
|
|
|
|
- if (!this.world.s_() && this.random.nextInt(10) != 0) {
|
|
|
|
+ if (!this.world.s_() && this.random.nextInt(10) != 0 && this.tryEscape(damagesource == DamageSource.DROWN ? EndermanEscapeEvent.Reason.DROWN : EndermanEscapeEvent.Reason.CRITICAL_HIT)) { // Paper
|
|
|
|
this.eM();
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -459,7 +468,7 @@ public class EntityEnderman extends EntityMonster implements IEntityAngerable {
|
2018-04-30 19:16:42 +02:00
|
|
|
|
|
|
|
static class PathfinderGoalPlayerWhoLookedAtTarget extends PathfinderGoalNearestAttackableTarget<EntityHuman> {
|
|
|
|
|
|
|
|
- private final EntityEnderman i;
|
2019-04-29 05:14:31 +02:00
|
|
|
+ private final EntityEnderman i; public final EntityEnderman getEnderman() { return this.i; } // Paper - OBFHELPER
|
2018-04-30 19:16:42 +02:00
|
|
|
private EntityHuman j;
|
|
|
|
private int k;
|
|
|
|
private int l;
|
2020-06-25 16:09:55 +02:00
|
|
|
@@ -522,7 +531,7 @@ public class EntityEnderman extends EntityMonster implements IEntityAngerable {
|
2018-04-30 19:16:42 +02:00
|
|
|
} else {
|
2019-04-29 05:14:31 +02:00
|
|
|
if (this.c != null && !this.i.isPassenger()) {
|
2020-06-25 16:09:55 +02:00
|
|
|
if (this.i.g((EntityHuman) this.c)) {
|
2019-04-29 05:14:31 +02:00
|
|
|
- if (this.c.h((Entity) this.i) < 16.0D) {
|
|
|
|
+ if (this.c.h((Entity) this.i) < 16.0D && this.getEnderman().tryEscape(EndermanEscapeEvent.Reason.STARE)) {
|
2020-06-25 16:09:55 +02:00
|
|
|
this.i.eM();
|
2018-04-30 19:16:42 +02:00
|
|
|
}
|
|
|
|
|