2015-05-25 12:37:24 +02:00
|
|
|
--- a/net/minecraft/server/EntityInsentient.java
|
|
|
|
+++ b/net/minecraft/server/EntityInsentient.java
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -10,6 +10,18 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
import java.util.UUID;
|
2016-05-10 13:47:39 +02:00
|
|
|
import javax.annotation.Nullable;
|
2014-11-25 22:32:16 +01:00
|
|
|
|
|
|
|
+// CraftBukkit start
|
|
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
|
|
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
2017-07-28 09:47:59 +02:00
|
|
|
+import org.bukkit.entity.LivingEntity;
|
2018-07-15 02:00:00 +02:00
|
|
|
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
2017-07-28 09:47:59 +02:00
|
|
|
+import org.bukkit.event.entity.EntityPickupItemEvent;
|
2014-11-25 22:32:16 +01:00
|
|
|
+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);
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -28,7 +40,7 @@
|
2017-06-26 00:34:52 +02:00
|
|
|
public float[] dropChanceHand;
|
2018-07-15 02:00:00 +02:00
|
|
|
private final NonNullList<ItemStack> bE;
|
2017-06-26 00:34:52 +02:00
|
|
|
public float[] dropChanceArmor;
|
|
|
|
- public boolean canPickUpLoot;
|
|
|
|
+ // public boolean canPickUpLoot; // CraftBukkit - moved up to EntityLiving
|
|
|
|
public boolean persistent;
|
2018-07-15 02:00:00 +02:00
|
|
|
private final Map<PathType, Float> bH;
|
2018-08-26 04:00:00 +02:00
|
|
|
public MinecraftKey lootTableKey;
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -58,6 +70,9 @@
|
2018-07-15 02:00:00 +02:00
|
|
|
this.n();
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - default persistance to type's persistance value
|
|
|
|
+ this.persistent = !isTypeNotPersistent();
|
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2018-07-15 02:00:00 +02:00
|
|
|
protected void n() {}
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -111,7 +126,38 @@
|
2016-05-10 13:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setGoalTarget(@Nullable EntityLiving entityliving) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - fire event
|
|
|
|
+ setGoalTarget(entityliving, EntityTargetEvent.TargetReason.UNKNOWN, true);
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2016-04-20 12:40:16 +02:00
|
|
|
+ public boolean setGoalTarget(EntityLiving entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
|
|
|
|
+ if (getGoalTarget() == entityliving) return false;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ 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()) {
|
2016-04-20 12:40:16 +02:00
|
|
|
+ return false;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ if (event.getTarget() != null) {
|
|
|
|
+ entityliving = ((CraftLivingEntity) event.getTarget()).getHandle();
|
|
|
|
+ } else {
|
|
|
|
+ entityliving = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
this.goalTarget = entityliving;
|
2016-04-20 12:40:16 +02:00
|
|
|
+ return true;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2018-07-15 02:00:00 +02:00
|
|
|
public boolean b(Class<? extends EntityLiving> oclass) {
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -337,11 +383,20 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
super.a(nbttagcompound);
|
2016-02-29 22:32:46 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +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)) {
|
2018-07-15 02:00:00 +02:00
|
|
|
- this.p(nbttagcompound.getBoolean("CanPickUpLoot"));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ boolean data = nbttagcompound.getBoolean("CanPickUpLoot");
|
|
|
|
+ if (isLevelAtLeast(nbttagcompound, 1) || data) {
|
2018-07-15 02:00:00 +02:00
|
|
|
+ this.p(data);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
- this.persistent = nbttagcompound.getBoolean("PersistenceRequired");
|
|
|
|
+ boolean data = nbttagcompound.getBoolean("PersistenceRequired");
|
|
|
|
+ if (isLevelAtLeast(nbttagcompound, 1) || data) {
|
|
|
|
+ this.persistent = data;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
NBTTagList nbttaglist;
|
|
|
|
int i;
|
|
|
|
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -395,6 +450,11 @@
|
2018-08-26 04:00:00 +02:00
|
|
|
protected MinecraftKey getDefaultLootTable() {
|
2018-08-12 10:39:51 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
+ // CraftBukkit - start
|
|
|
|
+ public MinecraftKey getLootTable() {
|
2018-08-26 04:00:00 +02:00
|
|
|
+ return getDefaultLootTable();
|
2018-08-12 10:39:51 +02:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit - end
|
|
|
|
|
|
|
|
protected void a(boolean flag, int i, DamageSource damagesource) {
|
2018-08-26 04:00:00 +02:00
|
|
|
MinecraftKey minecraftkey = this.lootTableKey;
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -471,11 +531,21 @@
|
2018-07-15 02:00:00 +02:00
|
|
|
ItemStack itemstack1 = this.getEquipment(enumitemslot);
|
|
|
|
boolean flag = this.a(itemstack, itemstack1, enumitemslot);
|
2017-07-28 09:47:59 +02:00
|
|
|
|
2018-07-15 02:00:00 +02:00
|
|
|
- if (flag && this.d(itemstack)) {
|
2017-07-28 09:47:59 +02:00
|
|
|
+ // CraftBukkit start
|
2018-07-15 02:00:00 +02:00
|
|
|
+ boolean canPickup = flag && this.d(itemstack);
|
2017-07-28 09:47:59 +02:00
|
|
|
+
|
|
|
|
+ EntityPickupItemEvent entityEvent = new EntityPickupItemEvent((LivingEntity) getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity(), 0);
|
|
|
|
+ entityEvent.setCancelled(!canPickup);
|
|
|
|
+ this.world.getServer().getPluginManager().callEvent(entityEvent);
|
|
|
|
+ canPickup = !entityEvent.isCancelled();
|
|
|
|
+ if (canPickup) {
|
|
|
|
+ // CraftBukkit end
|
2018-08-26 04:00:00 +02:00
|
|
|
double d0 = (double) this.c(enumitemslot);
|
2017-04-09 01:05:32 +02:00
|
|
|
|
|
|
|
if (!itemstack1.isEmpty() && (double) (this.random.nextFloat() - 0.1F) < d0) {
|
|
|
|
+ this.forceDrops = true; // CraftBukkit
|
2018-07-15 02:00:00 +02:00
|
|
|
this.a_(itemstack1);
|
2017-04-09 01:05:32 +02:00
|
|
|
+ this.forceDrops = false; // CraftBukkit
|
|
|
|
}
|
|
|
|
|
2017-05-14 04:00:00 +02:00
|
|
|
this.setSlot(enumitemslot, itemstack);
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -554,11 +624,11 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
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
|
2014-11-25 22:32:16 +01:00
|
|
|
this.die();
|
|
|
|
} else if (d3 < 1024.0D) {
|
2015-02-26 23:41:06 +01:00
|
|
|
this.ticksFarFromPlayer = 0;
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -932,12 +1002,24 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2016-11-17 02:41:03 +01:00
|
|
|
public final boolean b(EntityHuman entityhuman, EnumHand enumhand) {
|
2016-02-29 22:32:46 +01:00
|
|
|
if (this.isLeashed() && this.getLeashHolder() == entityhuman) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // 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()));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
this.unleash(true, !entityhuman.abilities.canInstantlyBuild);
|
|
|
|
return true;
|
2016-11-17 02:41:03 +01:00
|
|
|
} else {
|
|
|
|
ItemStack itemstack = entityhuman.b(enumhand);
|
|
|
|
|
|
|
|
if (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.subtract(1);
|
|
|
|
return true;
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -958,10 +1040,12 @@
|
2016-11-17 02:41:03 +01:00
|
|
|
|
2018-07-15 02:00:00 +02:00
|
|
|
if (this.bK) {
|
2014-11-25 22:32:16 +01:00
|
|
|
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) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.HOLDER_GONE)); // CraftBukkit
|
|
|
|
this.unleash(true, true);
|
|
|
|
}
|
|
|
|
}
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -972,7 +1056,9 @@
|
2018-07-15 02:00:00 +02:00
|
|
|
this.bK = false;
|
2016-03-11 09:24:57 +01:00
|
|
|
this.leashHolder = null;
|
|
|
|
if (!this.world.isClientSide && flag1) {
|
|
|
|
+ this.forceDrops = true; // CraftBukkit
|
2018-07-15 02:00:00 +02:00
|
|
|
this.a((IMaterial) Items.LEAD);
|
2016-03-11 09:24:57 +01:00
|
|
|
+ this.forceDrops = false; // CraftBukkit
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.world.isClientSide && flag && this.world instanceof WorldServer) {
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -1042,6 +1128,7 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2016-11-17 02:41:03 +01:00
|
|
|
this.setLeashHolder(entityleash, true);
|
2014-11-25 22:32:16 +01:00
|
|
|
} 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
|
|
|
}
|
2018-12-25 22:00:00 +01:00
|
|
|
@@ -1137,7 +1224,14 @@
|
2018-07-15 02:00:00 +02:00
|
|
|
int j = EnchantmentManager.getFireAspectEnchantmentLevel(this);
|
|
|
|
|
|
|
|
if (j > 0) {
|
|
|
|
- entity.setOnFire(j * 4);
|
|
|
|
+ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
|
|
|
|
+ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), j * 4);
|
|
|
|
+ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
|
|
|
|
+
|
|
|
|
+ if (!combustEvent.isCancelled()) {
|
2019-01-11 01:41:32 +01:00
|
|
|
+ entity.setOnFire(combustEvent.getDuration(), false);
|
2018-07-15 02:00:00 +02:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entity instanceof EntityHuman) {
|