mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 19:49:35 +01:00
159ae52462
By: Parker Hawke <hawkeboyz2@hotmail.com>
319 lines
14 KiB
Diff
319 lines
14 KiB
Diff
--- a/net/minecraft/world/entity/EntityInsentient.java
|
|
+++ b/net/minecraft/world/entity/EntityInsentient.java
|
|
@@ -75,6 +75,19 @@
|
|
import net.minecraft.world.level.pathfinder.PathType;
|
|
import net.minecraft.world.level.storage.loot.LootTableInfo;
|
|
|
|
+// CraftBukkit start
|
|
+import net.minecraft.server.level.EntityPlayer;
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
|
+import org.bukkit.event.entity.CreatureSpawnEvent;
|
|
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
|
+import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
|
+import org.bukkit.event.entity.EntityTargetEvent;
|
|
+import org.bukkit.event.entity.EntityTransformEvent;
|
|
+import org.bukkit.event.entity.EntityUnleashEvent;
|
|
+import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
|
|
+// CraftBukkit end
|
|
+
|
|
public abstract class EntityInsentient extends EntityLiving {
|
|
|
|
private static final DataWatcherObject<Byte> DATA_MOB_FLAGS_ID = DataWatcher.defineId(EntityInsentient.class, DataWatcherRegistry.BYTE);
|
|
@@ -121,6 +134,8 @@
|
|
private BlockPosition restrictCenter;
|
|
private float restrictRadius;
|
|
|
|
+ public boolean aware = true; // CraftBukkit
|
|
+
|
|
protected EntityInsentient(EntityTypes<? extends EntityInsentient> entitytypes, World world) {
|
|
super(entitytypes, world);
|
|
this.handItems = NonNullList.withSize(2, ItemStack.EMPTY);
|
|
@@ -146,6 +161,12 @@
|
|
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
+ public void setPersistenceRequired(boolean persistenceRequired) {
|
|
+ this.persistenceRequired = persistenceRequired;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
protected void registerGoals() {}
|
|
|
|
public static AttributeProvider.Builder createMobAttributes() {
|
|
@@ -224,7 +245,38 @@
|
|
}
|
|
|
|
public void setTarget(@Nullable EntityLiving entityliving) {
|
|
+ // CraftBukkit start - fire event
|
|
+ setTarget(entityliving, EntityTargetEvent.TargetReason.UNKNOWN, true);
|
|
+ }
|
|
+
|
|
+ public boolean setTarget(EntityLiving entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
|
|
+ if (getTarget() == entityliving) return false;
|
|
+ if (fireEvent) {
|
|
+ if (reason == EntityTargetEvent.TargetReason.UNKNOWN && getTarget() != null && entityliving == null) {
|
|
+ reason = getTarget().isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
|
|
+ }
|
|
+ if (reason == EntityTargetEvent.TargetReason.UNKNOWN) {
|
|
+ level.getCraftServer().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);
|
|
+ level.getCraftServer().getPluginManager().callEvent(event);
|
|
+ if (event.isCancelled()) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ if (event.getTarget() != null) {
|
|
+ entityliving = ((CraftLivingEntity) event.getTarget()).getHandle();
|
|
+ } else {
|
|
+ entityliving = null;
|
|
+ }
|
|
+ }
|
|
this.target = entityliving;
|
|
+ return true;
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
@Override
|
|
@@ -364,6 +416,12 @@
|
|
return null;
|
|
}
|
|
|
|
+ // CraftBukkit start - Add delegate method
|
|
+ public SoundEffect getAmbientSound0() {
|
|
+ return getAmbientSound();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
@Override
|
|
public void addAdditionalSaveData(NBTTagCompound nbttagcompound) {
|
|
super.addAdditionalSaveData(nbttagcompound);
|
|
@@ -453,16 +511,26 @@
|
|
nbttagcompound.putBoolean("NoAI", this.isNoAi());
|
|
}
|
|
|
|
+ nbttagcompound.putBoolean("Bukkit.Aware", this.aware); // CraftBukkit
|
|
}
|
|
|
|
@Override
|
|
public void readAdditionalSaveData(NBTTagCompound nbttagcompound) {
|
|
super.readAdditionalSaveData(nbttagcompound);
|
|
+
|
|
+ // CraftBukkit start - If looting or persistence is false only use it if it was set after we started using it
|
|
if (nbttagcompound.contains("CanPickUpLoot", 1)) {
|
|
- this.setCanPickUpLoot(nbttagcompound.getBoolean("CanPickUpLoot"));
|
|
+ boolean data = nbttagcompound.getBoolean("CanPickUpLoot");
|
|
+ if (isLevelAtLeast(nbttagcompound, 1) || data) {
|
|
+ this.setCanPickUpLoot(data);
|
|
+ }
|
|
}
|
|
|
|
- this.persistenceRequired = nbttagcompound.getBoolean("PersistenceRequired");
|
|
+ boolean data = nbttagcompound.getBoolean("PersistenceRequired");
|
|
+ if (isLevelAtLeast(nbttagcompound, 1) || data) {
|
|
+ this.persistenceRequired = data;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
NBTTagList nbttaglist;
|
|
int i;
|
|
|
|
@@ -509,6 +577,11 @@
|
|
}
|
|
|
|
this.setNoAi(nbttagcompound.getBoolean("NoAI"));
|
|
+ // CraftBukkit start
|
|
+ if (nbttagcompound.contains("Bukkit.Aware")) {
|
|
+ this.aware = nbttagcompound.getBoolean("Bukkit.Aware");
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
@Override
|
|
@@ -577,7 +650,7 @@
|
|
protected void pickUpItem(EntityItem entityitem) {
|
|
ItemStack itemstack = entityitem.getItem();
|
|
|
|
- if (this.equipItemIfPossible(itemstack)) {
|
|
+ if (this.equipItemIfPossible(itemstack, entityitem)) { // CraftBukkit - add item
|
|
this.onItemPickup(entityitem);
|
|
this.take(entityitem, itemstack.getCount());
|
|
entityitem.discard();
|
|
@@ -586,15 +659,29 @@
|
|
}
|
|
|
|
public boolean equipItemIfPossible(ItemStack itemstack) {
|
|
+ // CraftBukkit start - add item
|
|
+ return this.equipItemIfPossible(itemstack, null);
|
|
+ }
|
|
+
|
|
+ public boolean equipItemIfPossible(ItemStack itemstack, EntityItem entityitem) {
|
|
+ // CraftBukkit end
|
|
EnumItemSlot enumitemslot = getEquipmentSlotForItem(itemstack);
|
|
ItemStack itemstack1 = this.getItemBySlot(enumitemslot);
|
|
boolean flag = this.canReplaceCurrentItem(itemstack, itemstack1);
|
|
|
|
- if (flag && this.canHoldItem(itemstack)) {
|
|
+ // CraftBukkit start
|
|
+ boolean canPickup = flag && this.canHoldItem(itemstack);
|
|
+ if (entityitem != null) {
|
|
+ canPickup = !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(this, entityitem, 0, !canPickup).isCancelled();
|
|
+ }
|
|
+ if (canPickup) {
|
|
+ // CraftBukkit end
|
|
double d0 = (double) this.getEquipmentDropChance(enumitemslot);
|
|
|
|
if (!itemstack1.isEmpty() && (double) Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d0) {
|
|
+ this.forceDrops = true; // CraftBukkit
|
|
this.spawnAtLocation(itemstack1);
|
|
+ this.forceDrops = false; // CraftBukkit
|
|
}
|
|
|
|
this.setItemSlotAndDropWhenKilled(enumitemslot, itemstack);
|
|
@@ -732,6 +819,7 @@
|
|
@Override
|
|
protected final void serverAiStep() {
|
|
++this.noActionTime;
|
|
+ if (!this.aware) return; // CraftBukkit
|
|
this.level.getProfiler().push("sensing");
|
|
this.sensing.tick();
|
|
this.level.getProfiler().pop();
|
|
@@ -1125,6 +1213,12 @@
|
|
if (!this.isAlive()) {
|
|
return EnumInteractionResult.PASS;
|
|
} else if (this.getLeashHolder() == entityhuman) {
|
|
+ // CraftBukkit start - fire PlayerUnleashEntityEvent
|
|
+ if (CraftEventFactory.callPlayerUnleashEntityEvent(this, entityhuman, enumhand).isCancelled()) {
|
|
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutAttachEntity(this, this.getLeashHolder()));
|
|
+ return EnumInteractionResult.PASS;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.dropLeash(true, !entityhuman.getAbilities().instabuild);
|
|
return EnumInteractionResult.sidedSuccess(this.level.isClientSide);
|
|
} else {
|
|
@@ -1148,6 +1242,12 @@
|
|
ItemStack itemstack = entityhuman.getItemInHand(enumhand);
|
|
|
|
if (itemstack.is(Items.LEAD) && this.canBeLeashed(entityhuman)) {
|
|
+ // CraftBukkit start - fire PlayerLeashEntityEvent
|
|
+ if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman, enumhand).isCancelled()) {
|
|
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutAttachEntity(this, this.getLeashHolder()));
|
|
+ return EnumInteractionResult.PASS;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.setLeashedTo(entityhuman, true);
|
|
itemstack.shrink(1);
|
|
return EnumInteractionResult.sidedSuccess(this.level.isClientSide);
|
|
@@ -1163,7 +1263,7 @@
|
|
if (itemstack.getItem() instanceof ItemMonsterEgg) {
|
|
if (this.level instanceof WorldServer) {
|
|
ItemMonsterEgg itemmonsteregg = (ItemMonsterEgg) itemstack.getItem();
|
|
- Optional<EntityInsentient> optional = itemmonsteregg.spawnOffspringFromSpawnEgg(entityhuman, this, this.getType(), (WorldServer) this.level, this.position(), itemstack);
|
|
+ Optional<EntityInsentient> optional = itemmonsteregg.spawnOffspringFromSpawnEgg(entityhuman, this, (EntityTypes<? extends EntityInsentient>) this.getType(), (WorldServer) this.level, this.position(), itemstack); // CraftBukkit - decompile error
|
|
|
|
optional.ifPresent((entityinsentient) -> {
|
|
this.onOffspringSpawnedFromEgg(entityhuman, entityinsentient);
|
|
@@ -1213,12 +1313,19 @@
|
|
return this.restrictRadius != -1.0F;
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
@Nullable
|
|
public <T extends EntityInsentient> T convertTo(EntityTypes<T> entitytypes, boolean flag) {
|
|
+ return this.convertTo(entitytypes, flag, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT);
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ public <T extends EntityInsentient> T convertTo(EntityTypes<T> entitytypes, boolean flag, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
|
|
+ // CraftBukkit end
|
|
if (this.isRemoved()) {
|
|
return null;
|
|
} else {
|
|
- T t0 = (EntityInsentient) entitytypes.create(this.level);
|
|
+ T t0 = entitytypes.create(this.level); // CraftBukkit - decompile error
|
|
|
|
t0.copyPosition(this);
|
|
t0.setBaby(this.isBaby());
|
|
@@ -1250,7 +1357,12 @@
|
|
}
|
|
}
|
|
|
|
- this.level.addFreshEntity(t0);
|
|
+ // CraftBukkit start
|
|
+ if (CraftEventFactory.callEntityTransformEvent(this, t0, transformReason).isCancelled()) {
|
|
+ return null;
|
|
+ }
|
|
+ this.level.addFreshEntity(t0, spawnReason);
|
|
+ // CraftBukkit end
|
|
if (this.isPassenger()) {
|
|
Entity entity = this.getVehicle();
|
|
|
|
@@ -1270,6 +1382,7 @@
|
|
|
|
if (this.leashHolder != null) {
|
|
if (!this.isAlive() || !this.leashHolder.isAlive()) {
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), (!this.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE)); // CraftBukkit
|
|
this.dropLeash(true, true);
|
|
}
|
|
|
|
@@ -1281,7 +1394,9 @@
|
|
this.leashHolder = null;
|
|
this.leashInfoTag = null;
|
|
if (!this.level.isClientSide && flag1) {
|
|
+ this.forceDrops = true; // CraftBukkit
|
|
this.spawnAtLocation((IMaterial) Items.LEAD);
|
|
+ this.forceDrops = false; // CraftBukkit
|
|
}
|
|
|
|
if (!this.level.isClientSide && flag && this.level instanceof WorldServer) {
|
|
@@ -1331,6 +1446,7 @@
|
|
boolean flag1 = super.startRiding(entity, flag);
|
|
|
|
if (flag1 && this.isLeashed()) {
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
|
|
this.dropLeash(true, true);
|
|
}
|
|
|
|
@@ -1355,7 +1471,9 @@
|
|
}
|
|
|
|
if (this.tickCount > 100) {
|
|
+ this.forceDrops = true; // CraftBukkit
|
|
this.spawnAtLocation((IMaterial) Items.LEAD);
|
|
+ this.forceDrops = false; // CraftBukkit
|
|
this.leashInfoTag = null;
|
|
}
|
|
}
|
|
@@ -1432,7 +1550,14 @@
|
|
int i = EnchantmentManager.getFireAspect(this);
|
|
|
|
if (i > 0) {
|
|
- entity.setSecondsOnFire(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);
|
|
+
|
|
+ if (!combustEvent.isCancelled()) {
|
|
+ entity.setSecondsOnFire(combustEvent.getDuration(), false);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
boolean flag = entity.hurt(DamageSource.mobAttack(this), f);
|
|
@@ -1500,9 +1625,10 @@
|
|
@Override
|
|
protected void removeAfterChangingDimensions() {
|
|
super.removeAfterChangingDimensions();
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
|
|
this.dropLeash(true, false);
|
|
this.getAllSlots().forEach((itemstack) -> {
|
|
- itemstack.setCount(0);
|
|
+ if (!itemstack.isEmpty()) itemstack.setCount(0); // CraftBukkit
|
|
});
|
|
}
|
|
|