diff --git a/paper-api/src/main/java/org/bukkit/entity/Armadillo.java b/paper-api/src/main/java/org/bukkit/entity/Armadillo.java index a8daf56dc5..d4eacd26e4 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Armadillo.java +++ b/paper-api/src/main/java/org/bukkit/entity/Armadillo.java @@ -1,8 +1,38 @@ package org.bukkit.entity; +import org.jspecify.annotations.NullMarked; + /** * Represents an Armadillo. */ +@NullMarked public interface Armadillo extends Animals { + /** + * Get the current state of the armadillo. + * + * @return the state of the armadillo + */ + State getState(); + + /** + * Attempt to roll up if the armadillo is {@link State#IDLE} + */ + void rollUp(); + + /** + * Attempt to roll out if the armadillo is not {@link State#IDLE} + */ + void rollOut(); + + /** + * Represents the current state of the armadillo. + */ + enum State { + IDLE, + ROLLING, + SCARED, + UNROLLING; + } + } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArmadillo.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArmadillo.java index e7f2d8de25..e039bc3356 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArmadillo.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArmadillo.java @@ -1,5 +1,7 @@ package org.bukkit.craftbukkit.entity; +import net.minecraft.world.entity.ai.memory.MemoryModuleType; +import net.minecraft.world.entity.animal.armadillo.Armadillo.ArmadilloState; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Armadillo; @@ -14,8 +16,48 @@ public class CraftArmadillo extends CraftAnimals implements Armadillo { return (net.minecraft.world.entity.animal.armadillo.Armadillo) super.getHandle(); } + @Override + public State getState() { + return CraftArmadillo.stateToBukkit(this.getHandle().getState()); + } + + @Override + public void rollUp() { + this.getHandle().getBrain().setMemoryWithExpiry(MemoryModuleType.DANGER_DETECTED_RECENTLY, true, net.minecraft.world.entity.animal.armadillo.Armadillo.SCARE_CHECK_INTERVAL); + this.getHandle().rollUp(); + } + + @Override + public void rollOut() { + if (this.getHandle().getBrain().getTimeUntilExpiry(MemoryModuleType.DANGER_DETECTED_RECENTLY) <= ArmadilloState.UNROLLING.animationDuration()) { + // already unrolling or unrolled + return; + } + + this.getHandle().lastHurtByMob = null; // Clear this memory to not have the sensor trigger rollUp instantly for damaged armadillo + this.getHandle().getBrain().setMemoryWithExpiry(MemoryModuleType.DANGER_DETECTED_RECENTLY, true, ArmadilloState.UNROLLING.animationDuration()); + } + @Override public String toString() { return "CraftArmadillo"; } + + public static State stateToBukkit(ArmadilloState state) { + return switch (state) { + case IDLE -> State.IDLE; + case ROLLING -> State.ROLLING; + case SCARED -> State.SCARED; + case UNROLLING -> State.UNROLLING; + }; + } + + public static ArmadilloState stateToNMS(State state) { + return switch (state) { + case State.IDLE -> ArmadilloState.IDLE; + case State.ROLLING -> ArmadilloState.ROLLING; + case State.SCARED -> ArmadilloState.SCARED; + case State.UNROLLING -> ArmadilloState.UNROLLING; + }; + } }