From ff9cf280c2989c55c4c8383c1d8773886c2d7f11 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 14 Dec 2024 19:16:30 +0100 Subject: [PATCH] net.minecraft.world.entity.animal.{armadillo|camel|sniffer} --- .../animal/armadillo/Armadillo.java.patch | 46 +++++++++++ .../entity/animal/camel/Camel.java.patch | 46 +++-------- .../entity/animal/sniffer/Sniffer.java.patch | 36 +++++++++ .../animal/armadillo/Armadillo.java.patch | 81 ------------------- .../entity/animal/sniffer/Sniffer.java.patch | 56 ------------- 5 files changed, 94 insertions(+), 171 deletions(-) create mode 100644 paper-server/patches/sources/net/minecraft/world/entity/animal/armadillo/Armadillo.java.patch rename paper-server/patches/{unapplied => sources}/net/minecraft/world/entity/animal/camel/Camel.java.patch (62%) create mode 100644 paper-server/patches/sources/net/minecraft/world/entity/animal/sniffer/Sniffer.java.patch delete mode 100644 paper-server/patches/unapplied/net/minecraft/world/entity/animal/armadillo/Armadillo.java.patch delete mode 100644 paper-server/patches/unapplied/net/minecraft/world/entity/animal/sniffer/Sniffer.java.patch diff --git a/paper-server/patches/sources/net/minecraft/world/entity/animal/armadillo/Armadillo.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/animal/armadillo/Armadillo.java.patch new file mode 100644 index 0000000000..95199daa53 --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/entity/animal/armadillo/Armadillo.java.patch @@ -0,0 +1,46 @@ +--- a/net/minecraft/world/entity/animal/armadillo/Armadillo.java ++++ b/net/minecraft/world/entity/animal/armadillo/Armadillo.java +@@ -141,10 +_,12 @@ + ArmadilloAi.updateActivity(this); + profilerFiller.pop(); + if (this.isAlive() && !this.isBaby() && --this.scuteTime <= 0) { ++ this.forceDrops = true; // CraftBukkit + if (this.dropFromGiftLootTable(level, BuiltInLootTables.ARMADILLO_SHED, this::spawnAtLocation)) { + this.playSound(SoundEvents.ARMADILLO_SCUTE_DROP, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); + this.gameEvent(GameEvent.ENTITY_PLACE); + } ++ this.forceDrops = false; // CraftBukkit + + this.scuteTime = this.pickNextScuteDropTime(); + } +@@ -283,7 +_,11 @@ + } + + @Override +- protected void actuallyHurt(ServerLevel level, DamageSource damageSource, float amount) { ++ // CraftBukkit start - void -> boolean ++ public boolean actuallyHurt(ServerLevel level, DamageSource damageSource, float amount, org.bukkit.event.entity.EntityDamageEvent event) { ++ boolean damageResult = super.actuallyHurt(level, damageSource, amount, event); ++ if (!damageResult) return false; ++ // CraftBukkit end + super.actuallyHurt(level, damageSource, amount); + if (!this.isNoAi() && !this.isDeadOrDying()) { + if (damageSource.getEntity() instanceof LivingEntity) { +@@ -295,6 +_,7 @@ + this.rollOut(); + } + } ++ return true; // CraftBukkit + } + + @Override +@@ -313,7 +_,9 @@ + return false; + } else { + if (this.level() instanceof ServerLevel serverLevel) { ++ this.forceDrops = true; // CraftBukkit + this.spawnAtLocation(serverLevel, new ItemStack(Items.ARMADILLO_SCUTE)); ++ this.forceDrops = false; // CraftBukkit + this.gameEvent(GameEvent.ENTITY_INTERACT); + this.playSound(SoundEvents.ARMADILLO_BRUSH); + } diff --git a/paper-server/patches/unapplied/net/minecraft/world/entity/animal/camel/Camel.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/animal/camel/Camel.java.patch similarity index 62% rename from paper-server/patches/unapplied/net/minecraft/world/entity/animal/camel/Camel.java.patch rename to paper-server/patches/sources/net/minecraft/world/entity/animal/camel/Camel.java.patch index e2b9543713..2ca2c4bbf8 100644 --- a/paper-server/patches/unapplied/net/minecraft/world/entity/animal/camel/Camel.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/animal/camel/Camel.java.patch @@ -1,59 +1,37 @@ --- a/net/minecraft/world/entity/animal/camel/Camel.java +++ b/net/minecraft/world/entity/animal/camel/Camel.java -@@ -49,6 +49,9 @@ - import net.minecraft.world.level.gameevent.GameEvent; - import net.minecraft.world.phys.Vec2; - import net.minecraft.world.phys.Vec3; -+// CraftBukkit start -+import org.bukkit.event.entity.EntityDamageEvent; -+// CraftBukkit end - - public class Camel extends AbstractHorse { - -@@ -143,7 +146,7 @@ - ProfilerFiller gameprofilerfiller = Profiler.get(); - - gameprofilerfiller.push("camelBrain"); -- Brain behaviorcontroller = this.getBrain(); -+ Brain behaviorcontroller = (Brain) this.getBrain(); // CraftBukkit - decompile error - - behaviorcontroller.tick(world, this); - gameprofilerfiller.pop(); -@@ -386,13 +389,13 @@ +@@ -386,12 +_,12 @@ + } else { boolean flag = this.getHealth() < this.getMaxHealth(); - if (flag) { - this.heal(2.0F); + this.heal(2.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.EATING); // Paper - Add missing regain reason } boolean flag1 = this.isTamed() && this.getAge() == 0 && this.canFallInLove(); - if (flag1) { - this.setInLove(player); + this.setInLove(player, item.copy()); // Paper - Fix EntityBreedEvent copying } - boolean flag2 = this.isBaby(); -@@ -454,9 +457,15 @@ + boolean isBaby = this.isBaby(); +@@ -451,9 +_,13 @@ } @Override -- protected void actuallyHurt(ServerLevel world, DamageSource source, float amount) { +- protected void actuallyHurt(ServerLevel level, DamageSource damageSource, float amount) { + // CraftBukkit start - void -> boolean -+ public boolean actuallyHurt(ServerLevel worldserver, DamageSource damagesource, float f, EntityDamageEvent event) { -+ boolean damageResult = super.actuallyHurt(worldserver, damagesource, f, event); -+ if (!damageResult) { -+ return false; -+ } ++ public boolean actuallyHurt(ServerLevel level, DamageSource damageSource, float amount, org.bukkit.event.entity.EntityDamageEvent event) { ++ boolean damageResult = super.actuallyHurt(level, damageSource, amount, event); ++ if (!damageResult) return false; + // CraftBukkit end this.standUpInstantly(); -- super.actuallyHurt(world, source, amount); +- super.actuallyHurt(level, damageSource, amount); + return true; // CraftBukkit } @Override -@@ -563,7 +572,7 @@ +@@ -554,7 +_,7 @@ } public void sitDown() { @@ -62,7 +40,7 @@ this.makeSound(SoundEvents.CAMEL_SIT); this.setPose(Pose.SITTING); this.gameEvent(GameEvent.ENTITY_ACTION); -@@ -572,7 +581,7 @@ +@@ -563,7 +_,7 @@ } public void standUp() { @@ -71,7 +49,7 @@ this.makeSound(SoundEvents.CAMEL_STAND); this.setPose(Pose.STANDING); this.gameEvent(GameEvent.ENTITY_ACTION); -@@ -581,6 +590,7 @@ +@@ -572,6 +_,7 @@ } public void standUpInstantly() { diff --git a/paper-server/patches/sources/net/minecraft/world/entity/animal/sniffer/Sniffer.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/animal/sniffer/Sniffer.java.patch new file mode 100644 index 0000000000..0e059e7e5c --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/entity/animal/sniffer/Sniffer.java.patch @@ -0,0 +1,36 @@ +--- a/net/minecraft/world/entity/animal/sniffer/Sniffer.java ++++ b/net/minecraft/world/entity/animal/sniffer/Sniffer.java +@@ -266,6 +_,13 @@ + BlockPos headBlock = this.getHeadBlock(); + this.dropFromGiftLootTable(serverLevel, BuiltInLootTables.SNIFFER_DIGGING, (serverLevel1, itemStack) -> { + ItemEntity itemEntity = new ItemEntity(this.level(), headBlock.getX(), headBlock.getY(), headBlock.getZ(), itemStack); ++ // CraftBukkit start - handle EntityDropItemEvent ++ org.bukkit.event.entity.EntityDropItemEvent event = new org.bukkit.event.entity.EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) itemEntity.getBukkitEntity()); ++ org.bukkit.Bukkit.getPluginManager().callEvent(event); ++ if (event.isCancelled()) { ++ return; ++ } ++ // CraftBukkit end + itemEntity.setDefaultPickUpDelay(); + serverLevel1.addFreshEntity(itemEntity); + }); +@@ -325,12 +_,17 @@ + + @Override + public void spawnChildFromBreeding(ServerLevel level, Animal mate) { ++ // Paper start - Add EntityFertilizeEggEvent event ++ final io.papermc.paper.event.entity.EntityFertilizeEggEvent result = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityFertilizeEggEvent(this, mate); ++ if (result.isCancelled()) return; ++ // Paper end - Add EntityFertilizeEggEvent event + ItemStack itemStack = new ItemStack(Items.SNIFFER_EGG); + ItemEntity itemEntity = new ItemEntity(level, this.position().x(), this.position().y(), this.position().z(), itemStack); + itemEntity.setDefaultPickUpDelay(); +- this.finalizeSpawnChildFromBreeding(level, mate, null); ++ this.finalizeSpawnChildFromBreeding(level, mate, null, result.getExperience()); // Paper - Add EntityFertilizeEggEvent event ++ if (this.spawnAtLocation(level, itemEntity) != null) { // Paper - Call EntityDropItemEvent + this.playSound(SoundEvents.SNIFFER_EGG_PLOP, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 0.5F); +- level.addFreshEntity(itemEntity); ++ } // Paper - Call EntityDropItemEvent + } + + @Override diff --git a/paper-server/patches/unapplied/net/minecraft/world/entity/animal/armadillo/Armadillo.java.patch b/paper-server/patches/unapplied/net/minecraft/world/entity/animal/armadillo/Armadillo.java.patch deleted file mode 100644 index 2e72adb5ea..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/world/entity/animal/armadillo/Armadillo.java.patch +++ /dev/null @@ -1,81 +0,0 @@ ---- a/net/minecraft/world/entity/animal/armadillo/Armadillo.java -+++ b/net/minecraft/world/entity/animal/armadillo/Armadillo.java -@@ -47,6 +47,9 @@ - import net.minecraft.world.level.block.state.BlockState; - import net.minecraft.world.level.gameevent.GameEvent; - import net.minecraft.world.level.storage.loot.BuiltInLootTables; -+// CraftBukkit start -+import org.bukkit.event.entity.EntityDamageEvent; -+// CraftBukkit end - - public class Armadillo extends Animal { - -@@ -135,16 +138,18 @@ - ProfilerFiller gameprofilerfiller = Profiler.get(); - - gameprofilerfiller.push("armadilloBrain"); -- this.brain.tick(world, this); -+ ((Brain) this.brain).tick(world, this); // CraftBukkit - decompile error - gameprofilerfiller.pop(); - gameprofilerfiller.push("armadilloActivityUpdate"); - ArmadilloAi.updateActivity(this); - gameprofilerfiller.pop(); - if (this.isAlive() && !this.isBaby() && --this.scuteTime <= 0) { -+ this.forceDrops = true; // CraftBukkit - if (this.dropFromGiftLootTable(world, BuiltInLootTables.ARMADILLO_SHED, this::spawnAtLocation)) { - this.playSound(SoundEvents.ARMADILLO_SCUTE_DROP, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); - this.gameEvent(GameEvent.ENTITY_PLACE); - } -+ this.forceDrops = false; // CraftBukkit - - this.scuteTime = this.pickNextScuteDropTime(); - } -@@ -291,19 +296,25 @@ - } - - @Override -- protected void actuallyHurt(ServerLevel world, DamageSource source, float amount) { -- super.actuallyHurt(world, source, amount); -+ // CraftBukkit start - void -> boolean -+ public boolean actuallyHurt(ServerLevel worldserver, DamageSource damagesource, float f, EntityDamageEvent event) { -+ boolean damageResult = super.actuallyHurt(worldserver, damagesource, f, event); -+ if (!damageResult) { -+ return false; -+ } -+ // CraftBukkit end - if (!this.isNoAi() && !this.isDeadOrDying()) { -- if (source.getEntity() instanceof LivingEntity) { -+ if (damagesource.getEntity() instanceof LivingEntity) { - this.getBrain().setMemoryWithExpiry(MemoryModuleType.DANGER_DETECTED_RECENTLY, true, 80L); - if (this.canStayRolledUp()) { - this.rollUp(); - } -- } else if (source.is(DamageTypeTags.PANIC_ENVIRONMENTAL_CAUSES)) { -+ } else if (damagesource.is(DamageTypeTags.PANIC_ENVIRONMENTAL_CAUSES)) { - this.rollOut(); - } - - } -+ return true; // CraftBukkit - } - - @Override -@@ -327,7 +338,9 @@ - if (world instanceof ServerLevel) { - ServerLevel worldserver = (ServerLevel) world; - -+ this.forceDrops = true; // CraftBukkit - this.spawnAtLocation(worldserver, new ItemStack(Items.ARMADILLO_SCUTE)); -+ this.forceDrops = false; // CraftBukkit - this.gameEvent(GameEvent.ENTITY_INTERACT); - this.playSound(SoundEvents.ARMADILLO_BRUSH); - } -@@ -431,7 +444,7 @@ - } - - public static Armadillo.ArmadilloState fromName(String name) { -- return (Armadillo.ArmadilloState) Armadillo.ArmadilloState.CODEC.byName(name, (Enum) Armadillo.ArmadilloState.IDLE); -+ return (Armadillo.ArmadilloState) Armadillo.ArmadilloState.CODEC.byName(name, Armadillo.ArmadilloState.IDLE); // CraftBukkit - decompile error - } - - @Override diff --git a/paper-server/patches/unapplied/net/minecraft/world/entity/animal/sniffer/Sniffer.java.patch b/paper-server/patches/unapplied/net/minecraft/world/entity/animal/sniffer/Sniffer.java.patch deleted file mode 100644 index a6567df470..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/world/entity/animal/sniffer/Sniffer.java.patch +++ /dev/null @@ -1,56 +0,0 @@ ---- a/net/minecraft/world/entity/animal/sniffer/Sniffer.java -+++ b/net/minecraft/world/entity/animal/sniffer/Sniffer.java -@@ -267,6 +267,13 @@ - this.dropFromGiftLootTable(worldserver, BuiltInLootTables.SNIFFER_DIGGING, (worldserver1, itemstack) -> { - ItemEntity entityitem = new ItemEntity(this.level(), (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack); - -+ // CraftBukkit start - handle EntityDropItemEvent -+ org.bukkit.event.entity.EntityDropItemEvent event = new org.bukkit.event.entity.EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity()); -+ org.bukkit.Bukkit.getPluginManager().callEvent(event); -+ if (event.isCancelled()) { -+ return; -+ } -+ // CraftBukkit end - entityitem.setDefaultPickUpDelay(); - worldserver1.addFreshEntity(entityitem); - }); -@@ -308,7 +315,7 @@ - List list = (List) this.getExploredPositions().limit(20L).collect(Collectors.toList()); - - list.add(0, GlobalPos.of(this.level().dimension(), pos)); -- this.getBrain().setMemory(MemoryModuleType.SNIFFER_EXPLORED_POSITIONS, (Object) list); -+ this.getBrain().setMemory(MemoryModuleType.SNIFFER_EXPLORED_POSITIONS, list); // CraftBukkit - decompile error - return this; - } - -@@ -333,13 +340,19 @@ - - @Override - public void spawnChildFromBreeding(ServerLevel world, Animal other) { -+ // Paper start - Add EntityFertilizeEggEvent event -+ final io.papermc.paper.event.entity.EntityFertilizeEggEvent result = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityFertilizeEggEvent(this, other); -+ if (result.isCancelled()) return; -+ // Paper end - Add EntityFertilizeEggEvent event -+ - ItemStack itemstack = new ItemStack(Items.SNIFFER_EGG); - ItemEntity entityitem = new ItemEntity(world, this.position().x(), this.position().y(), this.position().z(), itemstack); - - entityitem.setDefaultPickUpDelay(); -- this.finalizeSpawnChildFromBreeding(world, other, (AgeableMob) null); -+ this.finalizeSpawnChildFromBreeding(world, other, (AgeableMob) null, result.getExperience()); // Paper - Add EntityFertilizeEggEvent event -+ if (this.spawnAtLocation(world, entityitem) != null) { // Paper - Call EntityDropItemEvent - this.playSound(SoundEvents.SNIFFER_EGG_PLOP, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 0.5F); -- world.addFreshEntity(entityitem); -+ } // Paper - Call EntityDropItemEvent - } - - @Override -@@ -444,7 +457,7 @@ - - @Override - public Brain getBrain() { -- return super.getBrain(); -+ return (Brain) super.getBrain(); // CraftBukkit - decompile error - } - - @Override