Search in sources :

Example 1 with PrioritizedGoal

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);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal)

Example 2 with 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();
    }
}
Also used : Goal(net.minecraft.entity.ai.goal.Goal) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal)

Example 3 with PrioritizedGoal

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();
}
Also used : PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal)

Example 4 with PrioritizedGoal

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());
    }
}
Also used : PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal)

Example 5 with PrioritizedGoal

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);
    }
}
Also used : ModModelTypes(com.minecolonies.api.client.render.modeltype.ModModelTypes) DesiredActivity(com.minecolonies.api.entity.ai.DesiredActivity) AdvancementUtils(com.minecolonies.coremod.util.AdvancementUtils) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) ArrayList(java.util.ArrayList) DATA_MODEL(com.minecolonies.api.entity.citizen.AbstractEntityCitizen.DATA_MODEL) Nullable(org.jetbrains.annotations.Nullable) AdvancementTriggers(com.minecolonies.api.advancements.AdvancementTriggers) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) AbstractAISkeleton(com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton) IColony(com.minecolonies.api.colony.IColony) ICitizenJobHandler(com.minecolonies.api.entity.citizen.citizenhandlers.ICitizenJobHandler) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) NotNull(org.jetbrains.annotations.NotNull) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) IJob(com.minecolonies.api.colony.jobs.IJob) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) AbstractAISkeleton(com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton) ArrayList(java.util.ArrayList) IColony(com.minecolonies.api.colony.IColony) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PrioritizedGoal (net.minecraft.entity.ai.goal.PrioritizedGoal)15 Goal (net.minecraft.entity.ai.goal.Goal)7 ArrayList (java.util.ArrayList)6 AdvancementTriggers (com.minecolonies.api.advancements.AdvancementTriggers)2 ModModelTypes (com.minecolonies.api.client.render.modeltype.ModModelTypes)2 IColony (com.minecolonies.api.colony.IColony)2 IJob (com.minecolonies.api.colony.jobs.IJob)2 DesiredActivity (com.minecolonies.api.entity.ai.DesiredActivity)2 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)2 DATA_MODEL (com.minecolonies.api.entity.citizen.AbstractEntityCitizen.DATA_MODEL)2 ICitizenJobHandler (com.minecolonies.api.entity.citizen.citizenhandlers.ICitizenJobHandler)2 BlockPosUtil (com.minecolonies.api.util.BlockPosUtil)2 AbstractJobGuard (com.minecolonies.coremod.colony.jobs.AbstractJobGuard)2 AbstractAISkeleton (com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton)2 AdvancementUtils (com.minecolonies.coremod.util.AdvancementUtils)2 Map (java.util.Map)2 LivingEntity (net.minecraft.entity.LivingEntity)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2