Search in sources :

Example 11 with PrioritizedGoal

use of net.minecraft.entity.ai.goal.PrioritizedGoal in project Arclight by IzzelAliz.

the class GoalSelectorMixin method tick.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void tick() {
    this.profiler.startSection("goalCleanup");
    for (PrioritizedGoal prioritizedGoal : this.goals) {
        if (prioritizedGoal.isRunning()) {
            if (!prioritizedGoal.isRunning()) {
                prioritizedGoal.resetTask();
            } else {
                EnumSet<Goal.Flag> flags = this.disabledFlags;
                boolean b = false;
                for (Goal.Flag flag : prioritizedGoal.getMutexFlags()) {
                    if (flags.contains(flag)) {
                        b = true;
                        break;
                    }
                }
                if (b || !prioritizedGoal.shouldContinueExecuting()) {
                    prioritizedGoal.resetTask();
                }
            }
        }
    }
    for (Map.Entry<Goal.Flag, PrioritizedGoal> entry : this.flagGoals.entrySet()) {
        Goal.Flag flag = entry.getKey();
        PrioritizedGoal prioritizedGoal = entry.getValue();
        if (!prioritizedGoal.isRunning()) {
            this.flagGoals.remove(flag);
        }
    }
    this.profiler.endSection();
    this.profiler.startSection("goalUpdate");
    for (PrioritizedGoal prioritizedGoal : this.goals) {
        if (!prioritizedGoal.isRunning()) {
            EnumSet<Goal.Flag> flags = this.disabledFlags;
            boolean b = true;
            for (Goal.Flag flag : prioritizedGoal.getMutexFlags()) {
                if (flags.contains(flag)) {
                    b = false;
                    break;
                }
            }
            if (b) {
                boolean result = true;
                for (Goal.Flag flag : prioritizedGoal.getMutexFlags()) {
                    if (!this.flagGoals.getOrDefault(flag, DUMMY).isPreemptedBy(prioritizedGoal)) {
                        result = false;
                        break;
                    }
                }
                if (result) {
                    if (prioritizedGoal.shouldExecute()) {
                        for (Goal.Flag flag : prioritizedGoal.getMutexFlags()) {
                            PrioritizedGoal prioritizedgoal = this.flagGoals.getOrDefault(flag, DUMMY);
                            prioritizedgoal.resetTask();
                            this.flagGoals.put(flag, prioritizedGoal);
                        }
                        prioritizedGoal.startExecuting();
                    }
                }
            }
        }
    }
    this.profiler.endSection();
    this.profiler.startSection("goalTick");
    for (PrioritizedGoal goal : this.goals) {
        if (goal.isRunning()) {
            goal.tick();
        }
    }
    this.profiler.endSection();
}
Also used : Goal(net.minecraft.entity.ai.goal.Goal) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) Map(java.util.Map) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 12 with PrioritizedGoal

use of net.minecraft.entity.ai.goal.PrioritizedGoal in project Arclight by IzzelAliz.

the class GoalSelectorMixin method tick.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void tick() {
    this.profiler.startSection("goalCleanup");
    for (PrioritizedGoal p_220881_1_ : this.goals) {
        if (p_220881_1_.isRunning()) {
            EnumSet<Goal.Flag> flags = this.disabledFlags;
            boolean b = false;
            for (Goal.Flag flag : p_220881_1_.getMutexFlags()) {
                if (flags.contains(flag)) {
                    b = true;
                    break;
                }
            }
            if (b) {
                p_220881_1_.resetTask();
            } else if (!p_220881_1_.isRunning() || !p_220881_1_.shouldContinueExecuting()) {
                p_220881_1_.resetTask();
            }
        }
    }
    for (Map.Entry<Goal.Flag, PrioritizedGoal> entry : this.flagGoals.entrySet()) {
        Goal.Flag p_220885_1_ = entry.getKey();
        PrioritizedGoal p_220885_2_ = entry.getValue();
        if (!p_220885_2_.isRunning()) {
            this.flagGoals.remove(p_220885_1_);
        }
    }
    this.profiler.endSection();
    this.profiler.startSection("goalUpdate");
    for (PrioritizedGoal p_220883_0_ : this.goals) {
        if (!p_220883_0_.isRunning()) {
            EnumSet<Goal.Flag> flags = this.disabledFlags;
            boolean b = true;
            for (Goal.Flag flag : p_220883_0_.getMutexFlags()) {
                if (flags.contains(flag)) {
                    b = false;
                    break;
                }
            }
            if (b) {
                boolean result = true;
                for (Goal.Flag p_220887_2_ : p_220883_0_.getMutexFlags()) {
                    if (!this.flagGoals.getOrDefault(p_220887_2_, DUMMY).isPreemptedBy(p_220883_0_)) {
                        result = false;
                        break;
                    }
                }
                if (result) {
                    if (p_220883_0_.shouldExecute()) {
                        for (Goal.Flag p_220876_2_ : p_220883_0_.getMutexFlags()) {
                            PrioritizedGoal prioritizedgoal = this.flagGoals.getOrDefault(p_220876_2_, DUMMY);
                            prioritizedgoal.resetTask();
                            this.flagGoals.put(p_220876_2_, p_220883_0_);
                        }
                        p_220883_0_.startExecuting();
                    }
                }
            }
        }
    }
    this.profiler.endSection();
    this.profiler.startSection("goalTick");
    for (PrioritizedGoal goal : this.goals) {
        if (goal.isRunning()) {
            goal.tick();
        }
    }
    this.profiler.endSection();
}
Also used : Goal(net.minecraft.entity.ai.goal.Goal) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) Map(java.util.Map) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 13 with PrioritizedGoal

