Search in sources :

Example 1 with Goal

use of net.minecraft.entity.ai.goal.Goal in project AgriCraft by AgriCraft.

the class GeneAnimalAttractant method onCropGrowthTick.

@SubscribeEvent
@SuppressWarnings("unused")
public void onCropGrowthTick(AgriCropEvent.Grow.General.Post event) {
    if (event.getCrop().world() != null && event.getCrop().hasPlant() && event.getCrop().isMature()) {
        BlockPos min = event.getCrop().getPosition().add(-RANGE, -RANGE, -RANGE);
        BlockPos max = event.getCrop().getPosition().add(RANGE, RANGE, RANGE);
        AxisAlignedBB range = new AxisAlignedBB(min, max);
        event.getCrop().world().getEntitiesWithinAABB(this.clazz, range, (entity) -> true).stream().map(entity -> CapabilityEatCropGoal.getInstance().getCropEatGoal(entity)).filter(Objects::nonNull).filter(goal -> goal.isSuitableTarget(event.getCrop())).forEach(goal -> goal.addPotentialTarget(event.getCrop()));
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) AgriNBT(com.infinityraider.agricraft.reference.AgriNBT) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) CompoundNBT(net.minecraft.nbt.CompoundNBT) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) Random(java.util.Random) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) EntityHelper(com.infinityraider.infinitylib.utility.EntityHelper) Goal(net.minecraft.entity.ai.goal.Goal) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) MobEntity(net.minecraft.entity.MobEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) AgriCraft(com.infinityraider.agricraft.AgriCraft) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) ImmutableSet(com.google.common.collect.ImmutableSet) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) Tuple(net.minecraft.util.Tuple) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Consumer(java.util.function.Consumer) EntityJoinWorldEvent(net.minecraftforge.event.entity.EntityJoinWorldEvent) List(java.util.List) Vector3f(net.minecraft.util.math.vector.Vector3f) AgriGenePair(com.infinityraider.agricraft.impl.v1.genetics.AgriGenePair) AgriCropEvent(com.infinityraider.agricraft.api.v1.event.AgriCropEvent) com.infinityraider.agricraft.api.v1.genetics(com.infinityraider.agricraft.api.v1.genetics) CapabilityEatCropGoal(com.infinityraider.agricraft.capability.CapabilityEatCropGoal) Objects(java.util.Objects) BlockPos(net.minecraft.util.math.BlockPos) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with Goal

use of net.minecraft.entity.ai.goal.Goal 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 Goal

use of net.minecraft.entity.ai.goal.Goal 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 4 with Goal

use of net.minecraft.entity.ai.goal.Goal 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 5 with Goal

use of net.minecraft.entity.ai.goal.Goal 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)

Aggregations

Goal (net.minecraft.entity.ai.goal.Goal)6 PrioritizedGoal (net.minecraft.entity.ai.goal.PrioritizedGoal)5 Map (java.util.Map)2 Set (java.util.Set)2 LivingEntity (net.minecraft.entity.LivingEntity)2 MobEntity (net.minecraft.entity.MobEntity)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 AgriCraft (com.infinityraider.agricraft.AgriCraft)1 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)1 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)1 AgriCropEvent (com.infinityraider.agricraft.api.v1.event.AgriCropEvent)1 com.infinityraider.agricraft.api.v1.genetics (com.infinityraider.agricraft.api.v1.genetics)1 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)1 CapabilityEatCropGoal (com.infinityraider.agricraft.capability.CapabilityEatCropGoal)1 AgriGenePair (com.infinityraider.agricraft.impl.v1.genetics.AgriGenePair)1 AgriNBT (com.infinityraider.agricraft.reference.AgriNBT)1 EntityHelper (com.infinityraider.infinitylib.utility.EntityHelper)1 List (java.util.List)1