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