From f60983ac062ef8007bdcffdd3ed207011d8ef2d1 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Fri, 13 Dec 2024 15:55:52 -0800
Subject: [PATCH] net.minecraft.world.entity.animal.allay

---
 .../entity/animal/allay/Allay.java.patch      |  83 ++++++++++++++
 .../entity/animal/allay/Allay.java.patch      | 102 ------------------
 2 files changed, 83 insertions(+), 102 deletions(-)
 create mode 100644 paper-server/patches/sources/net/minecraft/world/entity/animal/allay/Allay.java.patch
 delete mode 100644 paper-server/patches/unapplied/net/minecraft/world/entity/animal/allay/Allay.java.patch

diff --git a/paper-server/patches/sources/net/minecraft/world/entity/animal/allay/Allay.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/animal/allay/Allay.java.patch
new file mode 100644
index 0000000000..c30af2f229
--- /dev/null
+++ b/paper-server/patches/sources/net/minecraft/world/entity/animal/allay/Allay.java.patch
@@ -0,0 +1,83 @@
+--- a/net/minecraft/world/entity/animal/allay/Allay.java
++++ b/net/minecraft/world/entity/animal/allay/Allay.java
+@@ -118,6 +_,7 @@
+     private float dancingAnimationTicks;
+     private float spinningAnimationTicks;
+     private float spinningAnimationTicks0;
++    public boolean forceDancing = false; // CraftBukkit
+ 
+     public Allay(EntityType<? extends Allay> entityType, Level level) {
+         super(entityType, level);
+@@ -131,6 +_,12 @@
+         );
+     }
+ 
++    // CraftBukkit start
++    public void setCanDuplicate(boolean canDuplicate) {
++        this.entityData.set(Allay.DATA_CAN_DUPLICATE, canDuplicate);
++    }
++    // CraftBukkit end
++
+     @Override
+     protected Brain.Provider<Allay> brainProvider() {
+         return Brain.provider(MEMORY_TYPES, SENSOR_TYPES);
+@@ -252,7 +_,7 @@
+     public void aiStep() {
+         super.aiStep();
+         if (!this.level().isClientSide && this.isAlive() && this.tickCount % 10 == 0) {
+-            this.heal(1.0F);
++            this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit
+         }
+ 
+         if (this.isDancing() && this.shouldStopDancing() && this.tickCount % 20 == 0) {
+@@ -320,7 +_,12 @@
+         ItemStack itemInHand = player.getItemInHand(hand);
+         ItemStack itemInHand1 = this.getItemInHand(InteractionHand.MAIN_HAND);
+         if (this.isDancing() && itemInHand.is(ItemTags.DUPLICATES_ALLAYS) && this.canDuplicate()) {
+-            this.duplicateAllay();
++            // CraftBukkit start - handle cancel duplication
++            Allay allay = this.duplicateAllay();
++            if (allay == null) {
++                return InteractionResult.SUCCESS;
++            }
++            // CraftBukkit end
+             this.level().broadcastEntityEvent(this, (byte)18);
+             this.level().playSound(player, this, SoundEvents.AMETHYST_BLOCK_CHIME, SoundSource.NEUTRAL, 2.0F, 1.0F);
+             this.removeInteractionItem(player, itemInHand);
+@@ -425,6 +_,7 @@
+     }
+ 
+     private boolean shouldStopDancing() {
++        if (this.forceDancing) {return false;} // CraftBukkit
+         return this.jukeboxPos == null
+             || !this.jukeboxPos.closerToCenterThan(this.position(), GameEvent.JUKEBOX_PLAY.value().notificationRadius())
+             || !this.level().getBlockState(this.jukeboxPos).is(Blocks.JUKEBOX);
+@@ -489,7 +_,7 @@
+                 .ifPresent(data -> this.vibrationData = data);
+         }
+ 
+-        this.duplicationCooldown = tag.getInt("DuplicationCooldown");
++        this.duplicationCooldown = tag.getLong("DuplicationCooldown"); // Paper - Load as long
+         this.entityData.set(DATA_CAN_DUPLICATE, tag.getBoolean("CanDuplicate"));
+     }
+ 
+@@ -508,15 +_,17 @@
+         }
+     }
+ 
+-    public void duplicateAllay() {
++    @Nullable public Allay duplicateAllay() { // CraftBukkit - return allay
+         Allay allay = EntityType.ALLAY.create(this.level(), EntitySpawnReason.BREEDING);
+         if (allay != null) {
+             allay.moveTo(this.position());
+             allay.setPersistenceRequired();
+             allay.resetDuplicationCooldown();
+             this.resetDuplicationCooldown();
+-            this.level().addFreshEntity(allay);
++            this.level().addFreshEntity(allay, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DUPLICATION); // CraftBukkit - reason for duplicated allay
+         }
++
++        return allay; // CraftBukkit
+     }
+ 
+     public void resetDuplicationCooldown() {
diff --git a/paper-server/patches/unapplied/net/minecraft/world/entity/animal/allay/Allay.java.patch b/paper-server/patches/unapplied/net/minecraft/world/entity/animal/allay/Allay.java.patch
deleted file mode 100644
index 8c853dc764..0000000000
--- a/paper-server/patches/unapplied/net/minecraft/world/entity/animal/allay/Allay.java.patch
+++ /dev/null
@@ -1,102 +0,0 @@
---- a/net/minecraft/world/entity/animal/allay/Allay.java
-+++ b/net/minecraft/world/entity/animal/allay/Allay.java
-@@ -103,6 +103,7 @@
-     private float dancingAnimationTicks;
-     private float spinningAnimationTicks;
-     private float spinningAnimationTicks0;
-+    public boolean forceDancing = false; // CraftBukkit
- 
-     public Allay(EntityType<? extends Allay> type, Level world) {
-         super(type, world);
-@@ -114,6 +115,12 @@
-         this.dynamicJukeboxListener = new DynamicGameEventListener<>(new Allay.JukeboxListener(this.vibrationUser.getPositionSource(), ((GameEvent) GameEvent.JUKEBOX_PLAY.value()).notificationRadius()));
-     }
- 
-+    // CraftBukkit start
-+    public void setCanDuplicate(boolean canDuplicate) {
-+        this.entityData.set(Allay.DATA_CAN_DUPLICATE, canDuplicate);
-+    }
-+    // CraftBukkit end
-+
-     @Override
-     protected Brain.Provider<Allay> brainProvider() {
-         return Brain.provider(Allay.MEMORY_TYPES, Allay.SENSOR_TYPES);
-@@ -126,7 +133,7 @@
- 
-     @Override
-     public Brain<Allay> getBrain() {
--        return super.getBrain();
-+        return (Brain<Allay>) super.getBrain(); // CraftBukkit - decompile error
-     }
- 
-     public static AttributeSupplier.Builder createAttributes() {
-@@ -233,7 +240,7 @@
-     public void aiStep() {
-         super.aiStep();
-         if (!this.level().isClientSide && this.isAlive() && this.tickCount % 10 == 0) {
--            this.heal(1.0F);
-+            this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit
-         }
- 
-         if (this.isDancing() && this.shouldStopDancing() && this.tickCount % 20 == 0) {
-@@ -303,7 +310,12 @@
-         ItemStack itemstack1 = this.getItemInHand(InteractionHand.MAIN_HAND);
- 
-         if (this.isDancing() && itemstack.is(ItemTags.DUPLICATES_ALLAYS) && this.canDuplicate()) {
--            this.duplicateAllay();
-+            // CraftBukkit start - handle cancel duplication
-+            Allay allay = this.duplicateAllay();
-+            if (allay == null) {
-+                return InteractionResult.SUCCESS;
-+            }
-+            // CraftBukkit end
-             this.level().broadcastEntityEvent(this, (byte) 18);
-             this.level().playSound(player, (Entity) this, SoundEvents.AMETHYST_BLOCK_CHIME, SoundSource.NEUTRAL, 2.0F, 1.0F);
-             this.removeInteractionItem(player, itemstack);
-@@ -314,7 +326,7 @@
-             this.setItemInHand(InteractionHand.MAIN_HAND, itemstack2);
-             this.removeInteractionItem(player, itemstack);
-             this.level().playSound(player, (Entity) this, SoundEvents.ALLAY_ITEM_GIVEN, SoundSource.NEUTRAL, 2.0F, 1.0F);
--            this.getBrain().setMemory(MemoryModuleType.LIKED_PLAYER, (Object) player.getUUID());
-+            this.getBrain().setMemory(MemoryModuleType.LIKED_PLAYER, player.getUUID()); // CraftBukkit - decompile error
-             return InteractionResult.SUCCESS;
-         } else if (!itemstack1.isEmpty() && hand == InteractionHand.MAIN_HAND && itemstack.isEmpty()) {
-             this.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY);
-@@ -415,6 +427,7 @@
-     }
- 
-     private boolean shouldStopDancing() {
-+        if (this.forceDancing) {return false;} // CraftBukkit
-         return this.jukeboxPos == null || !this.jukeboxPos.closerToCenterThan(this.position(), (double) ((GameEvent) GameEvent.JUKEBOX_PLAY.value()).notificationRadius()) || !this.level().getBlockState(this.jukeboxPos).is(Blocks.JUKEBOX);
-     }
- 
-@@ -486,7 +499,7 @@
-             });
-         }
- 
--        this.duplicationCooldown = (long) nbt.getInt("DuplicationCooldown");
-+        this.duplicationCooldown = nbt.getLong("DuplicationCooldown"); // Paper - Load as long
-         this.entityData.set(Allay.DATA_CAN_DUPLICATE, nbt.getBoolean("CanDuplicate"));
-     }
- 
-@@ -506,7 +519,7 @@
- 
-     }
- 
--    public void duplicateAllay() {
-+    public Allay duplicateAllay() { // CraftBukkit - return allay
-         Allay allay = (Allay) EntityType.ALLAY.create(this.level(), EntitySpawnReason.BREEDING);
- 
-         if (allay != null) {
-@@ -514,9 +527,9 @@
-             allay.setPersistenceRequired();
-             allay.resetDuplicationCooldown();
-             this.resetDuplicationCooldown();
--            this.level().addFreshEntity(allay);
-+            this.level().addFreshEntity(allay, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DUPLICATION); // CraftBukkit - reason for duplicated allay
-         }
--
-+        return allay; // CraftBukkit
-     }
- 
-     public void resetDuplicationCooldown() {