use of net.minecraft.entity.ai.goal.PrioritizedGoal in project Champions by TheIllusiveC4.

the class MoltenAffix method onSpawn.

@Override
public void onSpawn(IChampion champion) {
    LivingEntity livingEntity = champion.getLivingEntity();
    livingEntity.addPotionEffect(new EffectInstance(Effects.FIRE_RESISTANCE, 40, 0, true, false));
    if (livingEntity instanceof MobEntity) {
        MobEntity mobEntity = (MobEntity) livingEntity;
        mobEntity.setPathPriority(PathNodeType.WATER, -1.0F);
        mobEntity.setPathPriority(PathNodeType.LAVA, 8.0F);
        mobEntity.setPathPriority(PathNodeType.DANGER_FIRE, 0.0F);
        mobEntity.setPathPriority(PathNodeType.DAMAGE_FIRE, 0.0F);
        try {
            @SuppressWarnings("unchecked") Set<PrioritizedGoal> goals = (Set<PrioritizedGoal>) GOALS.get(mobEntity.goalSelector);
            Iterator<PrioritizedGoal> iter = goals.iterator();
            while (iter.hasNext()) {
                PrioritizedGoal goal = iter.next();
                Goal baseGoal = goal.getGoal();
                if (baseGoal instanceof FleeSunGoal || baseGoal instanceof RestrictSunGoal) {
                    iter.remove();
                }
            }
        } catch (Exception e) {
            Champions.LOGGER.error("Error accessing goals!");
        }
        if (mobEntity.getNavigator() instanceof GroundPathNavigator) {
            ((GroundPathNavigator) mobEntity.getNavigator()).setAvoidSun(false);
        }
    }
}
Also used : Set(java.util.Set) FleeSunGoal(net.minecraft.entity.ai.goal.FleeSunGoal) LivingEntity(net.minecraft.entity.LivingEntity) Goal(net.minecraft.entity.ai.goal.Goal) RestrictSunGoal(net.minecraft.entity.ai.goal.RestrictSunGoal) FleeSunGoal(net.minecraft.entity.ai.goal.FleeSunGoal) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) RestrictSunGoal(net.minecraft.entity.ai.goal.RestrictSunGoal) GroundPathNavigator(net.minecraft.pathfinding.GroundPathNavigator) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) EffectInstance(net.minecraft.potion.EffectInstance) MobEntity(net.minecraft.entity.MobEntity)

Example 14 with PrioritizedGoal

use of net.minecraft.entity.ai.goal.PrioritizedGoal in project minecolonies by ldtteam.

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 15 with PrioritizedGoal

use of net.minecraft.entity.ai.goal.PrioritizedGoal in project minecolonies by ldtteam.

the class CustomGoalSelector method tick.

/**
 * Ticks this selector, first checks running goals to stop, then checks all goals to see which should start running. Finally ticks all running goals Performance wise this is
 * about 6 times faster, when checking at the same rate as the vanilla one, resulting in about 3-4 times less time spent updating and executing AI goals. When updating
 * non-running goals only every 4 ticks it goes up to about 10% of vanilla's time spent for the whole update goals and their execution.
 */
@Override
public void tick() {
    this.profiler.get().push("goalUpdate");
    boolean hasFlags;
    counter++;
    for (final PrioritizedGoal currentGoal : new ArrayList<>(availableGoals)) {
        hasFlags = !currentGoal.getFlags().isEmpty();
        if (currentGoal.isRunning() && (hasFlags && goalContainsDisabledFlag(currentGoal) || !currentGoal.canContinueToUse())) {
            currentGoal.stop();
        }
        // Vanilla behaviour changed to checking it each tick with 1.14
        if (counter == 1 && !currentGoal.isRunning() && ((!hasFlags && currentGoal.canUse()) || (!goalContainsDisabledFlag(currentGoal) && isPreemptedByAll(currentGoal) && currentGoal.canUse()))) {
            for (Goal.Flag flag : currentGoal.getFlags()) {
                final PrioritizedGoal prioritizedgoal = flagGoalsArray[flag.ordinal()];
                prioritizedgoal.stop();
                flagGoalsArray[flag.ordinal()] = currentGoal;
            }
            currentGoal.start();
        }
        if (currentGoal.isRunning()) {
            currentGoal.tick();
        }
    }
    if (counter > 3) {
        counter = 0;
    }
    this.profiler.get().pop();
}
Also used : Goal(net.minecraft.entity.ai.goal.Goal) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) ArrayList(java.util.ArrayList) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal)

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