diff --git a/src/main/java/net/minestom/server/entity/EntityCreature.java b/src/main/java/net/minestom/server/entity/EntityCreature.java index 7ad19c125..50505eb6f 100644 --- a/src/main/java/net/minestom/server/entity/EntityCreature.java +++ b/src/main/java/net/minestom/server/entity/EntityCreature.java @@ -67,7 +67,7 @@ public class EntityCreature extends Entity implements PathWalker, EntityAI { this.aiGroup = aiGroup; // Update entity creatures in AI goal // TODO: Is this needed? - for (AIGoal aiGoal : aiGroup.getGoalSelectors()) { + for (AIGoal aiGoal : aiGroup.getAIGoals()) { aiGoal.setEntityCreature(this); } } diff --git a/src/main/java/net/minestom/server/entity/ai/AIGoal.java b/src/main/java/net/minestom/server/entity/ai/AIGoal.java index 038b87f32..40c0a7646 100644 --- a/src/main/java/net/minestom/server/entity/ai/AIGoal.java +++ b/src/main/java/net/minestom/server/entity/ai/AIGoal.java @@ -79,9 +79,11 @@ public abstract class AIGoal implements Comparable { /** * Checks to see if this goal should interrupt the current goal, given the entity creature's current state + *

+ * Note: {@link EntityAIGroup} will only interrupt the current goal with this one if {@link #shouldStart()} is true as well. * @return true if this goal should interrupt the current one, false to continue as normal */ - public boolean shouldInterrupt() { + public boolean canInterrupt(@NotNull AIGoal currentGoal) { return false; } diff --git a/src/main/java/net/minestom/server/entity/ai/EntityAI.java b/src/main/java/net/minestom/server/entity/ai/EntityAI.java index a87a6c3d6..c10f0c9a5 100644 --- a/src/main/java/net/minestom/server/entity/ai/EntityAI.java +++ b/src/main/java/net/minestom/server/entity/ai/EntityAI.java @@ -26,7 +26,7 @@ public interface EntityAI { void setAIGroup(@NotNull EntityAIGroup aiGroup); default void addGoals(@NotNull List aiGoals) { - getAIGroup().getGoalSelectors().addAll(aiGoals); + getAIGroup().getAIGoals().addAll(aiGoals); } default void aiTick(long time) { diff --git a/src/main/java/net/minestom/server/entity/ai/EntityAIGroup.java b/src/main/java/net/minestom/server/entity/ai/EntityAIGroup.java index f64f8c881..d26334c94 100644 --- a/src/main/java/net/minestom/server/entity/ai/EntityAIGroup.java +++ b/src/main/java/net/minestom/server/entity/ai/EntityAIGroup.java @@ -12,8 +12,8 @@ import java.util.List; */ public class EntityAIGroup { - private AIGoal currentGoalSelector; - private final List goalSelectors = new ArrayList<>(); + private AIGoal currentAIGoal; + private final List aiGoals = new ArrayList<>(); /** * Gets the goal selectors of this group. @@ -21,12 +21,12 @@ public class EntityAIGroup { * @return an unmodifiable list containing this group's goal selectors */ @NotNull - public List getGoalSelectors() { - return Collections.unmodifiableList(goalSelectors); + public List getAIGoals() { + return Collections.unmodifiableList(aiGoals); } public void addAIGoals(@NotNull List goalSelectors) { - this.goalSelectors.addAll(goalSelectors); + this.aiGoals.addAll(goalSelectors); Collections.sort(goalSelectors); } @@ -36,24 +36,24 @@ public class EntityAIGroup { * @return the current AI goal of this group, null if not any */ @Nullable - public AIGoal getCurrentGoalSelector() { - return this.currentGoalSelector; + public AIGoal getCurrentAIGoal() { + return this.currentAIGoal; } public void tick(long time) { - AIGoal currentGoalSelector = getCurrentGoalSelector(); + AIGoal currentGoal = getCurrentAIGoal(); - if (currentGoalSelector != null) { - if (currentGoalSelector.shouldEnd()) { - currentGoalSelector.end(); - this.currentGoalSelector = null; + if (currentGoal != null) { + if (currentGoal.shouldEnd()) { + currentGoal.end(); + this.currentAIGoal = null; } else { - currentGoalSelector.tick(time); + currentGoal.tick(time); // Check for any goal interrupts - for (var goal : goalSelectors) { - if (goal.shouldInterrupt()) { - currentGoalSelector.end(); - this.currentGoalSelector = goal; + for (var goal : aiGoals) { + if (goal.canInterrupt(currentGoal) && goal.shouldStart()) { + currentGoal.end(); + this.currentAIGoal = goal; goal.start(); break; } @@ -61,11 +61,11 @@ public class EntityAIGroup { } } - if (currentGoalSelector == null) { + if (currentGoal == null) { // We don't have a current goal, pick one with the highest priority - for (var goal : goalSelectors) { + for (var goal : aiGoals) { if (goal.shouldStart()) { - this.currentGoalSelector = goal; + this.currentAIGoal = goal; goal.start(); break; } diff --git a/src/main/java/net/minestom/server/entity/ai/EntityAIGroupBuilder.java b/src/main/java/net/minestom/server/entity/ai/EntityAIGroupBuilder.java index 619f3b0a7..b4686f2ba 100644 --- a/src/main/java/net/minestom/server/entity/ai/EntityAIGroupBuilder.java +++ b/src/main/java/net/minestom/server/entity/ai/EntityAIGroupBuilder.java @@ -13,7 +13,7 @@ public class EntityAIGroupBuilder { * @return this builder. */ public EntityAIGroupBuilder addAIGoal(@NotNull AIGoal goalSelector) { - this.group.getGoalSelectors().add(goalSelector); + this.group.getAIGoals().add(goalSelector); return this; }