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()));
}
}
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();
}
}
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);
}
}
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();
}
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();
}
Aggregations