Search in sources :

Example 6 with PrioritizedGoal

use of net.minecraft.entity.ai.goal.PrioritizedGoal in project friends-and-foes by Faboslav.

the class CopperGolemEntity method becomeStatue.

private void becomeStatue() {
    NbtCompound entitySnapshot = this.takeEntitySnapshot();
    this.setEntitySnapshot(entitySnapshot);
    this.setAiDisabled(true);
    for (PrioritizedGoal goal : this.goalSelector.getRunningGoals().toList()) {
        goal.stop();
    }
    this.getNavigation().setSpeed(0);
    this.getNavigation().stop();
    this.getMoveControl().moveTo(this.getX(), this.getY(), this.getZ(), 0);
    this.getMoveControl().tick();
    this.getLookControl().lookAt(this.getLookControl().getLookX(), this.getLookControl().getLookY(), this.getLookControl().getLookZ());
    this.getLookControl().tick();
    this.intersectionChecked = false;
    this.jumping = false;
    this.setMovementSpeed(0.0F);
    this.prevHorizontalSpeed = 0.0F;
    this.horizontalSpeed = 0.0F;
    this.sidewaysSpeed = 0.0F;
    this.upwardSpeed = 0.0F;
    this.setVelocity(Vec3d.ZERO);
    this.velocityDirty = true;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal)

Example 7 with PrioritizedGoal

use of net.minecraft.entity.ai.goal.PrioritizedGoal in project Werewolves by TeamLapen.

the class ModEntityEventHandler method makeWerewolfFriendly.

/**
 * copy from {@link de.teamlapen.vampirism.entity.ModEntityEventHandler#makeVampireFriendly(String, MobEntity, Class, Class, int, BiFunction, Predicate)}
 */
public static <T extends MobEntity, S extends LivingEntity, Q extends NearestAttackableTargetGoal<S>> void makeWerewolfFriendly(String name, T entity, Class<Q> targetClass, Class<S> targetEntityClass, int attackPriority, BiFunction<T, Predicate<LivingEntity>, Q> replacement, Predicate<EntityType<? extends T>> typeCheck) {
    try {
        Goal target = null;
        for (PrioritizedGoal t : entity.targetSelector.availableGoals) {
            Goal g = t.getGoal();
            if (targetClass.equals(g.getClass()) && t.getPriority() == attackPriority && targetEntityClass.equals(((NearestAttackableTargetGoal<?>) g).targetType)) {
                target = g;
                break;
            }
        }
        if (target != null) {
            entity.targetSelector.removeGoal(target);
            EntityType<? extends T> type = (EntityType<? extends T>) entity.getType();
            if (typeCheck.test(type)) {
                Predicate<LivingEntity> newPredicate = nonWerewolfCheck;
                if (((Q) target).targetConditions.selector != null) {
                    newPredicate = newPredicate.and(((NearestAttackableTargetGoal<?>) target).targetConditions.selector);
                }
                entity.targetSelector.addGoal(attackPriority, replacement.apply(entity, newPredicate));
            }
        } else {
            if (entityAIReplacementWarnMap.getOrDefault(name, true)) {
                LOGGER.warn("Could not replace {} attack target task for {}", name, entity.getType().getDescription());
                entityAIReplacementWarnMap.put(name, false);
            }
        }
    } catch (Exception e) {
        LOGGER.error("Could not replace " + name + " attack target task for " + entity.getType().getDescription(), e);
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) LivingEntity(net.minecraft.entity.LivingEntity) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) Goal(net.minecraft.entity.ai.goal.Goal) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal)

Example 8 with PrioritizedGoal

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

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)

Example 9 with PrioritizedGoal

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

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)

Example 10 with PrioritizedGoal

use of net.minecraft.entity.ai.goal.PrioritizedGoal in project MCDoom by AzureDoom.

the class GladiatorEntity method onDeath.

@Override
public void onDeath(DamageSource source) {
    if (!this.world.isClient) {
        if (source == DamageSource.OUT_OF_WORLD) {
            this.setDeathState(1);
        }
        if (this.dataTracker.get(DEATH_STATE) == 0) {
            AreaEffectCloudEntity areaeffectcloudentity = new AreaEffectCloudEntity(this.world, this.getX(), this.getY(), this.getZ());
            areaeffectcloudentity.setParticleType(ParticleTypes.EXPLOSION);
            areaeffectcloudentity.setRadius(3.0F);
            areaeffectcloudentity.setDuration(55);
            areaeffectcloudentity.setPos(this.getX(), this.getY(), this.getZ());
            this.world.spawnEntity(areaeffectcloudentity);
            this.goalSelector.getRunningGoals().forEach(PrioritizedGoal::stop);
            this.onAttacking(this.getAttacker());
            this.world.sendEntityStatus(this, (byte) 3);
        }
        if (this.dataTracker.get(DEATH_STATE) == 1) {
            super.onDeath(source);
        }
    }
}
Also used : AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) 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