Paper/nms-patches/EntityInsentient.patch

171 lines
7.3 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityInsentient.java
+++ b/net/minecraft/server/EntityInsentient.java
2016-05-10 13:47:39 +02:00
@@ -9,6 +9,15 @@
import java.util.UUID;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
+import org.bukkit.event.entity.EntityTargetEvent;
+import org.bukkit.event.entity.EntityUnleashEvent;
+import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
+// CraftBukkit end
+
public abstract class EntityInsentient extends EntityLiving {
2016-02-29 22:32:46 +01:00
private static final DataWatcherObject<Byte> a = DataWatcher.a(EntityInsentient.class, DataWatcherRegistry.a);
2016-06-09 03:43:49 +02:00
@@ -52,6 +61,9 @@
2016-02-29 22:32:46 +01:00
this.r();
}
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - default persistance to type's persistance value
+ this.persistent = !isTypeNotPersistent();
+ // CraftBukkit end
}
2016-02-29 22:32:46 +01:00
protected void r() {}
2016-06-09 03:43:49 +02:00
@@ -66,9 +78,10 @@
}
2016-05-10 13:47:39 +02:00
public float a(PathType pathtype) {
2016-06-09 03:43:49 +02:00
- Float float = (Float) this.bB.get(pathtype);
2016-05-10 13:47:39 +02:00
+ // CraftBukkit - decompile error
2016-06-09 03:43:49 +02:00
+ Float ofloat = (Float) this.bB.get(pathtype);
2016-05-10 13:47:39 +02:00
- return float == null ? pathtype.a() : float.floatValue();
+ return ofloat == null ? pathtype.a() : ofloat.floatValue();
}
public void a(PathType pathtype, float f) {
2016-06-09 03:43:49 +02:00
@@ -105,7 +118,38 @@
2016-05-10 13:47:39 +02:00
}
public void setGoalTarget(@Nullable EntityLiving entityliving) {
+ // CraftBukkit start - fire event
+ setGoalTarget(entityliving, EntityTargetEvent.TargetReason.UNKNOWN, true);
+ }
2015-02-26 23:41:06 +01:00
+
+ public boolean setGoalTarget(EntityLiving entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
+ if (getGoalTarget() == entityliving) return false;
+ if (fireEvent) {
+ if (reason == EntityTargetEvent.TargetReason.UNKNOWN && getGoalTarget() != null && entityliving == null) {
+ reason = getGoalTarget().isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
+ }
+ if (reason == EntityTargetEvent.TargetReason.UNKNOWN) {
+ world.getServer().getLogger().log(java.util.logging.Level.WARNING, "Unknown target reason, please report on the issue tracker", new Exception());
+ }
+ CraftLivingEntity ctarget = null;
+ if (entityliving != null) {
+ ctarget = (CraftLivingEntity) entityliving.getBukkitEntity();
+ }
+ EntityTargetLivingEntityEvent event = new EntityTargetLivingEntityEvent(this.getBukkitEntity(), ctarget, reason);
+ world.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return false;
+ }
2015-02-26 23:41:06 +01:00
+
+ if (event.getTarget() != null) {
+ entityliving = ((CraftLivingEntity) event.getTarget()).getHandle();
+ } else {
+ entityliving = null;
+ }
+ }
this.goalTarget = entityliving;
+ return true;
+ // CraftBukkit end
}
2016-02-29 22:32:46 +01:00
public boolean d(Class<? extends EntityLiving> oclass) {
2016-06-09 03:43:49 +02:00
@@ -350,11 +394,20 @@
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
2016-02-29 22:32:46 +01:00
+
+ // CraftBukkit start - If looting or persistence is false only use it if it was set after we started using it
if (nbttagcompound.hasKeyOfType("CanPickUpLoot", 1)) {
2016-06-09 03:43:49 +02:00
- this.m(nbttagcompound.getBoolean("CanPickUpLoot"));
+ boolean data = nbttagcompound.getBoolean("CanPickUpLoot");
+ if (isLevelAtLeast(nbttagcompound, 1) || data) {
2016-02-29 22:32:46 +01:00
+ this.l(data);
+ }
}
- this.persistent = nbttagcompound.getBoolean("PersistenceRequired");
+ boolean data = nbttagcompound.getBoolean("PersistenceRequired");
+ if (isLevelAtLeast(nbttagcompound, 1) || data) {
+ this.persistent = data;
+ }
+ // CraftBukkit end
NBTTagList nbttaglist;
int i;
2016-06-09 03:43:49 +02:00
@@ -579,11 +632,11 @@
double d2 = entityhuman.locZ - this.locZ;
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
- if (this.isTypeNotPersistent() && d3 > 16384.0D) {
+ if (d3 > 16384.0D) { // CraftBukkit - remove isTypeNotPersistent() check
this.die();
}
2015-02-26 23:41:06 +01:00
- if (this.ticksFarFromPlayer > 600 && this.random.nextInt(800) == 0 && d3 > 1024.0D && this.isTypeNotPersistent()) {
+ if (this.ticksFarFromPlayer > 600 && this.random.nextInt(800) == 0 && d3 > 1024.0D) { // CraftBukkit - remove isTypeNotPersistent() check
this.die();
} else if (d3 < 1024.0D) {
2015-02-26 23:41:06 +01:00
this.ticksFarFromPlayer = 0;
2016-06-09 03:43:49 +02:00
@@ -965,9 +1018,21 @@
2016-05-10 13:47:39 +02:00
public final boolean a(EntityHuman entityhuman, @Nullable ItemStack itemstack, EnumHand enumhand) {
2016-02-29 22:32:46 +01:00
if (this.isLeashed() && this.getLeashHolder() == entityhuman) {
+ // CraftBukkit start - fire PlayerUnleashEntityEvent
+ if (CraftEventFactory.callPlayerUnleashEntityEvent(this, entityhuman).isCancelled()) {
2016-02-29 22:32:46 +01:00
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(this, this.getLeashHolder()));
+ return false;
+ }
+ // CraftBukkit end
this.unleash(true, !entityhuman.abilities.canInstantlyBuild);
return true;
2016-02-29 22:32:46 +01:00
} else if (itemstack != null && itemstack.getItem() == Items.LEAD && this.a(entityhuman)) {
+ // CraftBukkit start - fire PlayerLeashEntityEvent
+ if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman).isCancelled()) {
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(this, this.getLeashHolder()));
+ return false;
+ }
+ // CraftBukkit end
this.setLeashHolder(entityhuman, true);
--itemstack.count;
return true;
2016-06-09 03:43:49 +02:00
@@ -987,10 +1052,12 @@
2016-06-09 03:43:49 +02:00
if (this.bE) {
if (!this.isAlive()) {
+ this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.PLAYER_UNLEASH)); // CraftBukkit
this.unleash(true, true);
}
2016-02-29 22:32:46 +01:00
if (this.leashHolder == null || this.leashHolder.dead) {
+ this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.HOLDER_GONE)); // CraftBukkit
this.unleash(true, true);
}
}
2016-06-09 03:43:49 +02:00
@@ -1001,7 +1068,9 @@
this.bE = false;
this.leashHolder = null;
if (!this.world.isClientSide && flag1) {
+ this.forceDrops = true; // CraftBukkit
this.a(Items.LEAD, 1);
+ this.forceDrops = false; // CraftBukkit
}
if (!this.world.isClientSide && flag && this.world instanceof WorldServer) {
2016-06-09 03:43:49 +02:00
@@ -1071,6 +1140,7 @@
2016-02-29 22:32:46 +01:00
this.leashHolder = entityleash;
} else {
+ this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
this.unleash(false, true);
}
2015-02-26 23:41:06 +01:00
}