From 016503a85fa10b27ae06974bcdd0271e58aba7a1 Mon Sep 17 00:00:00 2001 From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Sat, 14 Dec 2024 12:28:42 -0500 Subject: [PATCH] net/minecraft/world/entity/animal/goat/ --- .../world/entity/animal/goat/Goat.java.patch | 51 +++++++++++++ .../world/entity/animal/goat/Goat.java.patch | 76 ------------------- 2 files changed, 51 insertions(+), 76 deletions(-) create mode 100644 paper-server/patches/sources/net/minecraft/world/entity/animal/goat/Goat.java.patch delete mode 100644 paper-server/patches/unapplied/net/minecraft/world/entity/animal/goat/Goat.java.patch diff --git a/paper-server/patches/sources/net/minecraft/world/entity/animal/goat/Goat.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/animal/goat/Goat.java.patch new file mode 100644 index 0000000000..0c41c3aea7 --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/entity/animal/goat/Goat.java.patch @@ -0,0 +1,51 @@ +--- a/net/minecraft/world/entity/animal/goat/Goat.java ++++ b/net/minecraft/world/entity/animal/goat/Goat.java +@@ -231,13 +_,22 @@ + public InteractionResult mobInteract(Player player, InteractionHand hand) { + ItemStack itemInHand = player.getItemInHand(hand); + if (itemInHand.is(Items.BUCKET) && !this.isBaby()) { ++ // CraftBukkit start - Got milk? ++ org.bukkit.event.player.PlayerBucketFillEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) player.level(), player, this.blockPosition(), this.blockPosition(), null, itemInHand, Items.MILK_BUCKET, hand); ++ ++ if (event.isCancelled()) { ++ player.containerMenu.sendAllDataToRemote(); // Paper - Fix inventory desync ++ return InteractionResult.PASS; ++ } ++ // CraftBukkit end + player.playSound(this.getMilkingSound(), 1.0F, 1.0F); +- ItemStack itemStack = ItemUtils.createFilledResult(itemInHand, player, Items.MILK_BUCKET.getDefaultInstance()); ++ ItemStack itemStack = ItemUtils.createFilledResult(itemInHand, player, org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit + player.setItemInHand(hand, itemStack); + return InteractionResult.SUCCESS; + } else { ++ boolean isFood = this.isFood(itemInHand); // Paper - track before stack is possibly decreased to 0 (Fixes MC-244739) + InteractionResult interactionResult = super.mobInteract(player, hand); +- if (interactionResult.consumesAction() && this.isFood(itemInHand)) { ++ if (interactionResult.consumesAction() && isFood) { // Paper + this.playEatingSound(); + } + +@@ -350,7 +_,7 @@ + double d2 = Mth.randomBetween(this.random, -0.2F, 0.2F); + ItemEntity itemEntity = new ItemEntity(this.level(), vec3.x(), vec3.y(), vec3.z(), itemStack, d, d1, d2); + this.level().addFreshEntity(itemEntity); +- return true; ++ return this.spawnAtLocation((net.minecraft.server.level.ServerLevel) this.level(), itemEntity) != null; // Paper - Call EntityDropItemEvent + } + } + +@@ -381,4 +_,14 @@ + ) { + return level.getBlockState(pos.below()).is(BlockTags.GOATS_SPAWNABLE_ON) && isBrightEnoughToSpawn(level, pos); + } ++ // Paper start - Goat ram API ++ public void ram(net.minecraft.world.entity.LivingEntity entity) { ++ Brain brain = this.getBrain(); ++ brain.setMemory(MemoryModuleType.RAM_TARGET, entity.position()); ++ brain.eraseMemory(MemoryModuleType.RAM_COOLDOWN_TICKS); ++ brain.eraseMemory(MemoryModuleType.BREED_TARGET); ++ brain.eraseMemory(MemoryModuleType.TEMPTING_PLAYER); ++ brain.setActiveActivityIfPossible(net.minecraft.world.entity.schedule.Activity.RAM); ++ } ++ // Paper end - Goat ram API + } diff --git a/paper-server/patches/unapplied/net/minecraft/world/entity/animal/goat/Goat.java.patch b/paper-server/patches/unapplied/net/minecraft/world/entity/animal/goat/Goat.java.patch deleted file mode 100644 index 44290161de..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/world/entity/animal/goat/Goat.java.patch +++ /dev/null @@ -1,76 +0,0 @@ ---- a/net/minecraft/world/entity/animal/goat/Goat.java -+++ b/net/minecraft/world/entity/animal/goat/Goat.java -@@ -53,6 +53,11 @@ - import net.minecraft.world.level.block.state.BlockState; - import net.minecraft.world.level.pathfinder.PathType; - import net.minecraft.world.phys.Vec3; -+// CraftBukkit start -+import org.bukkit.craftbukkit.event.CraftEventFactory; -+import org.bukkit.craftbukkit.inventory.CraftItemStack; -+import org.bukkit.event.player.PlayerBucketFillEvent; -+// CraftBukkit end - - public class Goat extends Animal { - -@@ -184,7 +189,7 @@ - - @Override - public Brain getBrain() { -- return super.getBrain(); -+ return (Brain) super.getBrain(); // CraftBukkit - decompile error - } - - @Override -@@ -229,15 +234,24 @@ - ItemStack itemstack = player.getItemInHand(hand); - - if (itemstack.is(Items.BUCKET) && !this.isBaby()) { -+ // CraftBukkit start - Got milk? -+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) player.level(), player, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET, hand); -+ -+ if (event.isCancelled()) { -+ player.containerMenu.sendAllDataToRemote(); // Paper - Fix inventory desync -+ return InteractionResult.PASS; -+ } -+ // CraftBukkit end - player.playSound(this.getMilkingSound(), 1.0F, 1.0F); -- ItemStack itemstack1 = ItemUtils.createFilledResult(itemstack, player, Items.MILK_BUCKET.getDefaultInstance()); -+ ItemStack itemstack1 = ItemUtils.createFilledResult(itemstack, player, CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit - - player.setItemInHand(hand, itemstack1); - return InteractionResult.SUCCESS; - } else { -+ boolean isFood = this.isFood(itemstack); // Paper - track before stack is possibly decreased to 0 (Fixes MC-244739) - InteractionResult enuminteractionresult = super.mobInteract(player, hand); - -- if (enuminteractionresult.consumesAction() && this.isFood(itemstack)) { -+ if (enuminteractionresult.consumesAction() && isFood) { // Paper - this.playEatingSound(); - } - -@@ -353,8 +367,7 @@ - double d2 = (double) Mth.randomBetween(this.random, -0.2F, 0.2F); - ItemEntity entityitem = new ItemEntity(this.level(), vec3d.x(), vec3d.y(), vec3d.z(), itemstack, d0, d1, d2); - -- this.level().addFreshEntity(entityitem); -- return true; -+ return this.spawnAtLocation((net.minecraft.server.level.ServerLevel) this.level(), entityitem) != null; // Paper - Call EntityDropItemEvent - } - } - -@@ -383,4 +396,15 @@ - public static boolean checkGoatSpawnRules(EntityType entityType, LevelAccessor world, EntitySpawnReason spawnReason, BlockPos pos, RandomSource random) { - return world.getBlockState(pos.below()).is(BlockTags.GOATS_SPAWNABLE_ON) && isBrightEnoughToSpawn(world, pos); - } -+ -+ // Paper start - Goat ram API -+ public void ram(net.minecraft.world.entity.LivingEntity entity) { -+ Brain brain = this.getBrain(); -+ brain.setMemory(MemoryModuleType.RAM_TARGET, entity.position()); -+ brain.eraseMemory(MemoryModuleType.RAM_COOLDOWN_TICKS); -+ brain.eraseMemory(MemoryModuleType.BREED_TARGET); -+ brain.eraseMemory(MemoryModuleType.TEMPTING_PLAYER); -+ brain.setActiveActivityIfPossible(net.minecraft.world.entity.schedule.Activity.RAM); -+ } -+ // Paper end - Goat ram API - }