Skip to content

Commit

Permalink
add methods for Armadillo
Browse files Browse the repository at this point in the history
  • Loading branch information
Doc94 committed Jan 27, 2025
1 parent 7e21cb8 commit b92319a
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
39 changes: 39 additions & 0 deletions paper-api/src/main/java/org/bukkit/entity/Armadillo.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
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
*/
public State getState();

/**
* Set a new state for the armadillo.
* <br>
* This will also make the armadillo make the transition to the new state.
*
* @param state the new state
*/
public void setState(final State state);

/**
* Attempt to rollUp if it in {@link State#IDLE}
*/
public void rollUp();

/**
* Attempt to rollUp if it's not in {@link State#IDLE}
*/
public void rollOut();

/**
* Represents the current state of the Armadillo.
*/
public enum State {
IDLE,
ROLLING,
SCARED,
UNROLLING;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.entity;

import com.google.common.base.Preconditions;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Armadillo;

Expand All @@ -14,8 +15,47 @@ public net.minecraft.world.entity.animal.armadillo.Armadillo getHandle() {
return (net.minecraft.world.entity.animal.armadillo.Armadillo) super.getHandle();
}

@Override
public State getState() {
return this.stateToBukkit(this.getHandle().getState());
}

@Override
public void setState(final State state) {
Preconditions.checkArgument(state != null, "state cannot be null");
this.getHandle().switchToState(this.stateToNMS(state));
}

@Override
public void rollUp() {
this.getHandle().rollUp();
}

@Override
public void rollOut() {
this.getHandle().rollOut();
}

@Override
public String toString() {
return "CraftArmadillo";
}

private State stateToBukkit(net.minecraft.world.entity.animal.armadillo.Armadillo.ArmadilloState state) {
return switch (state) {
case IDLE -> State.IDLE;
case ROLLING -> State.ROLLING;
case SCARED -> State.SCARED;
case UNROLLING -> State.UNROLLING;
};
}

private net.minecraft.world.entity.animal.armadillo.Armadillo.ArmadilloState stateToNMS(State state) {
return switch (state) {
case State.IDLE -> net.minecraft.world.entity.animal.armadillo.Armadillo.ArmadilloState.IDLE;
case State.ROLLING -> net.minecraft.world.entity.animal.armadillo.Armadillo.ArmadilloState.ROLLING;
case State.SCARED -> net.minecraft.world.entity.animal.armadillo.Armadillo.ArmadilloState.SCARED;
case State.UNROLLING -> net.minecraft.world.entity.animal.armadillo.Armadillo.ArmadilloState.UNROLLING;
};
}
}

0 comments on commit b92319a

Please sign in to comment.