2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/entity/EntityInsentient.java
+++ b/net/minecraft/world/entity/EntityInsentient.java
2021-06-11 07:00:00 +02:00
@@ -72,6 +72,19 @@
2021-03-15 23:00:00 +01:00
import net.minecraft.world.level.pathfinder.PathType;
import net.minecraft.world.level.storage.loot.LootTableInfo;
2014-11-25 22:32:16 +01:00
+// CraftBukkit start
2021-03-15 23:00:00 +01:00
+import net.minecraft.server.level.EntityPlayer;
2014-11-25 22:32:16 +01:00
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
2020-06-25 02:00:00 +02:00
+import org.bukkit.event.entity.CreatureSpawnEvent;
2018-07-15 02:00:00 +02:00
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
2014-11-25 22:32:16 +01:00
+import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
+import org.bukkit.event.entity.EntityTargetEvent;
2020-06-25 02:00:00 +02:00
+import org.bukkit.event.entity.EntityTransformEvent;
2014-11-25 22:32:16 +01:00
+import org.bukkit.event.entity.EntityUnleashEvent;
+import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
+// CraftBukkit end
+
public abstract class EntityInsentient extends EntityLiving {
2021-06-11 07:00:00 +02:00
private static final DataWatcherObject<Byte> DATA_MOB_FLAGS_ID = DataWatcher.a(EntityInsentient.class, DataWatcherRegistry.BYTE);
2021-07-06 16:00:00 +02:00
@@ -113,6 +126,8 @@
2021-06-11 07:00:00 +02:00
private BlockPosition restrictCenter;
private float restrictRadius;
2020-02-19 11:50:21 +01:00
+ public boolean aware = true; // CraftBukkit
+
protected EntityInsentient(EntityTypes<? extends EntityInsentient> entitytypes, World world) {
super(entitytypes, world);
2021-06-11 07:00:00 +02:00
this.handItems = NonNullList.a(2, ItemStack.EMPTY);
2021-07-06 16:00:00 +02:00
@@ -136,6 +151,9 @@
2019-04-23 04:00:00 +02:00
this.initPathfinder();
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
2021-06-11 07:00:00 +02:00
+ this.persistenceRequired = !isTypeNotPersistent(0);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
}
2019-04-23 04:00:00 +02:00
protected void initPathfinder() {}
2021-07-06 16:00:00 +02:00
@@ -216,7 +234,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) {
2021-06-11 13:33:49 +02:00
+ level.getCraftServer().getLogger().log(java.util.logging.Level.WARNING, "Unknown target reason, please report on the issue tracker", new Exception());
2014-11-25 22:32:16 +01:00
+ }
+ CraftLivingEntity ctarget = null;
+ if (entityliving != null) {
+ ctarget = (CraftLivingEntity) entityliving.getBukkitEntity();
+ }
+ EntityTargetLivingEntityEvent event = new EntityTargetLivingEntityEvent(this.getBukkitEntity(), ctarget, reason);
2021-06-11 13:33:49 +02:00
+ level.getCraftServer().getPluginManager().callEvent(event);
2014-11-25 22:32:16 +01:00
+ 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;
+ }
+ }
2021-06-11 07:00:00 +02:00
this.target = entityliving;
2016-04-20 12:40:16 +02:00
+ return true;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
}
2019-04-23 04:00:00 +02:00
@Override
2021-07-06 16:00:00 +02:00
@@ -443,16 +492,26 @@
2020-02-21 00:09:47 +01:00
nbttagcompound.setBoolean("NoAI", this.isNoAI());
}
+ nbttagcompound.setBoolean("Bukkit.Aware", this.aware); // CraftBukkit
}
2019-04-23 04:00:00 +02:00
@Override
2020-06-25 02:00:00 +02:00
public void loadData(NBTTagCompound nbttagcompound) {
super.loadData(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)) {
2019-04-23 04:00:00 +02:00
- this.setCanPickupLoot(nbttagcompound.getBoolean("CanPickUpLoot"));
2014-11-25 22:32:16 +01:00
+ boolean data = nbttagcompound.getBoolean("CanPickUpLoot");
+ if (isLevelAtLeast(nbttagcompound, 1) || data) {
2019-04-23 04:00:00 +02:00
+ this.setCanPickupLoot(data);
2014-11-25 22:32:16 +01:00
+ }
}
2021-06-11 07:00:00 +02:00
- this.persistenceRequired = nbttagcompound.getBoolean("PersistenceRequired");
2014-11-25 22:32:16 +01:00
+ boolean data = nbttagcompound.getBoolean("PersistenceRequired");
+ if (isLevelAtLeast(nbttagcompound, 1) || data) {
2021-06-11 07:00:00 +02:00
+ this.persistenceRequired = data;
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
NBTTagList nbttaglist;
int i;
2021-07-06 16:00:00 +02:00
@@ -499,6 +558,11 @@
2020-02-21 00:09:47 +01:00
}
this.setNoAI(nbttagcompound.getBoolean("NoAI"));
+ // CraftBukkit start
+ if (nbttagcompound.hasKey("Bukkit.Aware")) {
+ this.aware = nbttagcompound.getBoolean("Bukkit.Aware");
+ }
+ // CraftBukkit end
}
@Override
2021-07-06 16:00:00 +02:00
@@ -562,7 +626,7 @@
2020-06-25 02:00:00 +02:00
protected void b(EntityItem entityitem) {
ItemStack itemstack = entityitem.getItemStack();
2021-06-11 07:00:00 +02:00
- if (this.j(itemstack)) {
+ if (this.j(itemstack, entityitem)) { // CraftBukkit - add item
2020-06-25 02:00:00 +02:00
this.a(entityitem);
this.receive(entityitem, itemstack.getCount());
entityitem.die();
2021-07-06 16:00:00 +02:00
@@ -571,15 +635,29 @@
2020-06-25 02:00:00 +02:00
}
2021-06-11 07:00:00 +02:00
public boolean j(ItemStack itemstack) {
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start - add item
2021-06-11 07:00:00 +02:00
+ return this.j(itemstack, null);
2020-06-25 02:00:00 +02:00
+ }
+
2021-06-11 07:00:00 +02:00
+ public boolean j(ItemStack itemstack, EntityItem entityitem) {
2020-06-25 02:00:00 +02:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
EnumItemSlot enumitemslot = getEquipmentSlotForItem(itemstack);
2018-07-15 02:00:00 +02:00
ItemStack itemstack1 = this.getEquipment(enumitemslot);
2020-06-25 02:00:00 +02:00
boolean flag = this.a(itemstack, itemstack1);
2017-07-28 09:47:59 +02:00
2020-06-25 02:00:00 +02:00
- if (flag && this.canPickup(itemstack)) {
2017-07-28 09:47:59 +02:00
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ boolean canPickup = flag && this.canPickup(itemstack);
+ if (entityitem != null) {
+ canPickup = !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(this, entityitem, 0, !canPickup).isCancelled();
+ }
2017-07-28 09:47:59 +02:00
+ if (canPickup) {
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
double d0 = (double) this.e(enumitemslot);
2017-04-09 01:05:32 +02:00
2019-12-10 23:00:00 +01:00
if (!itemstack1.isEmpty() && (double) Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d0) {
2017-04-09 01:05:32 +02:00
+ this.forceDrops = true; // CraftBukkit
2021-06-11 07:00:00 +02:00
this.b(itemstack1);
2017-04-09 01:05:32 +02:00
+ this.forceDrops = false; // CraftBukkit
}
2020-06-25 02:00:00 +02:00
this.b(enumitemslot, itemstack);
2021-07-06 16:00:00 +02:00
@@ -692,18 +770,18 @@
2021-06-11 07:00:00 +02:00
EntityHuman entityhuman = this.level.findNearbyPlayer(this, -1.0D);
2020-06-25 02:00:00 +02:00
2019-04-23 04:00:00 +02:00
if (entityhuman != null) {
2021-06-11 07:00:00 +02:00
- double d0 = entityhuman.f(this);
+ double d0 = entityhuman.f((Entity) this); // CraftBukkit - decompile error
int i = this.getEntityType().f().f();
2020-06-25 02:00:00 +02:00
int j = i * i;
2014-11-25 22:32:16 +01:00
2020-06-25 02:00:00 +02:00
- if (d0 > (double) j && this.isTypeNotPersistent(d0)) {
+ if (d0 > (double) j) { // CraftBukkit - remove isTypeNotPersistent() check
2014-11-25 22:32:16 +01:00
this.die();
}
2021-06-11 07:00:00 +02:00
int k = this.getEntityType().f().g();
2020-06-25 02:00:00 +02:00
int l = k * k;
2021-06-11 07:00:00 +02:00
- if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l && this.isTypeNotPersistent(d0)) {
+ if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l) { // CraftBukkit - remove isTypeNotPersistent() check
2014-11-25 22:32:16 +01:00
this.die();
2020-06-25 02:00:00 +02:00
} else if (d0 < (double) l) {
2021-06-11 07:00:00 +02:00
this.noActionTime = 0;
2021-07-06 16:00:00 +02:00
@@ -718,6 +796,7 @@
2020-02-19 11:50:21 +01:00
@Override
protected final void doTick() {
2021-06-11 07:00:00 +02:00
++this.noActionTime;
2020-02-19 11:50:21 +01:00
+ if (!this.aware) return; // CraftBukkit
2021-06-11 07:00:00 +02:00
this.level.getMethodProfiler().enter("sensing");
this.sensing.a();
this.level.getMethodProfiler().exit();
2021-07-06 16:00:00 +02:00
@@ -1101,6 +1180,12 @@
2019-04-23 04:00:00 +02:00
if (!this.isAlive()) {
2020-06-25 02:00:00 +02:00
return EnumInteractionResult.PASS;
2019-04-23 04:00:00 +02:00
} else if (this.getLeashHolder() == entityhuman) {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - fire PlayerUnleashEntityEvent
+ if (CraftEventFactory.callPlayerUnleashEntityEvent(this, entityhuman).isCancelled()) {
2021-06-11 07:00:00 +02:00
+ ((EntityPlayer) entityhuman).connection.sendPacket(new PacketPlayOutAttachEntity(this, this.getLeashHolder()));
2020-06-25 02:00:00 +02:00
+ return EnumInteractionResult.PASS;
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.unleash(true, !entityhuman.getAbilities().instabuild);
return EnumInteractionResult.a(this.level.isClientSide);
2020-06-25 02:00:00 +02:00
} else {
2021-07-06 16:00:00 +02:00
@@ -1119,6 +1204,12 @@
2020-06-25 02:00:00 +02:00
ItemStack itemstack = entityhuman.b(enumhand);
2021-06-11 07:00:00 +02:00
if (itemstack.a(Items.LEAD) && this.a(entityhuman)) {
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start - fire PlayerLeashEntityEvent
+ if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman).isCancelled()) {
2021-06-11 07:00:00 +02:00
+ ((EntityPlayer) entityhuman).connection.sendPacket(new PacketPlayOutAttachEntity(this, this.getLeashHolder()));
2020-06-25 02:00:00 +02:00
+ return EnumInteractionResult.PASS;
+ }
+ // CraftBukkit end
this.setLeashHolder(entityhuman, true);
itemstack.subtract(1);
2021-06-11 07:00:00 +02:00
return EnumInteractionResult.a(this.level.isClientSide);
2021-07-06 16:00:00 +02:00
@@ -1134,7 +1225,7 @@
2020-06-25 02:00:00 +02:00
if (itemstack.getItem() instanceof ItemMonsterEgg) {
2021-06-11 07:00:00 +02:00
if (this.level instanceof WorldServer) {
2020-06-25 02:00:00 +02:00
ItemMonsterEgg itemmonsteregg = (ItemMonsterEgg) itemstack.getItem();
2021-06-11 07:00:00 +02:00
- Optional<EntityInsentient> optional = itemmonsteregg.a(entityhuman, this, this.getEntityType(), (WorldServer) this.level, this.getPositionVector(), itemstack);
+ Optional<EntityInsentient> optional = itemmonsteregg.a(entityhuman, this, (EntityTypes<? extends EntityInsentient>) this.getEntityType(), (WorldServer) this.level, this.getPositionVector(), itemstack); // CraftBukkit - decompile error
2020-06-25 02:00:00 +02:00
optional.ifPresent((entityinsentient) -> {
this.a(entityhuman, entityinsentient);
2021-07-06 16:00:00 +02:00
@@ -1184,12 +1275,19 @@
2021-06-11 07:00:00 +02:00
return this.restrictRadius != -1.0F;
2020-08-11 23:00:00 +02:00
}
+ // CraftBukkit start
@Nullable
public <T extends EntityInsentient> T a(EntityTypes<T> entitytypes, boolean flag) {
+ return this.a(entitytypes, flag, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ @Nullable
+ public <T extends EntityInsentient> T a(EntityTypes<T> entitytypes, boolean flag, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
if (this.isRemoved()) {
2020-06-25 02:00:00 +02:00
return null;
2016-11-17 02:41:03 +01:00
} else {
2021-06-11 07:00:00 +02:00
- T t0 = (EntityInsentient) entitytypes.a(this.level);
+ T t0 = entitytypes.a(this.level); // CraftBukkit - decompile error
2020-06-25 02:00:00 +02:00
2021-06-11 07:00:00 +02:00
t0.s(this);
2020-08-11 23:00:00 +02:00
t0.setBaby(this.isBaby());
2021-07-06 16:00:00 +02:00
@@ -1221,7 +1319,12 @@
2020-06-25 02:00:00 +02:00
}
}
2021-06-11 07:00:00 +02:00
- this.level.addEntity(t0);
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start
2020-08-11 23:00:00 +02:00
+ if (CraftEventFactory.callEntityTransformEvent(this, t0, transformReason).isCancelled()) {
2020-06-25 02:00:00 +02:00
+ return null;
+ }
2021-06-11 07:00:00 +02:00
+ this.level.addEntity(t0, spawnReason);
2020-06-25 02:00:00 +02:00
+ // CraftBukkit end
2020-08-11 23:00:00 +02:00
if (this.isPassenger()) {
Entity entity = this.getVehicle();
2021-07-06 16:00:00 +02:00
@@ -1241,6 +1344,7 @@
2016-11-17 02:41:03 +01:00
2019-04-23 04:00:00 +02:00
if (this.leashHolder != null) {
if (!this.isAlive() || !this.leashHolder.isAlive()) {
2021-06-11 13:33:49 +02:00
+ this.level.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), (!this.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE)); // CraftBukkit
2014-11-25 22:32:16 +01:00
this.unleash(true, true);
}
2021-07-06 16:00:00 +02:00
@@ -1252,7 +1356,9 @@
2016-03-11 09:24:57 +01:00
this.leashHolder = null;
2021-06-11 07:00:00 +02:00
this.leashInfoTag = null;
if (!this.level.isClientSide && flag1) {
2016-03-11 09:24:57 +01:00
+ 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
}
2021-06-11 07:00:00 +02:00
if (!this.level.isClientSide && flag && this.level instanceof WorldServer) {
2021-07-06 16:00:00 +02:00
@@ -1302,6 +1408,7 @@
2020-06-25 02:00:00 +02:00
boolean flag1 = super.a(entity, flag);
2014-11-25 22:32:16 +01:00
2020-06-25 02:00:00 +02:00
if (flag1 && this.isLeashed()) {
2021-06-11 13:33:49 +02:00
+ this.level.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
2020-06-25 02:00:00 +02:00
this.unleash(true, true);
}
2019-04-23 04:00:00 +02:00
2021-07-06 16:00:00 +02:00
@@ -1397,7 +1504,14 @@
2019-04-23 04:00:00 +02:00
int i = EnchantmentManager.getFireAspectEnchantmentLevel(this);
if (i > 0) {
- entity.setOnFire(i * 4);
+ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
+ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), i * 4);
+ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
2018-07-15 02:00:00 +02:00
+
2019-04-23 04:00:00 +02:00
+ if (!combustEvent.isCancelled()) {
+ entity.setOnFire(combustEvent.getDuration(), false);
+ }
+ // CraftBukkit end
}
2018-07-15 02:00:00 +02:00
2019-04-23 04:00:00 +02:00
boolean flag = entity.damageEntity(DamageSource.mobAttack(this), f);
2021-07-06 16:00:00 +02:00
@@ -1465,9 +1579,10 @@
2020-06-25 02:00:00 +02:00
@Override
2021-06-11 07:00:00 +02:00
protected void cc() {
super.cc();
2021-06-11 13:33:49 +02:00
+ this.level.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
2020-06-25 02:00:00 +02:00
this.unleash(true, false);
2021-06-11 07:00:00 +02:00
this.by().forEach((itemstack) -> {
- itemstack.setCount(0);
+ if (!itemstack.isEmpty()) itemstack.setCount(0); // CraftBukkit
});
2020-06-25 02:00:00 +02:00
}
2021-06-11 07:00:00 +02:00