use of net.minecraft.entity.ai.goal.PrioritizedGoal in project minecolonies by Minecolonies.
the class CustomGoalSelector method removeGoal.
/**
* removes the indicated task from the entity's AI tasks.
*/
@Override
public void removeGoal(Goal task) {
for (final PrioritizedGoal prioritizedGoal : new ArrayList<>(availableGoals)) {
if (prioritizedGoal.getGoal() == task) {
prioritizedGoal.stop();
availableGoals.remove(prioritizedGoal);
}
}
}
use of net.minecraft.entity.ai.goal.PrioritizedGoal in project roadrunner by MaxNeedsSnacks.
the class GoalSelectorMixin method startGoals.
/**
* Attempts to start all goals which are not-already running, can be started, and have their controls available.
*/
private void startGoals() {
for (PrioritizedGoal goal : this.goals) {
// Filter out goals which are already running or can't be started
if (goal.isRunning() || !goal.canStart()) {
continue;
}
// Check if the goal's controls are available or can be replaced
if (!this.areGoalControlsAvailable(goal)) {
continue;
}
// Hand over controls to this goal and stop any goals which depended on those controls
for (Goal.Control control : goal.getControls()) {
PrioritizedGoal otherGoal = this.getGoalOccupyingControl(control);
if (otherGoal != null) {
otherGoal.stop();
}
this.setGoalOccupyingControl(control, goal);
}
goal.start();
}
}
use of net.minecraft.entity.ai.goal.PrioritizedGoal in project roadrunner by MaxNeedsSnacks.
the class GoalSelectorMixin method tickGoals.
/**
* Ticks all running AI goals.
*/
private void tickGoals() {
this.profiler.get().push("goalTick");
// Tick all currently running goals
for (PrioritizedGoal goal : this.goals) {
if (goal.isRunning()) {
goal.tick();
}
}
this.profiler.get().pop();
}
use of net.minecraft.entity.ai.goal.PrioritizedGoal in project ChocolateQuestRepoured by TeamChocoQuest.
the class EntityAIRideHorse method removeHorseAI.
private void removeHorseAI() {
this.horseAI.clear();
this.horseAI.addAll(this.horse.goalSelector.availableGoals);
for (PrioritizedGoal task : this.horseAI) {
this.horse.goalSelector.removeGoal(task.getGoal());
}
}
use of net.minecraft.entity.ai.goal.PrioritizedGoal in project minecolonies by ldtteam.
the class CitizenJobHandler method onJobChanged.
/**
* Defines job changes and state changes of the citizen.
*
* @param job the set job.
*/
@Override
public void onJobChanged(@Nullable final IJob<?> job) {
// Model
setModelDependingOnJob(job);
// AI Tasks
for (@NotNull final PrioritizedGoal task : new ArrayList<>(citizen.getTasks().availableGoals)) {
if (task.getGoal() instanceof AbstractAISkeleton) {
citizen.getTasks().removeGoal(task.getGoal());
}
}
citizen.getCitizenData().setIdleAtJob(false);
if (job != null) {
job.addWorkerAIToTaskList(citizen.getTasks());
if (citizen.getTicksExisted() > 0 && citizen.getCitizenColonyHandler().getWorkBuilding() != null && citizen.getDesiredActivity() == DesiredActivity.WORK) {
BlockPosUtil.tryMoveBaseCitizenEntityToXYZ(citizen, citizen.getCitizenColonyHandler().getWorkBuilding().getPosition());
}
// Calculate the number of guards for some advancements
if (job instanceof AbstractJobGuard) {
IColony colony = citizen.getCitizenColonyHandler().getColony();
int guards = ((int) colony.getCitizenManager().getCitizens().stream().filter(citizen -> citizen.getJob() instanceof AbstractJobGuard).count());
AdvancementUtils.TriggerAdvancementPlayersForColony(citizen.getCitizenColonyHandler().getColony(), player -> AdvancementTriggers.ARMY_POPULATION.trigger(player, guards));
}
job.initEntityValues(citizen);
}
}
Aggregations