diff options
Diffstat (limited to 'patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/Mob.java.patch')
-rw-r--r-- | patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/Mob.java.patch | 349 |
1 files changed, 349 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/Mob.java.patch b/patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/Mob.java.patch new file mode 100644 index 0000000000..e998b34007 --- /dev/null +++ b/patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/Mob.java.patch @@ -0,0 +1,349 @@ +--- a/net/minecraft/world/entity/Mob.java ++++ b/net/minecraft/world/entity/Mob.java +@@ -75,6 +76,16 @@ + import net.minecraft.world.level.material.Fluid; + import net.minecraft.world.level.pathfinder.BlockPathTypes; + import net.minecraft.world.phys.AABB; ++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 Mob extends LivingEntity implements Targeting { + +@@ -123,8 +134,10 @@ + private BlockPos restrictCenter; + private float restrictRadius; + +- protected Mob(EntityType<? extends Mob> entitytype, Level level) { +- super(entitytype, level); ++ public boolean aware = true; // CraftBukkit ++ ++ protected Mob(EntityType<? extends Mob> entityType, Level level) { ++ super(entityType, level); + this.handItems = NonNullList.withSize(2, ItemStack.EMPTY); + this.handDropChances = new float[2]; + this.armorItems = NonNullList.withSize(4, ItemStack.EMPTY); +@@ -148,6 +161,12 @@ + + } + ++ // CraftBukkit start ++ public void setPersistenceRequired(boolean persistenceRequired) { ++ this.persistenceRequired = persistenceRequired; ++ } ++ // CraftBukkit end ++ + protected void registerGoals() {} + + public static AttributeSupplier.Builder createMobAttributes() { +@@ -260,10 +277,41 @@ + return this.target; + } + +- public void setTarget(@Nullable LivingEntity livingentity) { +- this.target = livingentity; ++ public void setTarget(@Nullable LivingEntity target) { ++ // CraftBukkit start - fire event ++ setTarget(target, EntityTargetEvent.TargetReason.UNKNOWN, true); + } + ++ public boolean setTarget(LivingEntity 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) { ++ this.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); ++ this.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 + @Override + public boolean canAttackType(EntityType<?> entitytype) { +@@ -409,6 +449,12 @@ + return null; + } + ++ // CraftBukkit start - Add delegate method ++ public SoundEvent getAmbientSound0() { ++ return getAmbientSound(); ++ } ++ // CraftBukkit end ++ + @Override + @Override + public void addAdditionalSaveData(CompoundTag compoundtag) { +@@ -467,9 +512,9 @@ + listtag3.add(FloatTag.valueOf(f1)); + } + +- compoundtag.put("HandDropChances", listtag3); +- if (this.leashHolder != null) { +- compoundtag2 = new CompoundTag(); ++ compound.put("HandDropChances", nbttaglist3); ++ if (this.leashHolder != null && !this.leashHolder.pluginRemoved) { // CraftBukkit - SPIGOT-7487: Don't save (and possible drop) leash, when the holder was removed by a plugin ++ nbttagcompound2 = new CompoundTag(); + if (this.leashHolder instanceof LivingEntity) { + UUID uuid = this.leashHolder.getUUID(); + +@@ -499,18 +544,27 @@ + compoundtag.putBoolean("NoAI", this.isNoAi()); + } + ++ compound.putBoolean("Bukkit.Aware", this.aware); // CraftBukkit + } + + @Override +- @Override +- public void readAdditionalSaveData(CompoundTag compoundtag) { +- super.readAdditionalSaveData(compoundtag); +- if (compoundtag.contains("CanPickUpLoot", 1)) { +- this.setCanPickUpLoot(compoundtag.getBoolean("CanPickUpLoot")); ++ public void readAdditionalSaveData(CompoundTag compound) { ++ super.readAdditionalSaveData(compound); ++ ++ // CraftBukkit start - If looting or persistence is false only use it if it was set after we started using it ++ if (compound.contains("CanPickUpLoot", 1)) { ++ boolean data = compound.getBoolean("CanPickUpLoot"); ++ if (isLevelAtLeast(compound, 1) || data) { ++ this.setCanPickUpLoot(data); ++ } + } + +- this.persistenceRequired = compoundtag.getBoolean("PersistenceRequired"); +- ListTag listtag; ++ boolean data = compound.getBoolean("PersistenceRequired"); ++ if (isLevelAtLeast(compound, 1) || data) { ++ this.persistenceRequired = data; ++ } ++ // CraftBukkit end ++ ListTag nbttaglist; + int i; + + if (compoundtag.contains("ArmorItems", 9)) { +@@ -555,7 +609,12 @@ + this.lootTableSeed = compoundtag.getLong("DeathLootTableSeed"); + } + +- this.setNoAi(compoundtag.getBoolean("NoAI")); ++ this.setNoAi(compound.getBoolean("NoAI")); ++ // CraftBukkit start ++ if (compound.contains("Bukkit.Aware")) { ++ this.aware = compound.getBoolean("Bukkit.Aware"); ++ } ++ // CraftBukkit end + } + + @Override +@@ -626,9 +680,9 @@ + return Mob.ITEM_PICKUP_REACH; + } + +- protected void pickUpItem(ItemEntity itementity) { +- ItemStack itemstack = itementity.getItem(); +- ItemStack itemstack1 = this.equipItemIfPossible(itemstack.copy()); ++ protected void pickUpItem(ItemEntity itemEntity) { ++ ItemStack itemstack = itemEntity.getItem(); ++ ItemStack itemstack1 = this.equipItemIfPossible(itemstack.copy(), itemEntity); // CraftBukkit - add item + + if (!itemstack1.isEmpty()) { + this.onItemPickup(itementity); +@@ -641,9 +695,15 @@ + + } + +- public ItemStack equipItemIfPossible(ItemStack itemstack) { +- EquipmentSlot equipmentslot = getEquipmentSlotForItem(itemstack); +- ItemStack itemstack1 = this.getItemBySlot(equipmentslot); ++ public ItemStack equipItemIfPossible(ItemStack stack) { ++ // CraftBukkit start - add item ++ return this.equipItemIfPossible(stack, null); ++ } ++ ++ public ItemStack equipItemIfPossible(ItemStack itemstack, ItemEntity entityitem) { ++ // CraftBukkit end ++ EquipmentSlot enumitemslot = getEquipmentSlotForItem(itemstack); ++ ItemStack itemstack1 = this.getItemBySlot(enumitemslot); + boolean flag = this.canReplaceCurrentItem(itemstack, itemstack1); + + if (equipmentslot.isArmor() && !flag) { +@@ -652,11 +712,19 @@ + flag = itemstack1.isEmpty(); + } + +- if (flag && this.canHoldItem(itemstack)) { +- double d0 = (double) this.getEquipmentDropChance(equipmentslot); ++ // 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 + } + + if (equipmentslot.isArmor() && itemstack.getCount() > 1) { +@@ -810,6 +876,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(); +@@ -1211,6 +1270,12 @@ + if (!this.isAlive()) { + return InteractionResult.PASS; + } else if (this.getLeashHolder() == player) { ++ // CraftBukkit start - fire PlayerUnleashEntityEvent ++ if (CraftEventFactory.callPlayerUnleashEntityEvent(this, player, hand).isCancelled()) { ++ ((ServerPlayer) player).connection.send(new ClientboundSetEntityLinkPacket(this, this.getLeashHolder())); ++ return InteractionResult.PASS; ++ } ++ // CraftBukkit end + this.dropLeash(true, !player.getAbilities().instabuild); + this.gameEvent(GameEvent.ENTITY_INTERACT, player); + return InteractionResult.sidedSuccess(this.level().isClientSide); +@@ -1236,6 +1301,12 @@ + ItemStack itemstack = player.getItemInHand(interactionhand); + + if (itemstack.is(Items.LEAD) && this.canBeLeashed(player)) { ++ // CraftBukkit start - fire PlayerLeashEntityEvent ++ if (CraftEventFactory.callPlayerLeashEntityEvent(this, player, player, hand).isCancelled()) { ++ ((ServerPlayer) player).connection.send(new ClientboundSetEntityLinkPacket(this, this.getLeashHolder())); ++ return InteractionResult.PASS; ++ } ++ // CraftBukkit end + this.setLeashedTo(player, true); + itemstack.shrink(1); + return InteractionResult.sidedSuccess(this.level().isClientSide); +@@ -1301,8 +1372,15 @@ + return this.restrictRadius != -1.0F; + } + ++ // CraftBukkit start + @Nullable +- public <T extends Mob> T convertTo(EntityType<T> entitytype, boolean flag) { ++ public <T extends Mob> T convertTo(EntityType<T> entityType, boolean transferInventory) { ++ return this.convertTo(entityType, transferInventory, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT); ++ } ++ ++ @Nullable ++ public <T extends Mob> T convertTo(EntityType<T> entitytypes, boolean flag, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) { ++ // CraftBukkit end + if (this.isRemoved()) { + return null; + } else { +@@ -1340,7 +1418,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(); + +@@ -1361,7 +1444,8 @@ + + if (this.leashHolder != null) { + if (!this.isAlive() || !this.leashHolder.isAlive()) { +- this.dropLeash(true, true); ++ this.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), (!this.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE)); // CraftBukkit ++ this.dropLeash(true, !this.leashHolder.pluginRemoved);// CraftBukkit - SPIGOT-7487: Don't drop leash, when the holder was removed by a plugin + } + + } +@@ -1371,8 +1455,10 @@ + if (this.leashHolder != null) { + this.leashHolder = null; + this.leashInfoTag = null; +- if (!this.level().isClientSide && flag1) { +- this.spawnAtLocation((ItemLike) Items.LEAD); ++ if (!this.level().isClientSide && dropLeash) { ++ this.forceDrops = true; // CraftBukkit ++ this.spawnAtLocation((IMaterial) Items.LEAD); ++ this.forceDrops = false; // CraftBukkit + } + + if (!this.level().isClientSide && flag && this.level() instanceof ServerLevel) { +@@ -1423,6 +1508,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); + } + +@@ -1447,7 +1533,9 @@ + } + + if (this.tickCount > 100) { +- this.spawnAtLocation((ItemLike) Items.LEAD); ++ this.forceDrops = true; // CraftBukkit ++ this.spawnAtLocation((IMaterial) Items.LEAD); ++ this.forceDrops = false; // CraftBukkit + this.leashInfoTag = null; + } + } +@@ -1532,7 +1617,14 @@ + int i = EnchantmentHelper.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(this.damageSources().mobAttack(this), f); +@@ -1609,6 +1699,7 @@ + @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) -> { + if (!itemstack.isEmpty()) { |