2015-02-26 23:41:06 +01:00
|
|
|
--- /home/matt/mc-dev-private//net/minecraft/server/EntityInsentient.java 2015-02-26 22:40:22.575608140 +0000
|
|
|
|
+++ src/main/java/net/minecraft/server/EntityInsentient.java 2015-02-26 22:40:22.579608139 +0000
|
2014-11-25 22:32:16 +01:00
|
|
|
@@ -4,6 +4,15 @@
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
+// 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 {
|
|
|
|
|
|
|
|
public int a_;
|
2015-02-26 23:41:06 +01:00
|
|
|
@@ -13,14 +22,14 @@
|
2014-12-06 22:45:51 +01:00
|
|
|
protected ControllerJump g;
|
|
|
|
private EntityAIBodyControl b;
|
|
|
|
protected NavigationAbstract navigation;
|
|
|
|
- protected final PathfinderGoalSelector goalSelector;
|
|
|
|
- protected final PathfinderGoalSelector targetSelector;
|
2015-02-26 23:41:06 +01:00
|
|
|
+ public PathfinderGoalSelector goalSelector; // CraftBukkit - public
|
|
|
|
+ public PathfinderGoalSelector targetSelector; // CraftBukkit - public
|
2014-12-06 22:45:51 +01:00
|
|
|
private EntityLiving goalTarget;
|
2015-02-26 23:41:06 +01:00
|
|
|
private EntitySenses bk;
|
2014-12-06 22:45:51 +01:00
|
|
|
private ItemStack[] equipment = new ItemStack[5];
|
2015-02-26 23:41:06 +01:00
|
|
|
- protected float[] dropChances = new float[5];
|
|
|
|
- private boolean canPickUpLoot;
|
|
|
|
- private boolean persistent;
|
|
|
|
+ public float[] dropChances = new float[5]; // CraftBukkit - public
|
|
|
|
+ public boolean canPickUpLoot; // CraftBukkit - public
|
|
|
|
+ public boolean persistent; // CraftBukkit - public
|
|
|
|
private boolean bo;
|
|
|
|
private Entity bp;
|
|
|
|
private NBTTagCompound bq;
|
|
|
|
@@ -40,6 +49,9 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
this.dropChances[i] = 0.085F;
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
2015-02-26 23:41:06 +01:00
|
|
|
protected void initAttributes() {
|
|
|
|
@@ -76,7 +88,37 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setGoalTarget(EntityLiving entityliving) {
|
|
|
|
+ // CraftBukkit start - fire event
|
|
|
|
+ setGoalTarget(entityliving, EntityTargetEvent.TargetReason.UNKNOWN, true);
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ public void setGoalTarget(EntityLiving entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
|
|
|
|
+ if (getGoalTarget() == entityliving) return;
|
|
|
|
+ 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;
|
|
|
|
+ }
|
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;
|
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2015-02-26 23:41:06 +01:00
|
|
|
public boolean a(Class<? extends EntityLiving> oclass) {
|
|
|
|
@@ -235,11 +277,20 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
super.a(nbttagcompound);
|
2015-02-26 23:41:06 +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)) {
|
|
|
|
- this.j(nbttagcompound.getBoolean("CanPickUpLoot"));
|
|
|
|
+ boolean data = nbttagcompound.getBoolean("CanPickUpLoot");
|
|
|
|
+ if (isLevelAtLeast(nbttagcompound, 1) || data) {
|
|
|
|
+ this.j(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;
|
|
|
|
|
|
|
|
@@ -380,11 +431,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
|
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;
|
2014-11-25 22:32:16 +01:00
|
|
|
@@ -707,6 +758,12 @@
|
|
|
|
|
|
|
|
public final boolean e(EntityHuman entityhuman) {
|
2015-02-26 23:41:06 +01:00
|
|
|
if (this.cc() && this.getLeashHolder() == entityhuman) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - fire PlayerUnleashEntityEvent
|
|
|
|
+ if (CraftEventFactory.callPlayerUnleashEntityEvent(this, entityhuman).isCancelled()) {
|
|
|
|
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(1, this, this.getLeashHolder()));
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
this.unleash(true, !entityhuman.abilities.canInstantlyBuild);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
@@ -714,12 +771,24 @@
|
|
|
|
|
2015-02-26 23:41:06 +01:00
|
|
|
if (itemstack != null && itemstack.getItem() == Items.LEAD && this.cb()) {
|
2014-11-25 22:32:16 +01:00
|
|
|
if (!(this instanceof EntityTameableAnimal) || !((EntityTameableAnimal) this).isTamed()) {
|
|
|
|
+ // CraftBukkit start - fire PlayerLeashEntityEvent
|
|
|
|
+ if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman).isCancelled()) {
|
|
|
|
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(1, this, this.getLeashHolder()));
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
this.setLeashHolder(entityhuman, true);
|
|
|
|
--itemstack.count;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((EntityTameableAnimal) this).e((EntityLiving) entityhuman)) {
|
|
|
|
+ // CraftBukkit start - fire PlayerLeashEntityEvent
|
|
|
|
+ if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman).isCancelled()) {
|
|
|
|
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(1, this, this.getLeashHolder()));
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
this.setLeashHolder(entityhuman, true);
|
|
|
|
--itemstack.count;
|
|
|
|
return true;
|
|
|
|
@@ -741,10 +810,12 @@
|
|
|
|
|
2015-02-26 23:41:06 +01:00
|
|
|
if (this.bo) {
|
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);
|
|
|
|
}
|
|
|
|
|
2015-02-26 23:41:06 +01:00
|
|
|
if (this.bp == null || this.bp.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -811,6 +882,7 @@
|
|
|
|
|
2015-02-26 23:41:06 +01:00
|
|
|
this.bp = entityleash;
|
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
|
|
|
}
|