Improved CustomGoal
This commit is contained in:
@@ -3,6 +3,10 @@ package com.willfp.eco.core.entities.ai;
|
||||
import org.bukkit.entity.Mob;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Base interface for all custom goals.
|
||||
* <p>
|
||||
@@ -10,7 +14,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
*
|
||||
* @param <T> The type of mob that this goal can be applied to.
|
||||
*/
|
||||
public interface CustomGoal<T extends Mob> extends EntityGoal<T>, TargetGoal<T> {
|
||||
public abstract class CustomGoal<T extends Mob> implements EntityGoal<T>, TargetGoal<T> {
|
||||
/**
|
||||
* The flags for the goal.
|
||||
*/
|
||||
private final Set<GoalFlag> flags = EnumSet.noneOf(GoalFlag.class);
|
||||
|
||||
/**
|
||||
* Initialize the goal with a mob.
|
||||
* <p>
|
||||
@@ -18,7 +27,7 @@ public interface CustomGoal<T extends Mob> extends EntityGoal<T>, TargetGoal<T>
|
||||
*
|
||||
* @param mob The mob.
|
||||
*/
|
||||
void initialize(@NotNull T mob);
|
||||
public abstract void initialize(@NotNull T mob);
|
||||
|
||||
/**
|
||||
* Get if the goal can be used.
|
||||
@@ -26,7 +35,7 @@ public interface CustomGoal<T extends Mob> extends EntityGoal<T>, TargetGoal<T>
|
||||
*
|
||||
* @return If the goal can be used.
|
||||
*/
|
||||
boolean canUse();
|
||||
public abstract boolean canUse();
|
||||
|
||||
/**
|
||||
* Tick the goal.
|
||||
@@ -35,7 +44,7 @@ public interface CustomGoal<T extends Mob> extends EntityGoal<T>, TargetGoal<T>
|
||||
* <p>
|
||||
* Runs after {@link this#start()}.
|
||||
*/
|
||||
default void tick() {
|
||||
public void tick() {
|
||||
// Override when needed.
|
||||
}
|
||||
|
||||
@@ -44,7 +53,7 @@ public interface CustomGoal<T extends Mob> extends EntityGoal<T>, TargetGoal<T>
|
||||
* <p>
|
||||
* Runs once {@link this#canUse()} returns true.
|
||||
*/
|
||||
default void start() {
|
||||
public void start() {
|
||||
// Override when needed.
|
||||
}
|
||||
|
||||
@@ -53,12 +62,50 @@ public interface CustomGoal<T extends Mob> extends EntityGoal<T>, TargetGoal<T>
|
||||
* <p>
|
||||
* Runs once {@link this#canUse()} returns false.
|
||||
*/
|
||||
default void stop() {
|
||||
public void stop() {
|
||||
// Override when needed.
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the goal can continue to be used.
|
||||
*
|
||||
* @return If the goal can continue to be used.
|
||||
*/
|
||||
public boolean canContinueToUse() {
|
||||
return this.canUse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the goal is interruptable.
|
||||
*
|
||||
* @return If interruptable.
|
||||
*/
|
||||
public boolean isInterruptable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the goal flags.
|
||||
*
|
||||
* @return The flags.
|
||||
*/
|
||||
public EnumSet<GoalFlag> getFlags() {
|
||||
return EnumSet.copyOf(this.flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the flags for the goal.
|
||||
*
|
||||
* @param flags The flags.
|
||||
*/
|
||||
public void setFlags(@NotNull final Collection<GoalFlag> flags) {
|
||||
this.flags.clear();
|
||||
this.flags.addAll(flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
default T addToEntity(@NotNull T entity, int priority) {
|
||||
public T addToEntity(@NotNull final T entity,
|
||||
final int priority) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Shorthand syntax is not supported for custom goals by default as they can be both entity and target goals."
|
||||
);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.willfp.eco.core.entities.ai;
|
||||
|
||||
/**
|
||||
* Flags for ai goals.
|
||||
*/
|
||||
public enum GoalFlag {
|
||||
/**
|
||||
* Move.
|
||||
*/
|
||||
MOVE,
|
||||
|
||||
/**
|
||||
* Look around.
|
||||
*/
|
||||
LOOK,
|
||||
|
||||
/**
|
||||
* Jump.
|
||||
*/
|
||||
JUMP,
|
||||
|
||||
/**
|
||||
* Target.
|
||||
*/
|
||||
TARGET
|
||||
}
|
||||
Reference in New Issue
Block a user