mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-11 09:51:35 +01:00
rename some variables and change interruption to also check shouldStart
This commit is contained in:
parent
5203225c8e
commit
22511d200f
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -79,9 +79,11 @@ public abstract class AIGoal implements Comparable<AIGoal> {
|
||||
|
||||
/**
|
||||
* Checks to see if this goal should interrupt the current goal, given the entity creature's current state
|
||||
* <p></p>
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ public interface EntityAI {
|
||||
void setAIGroup(@NotNull EntityAIGroup aiGroup);
|
||||
|
||||
default void addGoals(@NotNull List<AIGoal> aiGoals) {
|
||||
getAIGroup().getGoalSelectors().addAll(aiGoals);
|
||||
getAIGroup().getAIGoals().addAll(aiGoals);
|
||||
}
|
||||
|
||||
default void aiTick(long time) {
|
||||
|
@ -12,8 +12,8 @@ import java.util.List;
|
||||
*/
|
||||
public class EntityAIGroup {
|
||||
|
||||
private AIGoal currentGoalSelector;
|
||||
private final List<AIGoal> goalSelectors = new ArrayList<>();
|
||||
private AIGoal currentAIGoal;
|
||||
private final List<AIGoal> 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<AIGoal> getGoalSelectors() {
|
||||
return Collections.unmodifiableList(goalSelectors);
|
||||
public List<AIGoal> getAIGoals() {
|
||||
return Collections.unmodifiableList(aiGoals);
|
||||
}
|
||||
|
||||
public void addAIGoals(@NotNull List<AIGoal> 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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user