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