3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-23 23:00:08 +01:00
Paper/nms-patches/EntityInsentient.patch

320 Zeilen
13 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityInsentient.java
+++ b/net/minecraft/server/EntityInsentient.java
2020-06-25 02:00:00 +02:00
@@ -10,6 +10,18 @@
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;
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;
+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;
+import org.bukkit.event.entity.EntityUnleashEvent;
+import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
+// CraftBukkit end
+
public abstract class EntityInsentient extends EntityLiving {
2019-04-23 04:00:00 +02:00
private static final DataWatcherObject<Byte> b = DataWatcher.a(EntityInsentient.class, DataWatcherRegistry.a);
2020-06-25 02:00:00 +02:00
@@ -28,7 +40,7 @@
2019-04-23 04:00:00 +02:00
public final float[] dropChanceHand;
2020-06-25 02:00:00 +02:00
private final NonNullList<ItemStack> bx;
2019-04-23 04:00:00 +02:00
public final float[] dropChanceArmor;
- private boolean canPickUpLoot;
+ // private boolean canPickUpLoot; // CraftBukkit - moved up to EntityLiving
public boolean persistent;
2020-06-25 02:00:00 +02:00
private final Map<PathType, Float> bA;
2018-08-26 04:00:00 +02:00
public MinecraftKey lootTableKey;
2020-06-25 02:00:00 +02:00
@@ -41,6 +53,8 @@
private BlockPosition bG;
private float bH;
+ public boolean aware = true; // CraftBukkit
+
protected EntityInsentient(EntityTypes<? extends EntityInsentient> entitytypes, World world) {
super(entitytypes, world);
2020-06-25 02:00:00 +02:00
this.bw = NonNullList.a(2, ItemStack.b);
@@ -64,6 +78,9 @@
2019-04-23 04:00:00 +02:00
this.initPathfinder();
}
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - default persistance to type's persistance value
2019-04-23 04:00:00 +02:00
+ this.persistent = !isTypeNotPersistent(0);
+ // CraftBukkit end
}
2019-04-23 04:00:00 +02:00
protected void initPathfinder() {}
2020-06-25 02:00:00 +02:00
@@ -144,7 +161,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
}
2019-04-23 04:00:00 +02:00
@Override
2020-06-25 02:00:00 +02:00
@@ -361,16 +409,26 @@
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
+
+ // 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"));
+ boolean data = nbttagcompound.getBoolean("CanPickUpLoot");
+ if (isLevelAtLeast(nbttagcompound, 1) || data) {
2019-04-23 04:00:00 +02:00
+ this.setCanPickupLoot(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;
2020-06-25 02:00:00 +02:00
@@ -417,6 +475,11 @@
}
this.setNoAI(nbttagcompound.getBoolean("NoAI"));
+ // CraftBukkit start
+ if (nbttagcompound.hasKey("Bukkit.Aware")) {
+ this.aware = nbttagcompound.getBoolean("Bukkit.Aware");
+ }
+ // CraftBukkit end
}
@Override
2020-06-25 02:00:00 +02:00
@@ -424,6 +487,11 @@
2019-04-23 04:00:00 +02:00
super.a(damagesource, flag);
this.lootTableKey = null;
2018-08-12 10:39:51 +02:00
}
+ // 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
2019-04-23 04:00:00 +02:00
@Override
protected LootTableInfo.Builder a(boolean flag, DamageSource damagesource) {
2020-06-25 02:00:00 +02:00
@@ -480,7 +548,7 @@
protected void b(EntityItem entityitem) {
ItemStack itemstack = entityitem.getItemStack();
- if (this.g(itemstack)) {
+ if (this.g(itemstack, entityitem)) { // CraftBukkit - add item
this.a(entityitem);
this.receive(entityitem, itemstack.getCount());
entityitem.die();
@@ -489,15 +557,29 @@
}
public boolean g(ItemStack itemstack) {
+ // CraftBukkit start - add item
+ return this.g(itemstack, null);
+ }
+
+ public boolean g(ItemStack itemstack, EntityItem entityitem) {
+ // CraftBukkit end
EnumItemSlot enumitemslot = j(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);
2020-06-25 02:00:00 +02:00
- if (flag && this.canPickup(itemstack)) {
+ // 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();
+ }
+ if (canPickup) {
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
double d0 = (double) this.e(enumitemslot);
2019-12-10 23:00:00 +01:00
if (!itemstack1.isEmpty() && (double) Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d0) {
+ this.forceDrops = true; // CraftBukkit
2019-04-23 04:00:00 +02:00
this.a(itemstack1);
+ this.forceDrops = false; // CraftBukkit
}
2020-06-25 02:00:00 +02:00
this.b(enumitemslot, itemstack);
@@ -610,18 +692,18 @@
EntityHuman entityhuman = this.world.findNearbyPlayer(this, -1.0D);
2019-04-23 04:00:00 +02:00
if (entityhuman != null) {
2020-06-25 02:00:00 +02:00
- double d0 = entityhuman.h(this);
+ double d0 = entityhuman.h((Entity) this); // CraftBukkit - decompile error
int i = this.getEntityType().e().f();
int j = i * i;
2020-06-25 02:00:00 +02:00
- if (d0 > (double) j && this.isTypeNotPersistent(d0)) {
+ if (d0 > (double) j) { // CraftBukkit - remove isTypeNotPersistent() check
this.die();
}
2020-06-25 02:00:00 +02:00
int k = this.getEntityType().e().g();
int l = k * k;
- if (this.ticksFarFromPlayer > 600 && this.random.nextInt(800) == 0 && d0 > (double) l && this.isTypeNotPersistent(d0)) {
+ if (this.ticksFarFromPlayer > 600 && this.random.nextInt(800) == 0 && d0 > (double) l) { // CraftBukkit - remove isTypeNotPersistent() check
this.die();
2020-06-25 02:00:00 +02:00
} else if (d0 < (double) l) {
2015-02-26 23:41:06 +01:00
this.ticksFarFromPlayer = 0;
2020-06-25 02:00:00 +02:00
@@ -636,6 +718,7 @@
@Override
protected final void doTick() {
++this.ticksFarFromPlayer;
+ if (!this.aware) return; // CraftBukkit
this.world.getMethodProfiler().enter("sensing");
2020-06-25 02:00:00 +02:00
this.bv.a();
this.world.getMethodProfiler().exit();
2020-06-25 02:00:00 +02:00
@@ -1014,6 +1097,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) {
+ // 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()));
2020-06-25 02:00:00 +02:00
+ return EnumInteractionResult.PASS;
+ }
+ // CraftBukkit end
this.unleash(true, !entityhuman.abilities.canInstantlyBuild);
2020-06-25 02:00:00 +02:00
return EnumInteractionResult.a(this.world.isClientSide);
} else {
@@ -1032,6 +1121,12 @@
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 EnumInteractionResult.PASS;
+ }
+ // CraftBukkit end
this.setLeashHolder(entityhuman, true);
itemstack.subtract(1);
return EnumInteractionResult.a(this.world.isClientSide);
@@ -1047,7 +1142,7 @@
if (itemstack.getItem() instanceof ItemMonsterEgg) {
if (!this.world.isClientSide) {
ItemMonsterEgg itemmonsteregg = (ItemMonsterEgg) itemstack.getItem();
- Optional<EntityInsentient> optional = itemmonsteregg.a(entityhuman, this, this.getEntityType(), this.world, this.getPositionVector(), itemstack);
+ Optional<EntityInsentient> optional = itemmonsteregg.a(entityhuman, this, (EntityTypes<? extends EntityInsentient>) this.getEntityType(), this.world, this.getPositionVector(), itemstack); // CraftBukkit - decompile error
optional.ifPresent((entityinsentient) -> {
this.a(entityhuman, entityinsentient);
@@ -1098,7 +1193,7 @@
if (this.dead) {
return null;
2016-11-17 02:41:03 +01:00
} else {
2020-06-25 02:00:00 +02:00
- T t0 = (EntityInsentient) entitytypes.a(this.world);
+ T t0 = entitytypes.a(this.world); // CraftBukkit - decompile error
t0.u(this);
t0.setCanPickupLoot(this.canPickupLoot());
@@ -1128,7 +1223,12 @@
}
}
- this.world.addEntity(t0);
+ // CraftBukkit start
+ if (CraftEventFactory.callEntityTransformEvent(this, t0, EntityTransformEvent.TransformReason.DROWNED).isCancelled()) {
+ return null;
+ }
+ this.world.addEntity(t0, CreatureSpawnEvent.SpawnReason.DROWNED);
+ // CraftBukkit end
this.die();
return t0;
}
@@ -1141,6 +1241,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()) {
+ this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), (!this.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE)); // CraftBukkit
this.unleash(true, true);
}
2020-06-25 02:00:00 +02:00
@@ -1157,7 +1258,9 @@
this.leashHolder = null;
2020-06-25 02:00:00 +02:00
this.bF = null;
if (!this.world.isClientSide && flag1) {
+ this.forceDrops = true; // CraftBukkit
2018-07-15 02:00:00 +02:00
this.a((IMaterial) Items.LEAD);
+ this.forceDrops = false; // CraftBukkit
}
if (!this.world.isClientSide && flag && this.world instanceof WorldServer) {
2020-06-25 02:00:00 +02:00
@@ -1207,6 +1310,7 @@
boolean flag1 = super.a(entity, flag);
2020-06-25 02:00:00 +02:00
if (flag1 && this.isLeashed()) {
+ this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
this.unleash(true, true);
}
2019-04-23 04:00:00 +02:00
2020-06-25 02:00:00 +02:00
@@ -1339,7 +1443,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);
2020-06-25 02:00:00 +02:00
@@ -1401,6 +1512,7 @@
@Override
protected void bJ() {
super.bJ();
+ this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
this.unleash(true, false);
}
}