From 8eea7a4d458f3db99545d3626ba523a3eb96c81d Mon Sep 17 00:00:00 2001
From: Duckulus <76813487+Duckulus@users.noreply.github.com>
Date: Thu, 14 Sep 2023 12:54:43 +0200
Subject: [PATCH] Add missing Piglin Dancing API (#8894)

---
 patches/api/Missing-Entity-API.patch    | 23 +++++++++++++++++++++++
 patches/server/Missing-Entity-API.patch | 23 +++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/patches/api/Missing-Entity-API.patch b/patches/api/Missing-Entity-API.patch
index 0dccb46b30..6367145bb6 100644
--- a/patches/api/Missing-Entity-API.patch
+++ b/patches/api/Missing-Entity-API.patch
@@ -8,6 +8,7 @@ Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
 Co-authored-by: William Blake Galbreath <blake.galbreath@gmail.com>
 Co-authored-by: SoSeDiK <mrsosedik@gmail.com>
 Co-authored-by: booky10 <boooky10@gmail.com>
+Co-authored-by: Amin <amin.haddou@frg.wwschool.de>
 
 diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/VanillaGoal.java b/src/main/java/com/destroystokyo/paper/entity/ai/VanillaGoal.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
@@ -762,6 +763,28 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +     * @return is charging
 +     */
 +    boolean isChargingCrossbow();
++
++    /**
++     * Sets whether the Piglin is dancing or not
++     *
++     * @param dancing is dancing
++     */
++    void setDancing(boolean dancing);
++
++    /**
++     * Causes the piglin to dance for a
++     * specified amount of time
++     *
++     * @param duration duration of the dance in ticks
++     */
++    void setDancing(long duration);
++
++    /**
++     * Gets if the piglin is currently dancing
++     *
++     * @return is dancing
++     */
++    boolean isDancing();
 +    // Paper end
 +
  }
diff --git a/patches/server/Missing-Entity-API.patch b/patches/server/Missing-Entity-API.patch
index 992eec953e..bc7aff4523 100644
--- a/patches/server/Missing-Entity-API.patch
+++ b/patches/server/Missing-Entity-API.patch
@@ -37,6 +37,7 @@ Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
 Co-authored-by: William Blake Galbreath <blake.galbreath@gmail.com>
 Co-authored-by: SoSeDiK <mrsosedik@gmail.com>
 Co-authored-by: booky10 <boooky10@gmail.com>
+Co-authored-by: Amin <amin.haddou@frg.wwschool.de>
 
 diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java b/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
@@ -941,6 +942,28 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    public boolean isChargingCrossbow() {
 +        return this.getHandle().isChargingCrossbow();
 +    }
++
++    @Override
++    public void setDancing(boolean dancing) {
++        if (dancing) {
++            this.getHandle().getBrain().setMemory(net.minecraft.world.entity.ai.memory.MemoryModuleType.DANCING, true);
++            this.getHandle().getBrain().setMemory(net.minecraft.world.entity.ai.memory.MemoryModuleType.CELEBRATE_LOCATION, this.getHandle().getOnPos());
++        } else {
++            this.getHandle().getBrain().eraseMemory(net.minecraft.world.entity.ai.memory.MemoryModuleType.DANCING);
++            this.getHandle().getBrain().eraseMemory(net.minecraft.world.entity.ai.memory.MemoryModuleType.CELEBRATE_LOCATION);
++        }
++    }
++
++    @Override
++    public void setDancing(long duration) {
++        this.getHandle().getBrain().setMemoryWithExpiry(net.minecraft.world.entity.ai.memory.MemoryModuleType.DANCING, true, duration);
++        this.getHandle().getBrain().setMemoryWithExpiry(net.minecraft.world.entity.ai.memory.MemoryModuleType.CELEBRATE_LOCATION, this.getHandle().getOnPos(), duration);
++    }
++
++    @Override
++    public boolean isDancing() {
++        return this.getHandle().isDancing();
++    }
 +    // Paper end
  }
 diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPolarBear.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPolarBear.java