mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 05:30:23 -07:00
Add methods for Armadillo (#12031)
This commit is contained in:
parent
fc0c371761
commit
a7a76c8fc7
@ -1,8 +1,38 @@
|
|||||||
package org.bukkit.entity;
|
package org.bukkit.entity;
|
||||||
|
|
||||||
|
import org.jspecify.annotations.NullMarked;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an Armadillo.
|
* Represents an Armadillo.
|
||||||
*/
|
*/
|
||||||
|
@NullMarked
|
||||||
public interface Armadillo extends Animals {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.bukkit.craftbukkit.entity;
|
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.craftbukkit.CraftServer;
|
||||||
import org.bukkit.entity.Armadillo;
|
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();
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "CraftArmadillo";
|
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;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user