use of net.minecraft.entity.ai.goal.AvoidEntityGoal in project Vampirism by TeamLapen.
the class ModEntityEventHandler method onEntityJoinWorld.
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
if (!event.getWorld().isClientSide()) {
if (event.getEntity() instanceof IAdjustableLevel) {
IAdjustableLevel entity = (IAdjustableLevel) event.getEntity();
if (entity.getLevel() == -1) {
Difficulty d = DifficultyCalculator.findDifficultyForPos(event.getWorld(), event.getEntity().blockPosition(), 30);
int l = entity.suggestLevel(d);
if (l > entity.getMaxLevel()) {
l = entity.getMaxLevel();
} else if (l < 0) {
event.setCanceled(true);
}
entity.setLevel(l);
if (entity instanceof CreatureEntity) {
((CreatureEntity) entity).setHealth(((CreatureEntity) entity).getMaxHealth());
}
}
}
// Creeper AI changes for AvoidedByCreepers Skill
if (VampirismConfig.BALANCE.creeperIgnoreVampire.get()) {
if (event.getEntity() instanceof CreeperEntity) {
((CreeperEntity) event.getEntity()).goalSelector.addGoal(3, new AvoidEntityGoal<>((CreeperEntity) event.getEntity(), PlayerEntity.class, 20, 1.1, 1.3, Helper::isVampire));
makeVampireFriendly("creeper", (CreeperEntity) event.getEntity(), NearestAttackableTargetGoal.class, PlayerEntity.class, 1, (entity, predicate) -> new NearestAttackableTargetGoal<>(entity, PlayerEntity.class, 10, true, false, predicate), type -> type == EntityType.CREEPER);
return;
}
}
// Zombie AI changes
if (VampirismConfig.BALANCE.zombieIgnoreVampire.get()) {
if (event.getEntity() instanceof ZombieEntity) {
makeVampireFriendly("zombie", (ZombieEntity) event.getEntity(), NearestAttackableTargetGoal.class, PlayerEntity.class, 2, (entity, predicate) -> entity instanceof DrownedEntity ? new NearestAttackableTargetGoal<>(entity, PlayerEntity.class, 10, true, false, predicate.and(((DrownedEntity) entity)::okTarget)) : new NearestAttackableTargetGoal<>(entity, PlayerEntity.class, 10, true, false, predicate), type -> type == EntityType.ZOMBIE || type == EntityType.HUSK || type == EntityType.ZOMBIE_VILLAGER || type == EntityType.DROWNED);
// Also replace attack villager task for entities that have it
makeVampireFriendly("villager zombie", (ZombieEntity) event.getEntity(), NearestAttackableTargetGoal.class, AbstractVillagerEntity.class, 3, (entity, predicate) -> new NearestAttackableTargetGoal<>(entity, AbstractVillagerEntity.class, 10, true, false, predicate), type -> type == EntityType.ZOMBIE || type == EntityType.HUSK || type == EntityType.ZOMBIE_VILLAGER || type == EntityType.DROWNED);
return;
}
}
if (VampirismConfig.BALANCE.skeletonIgnoreVampire.get()) {
if (event.getEntity() instanceof SkeletonEntity || event.getEntity() instanceof StrayEntity) {
makeVampireFriendly("skeleton", (AbstractSkeletonEntity) event.getEntity(), NearestAttackableTargetGoal.class, PlayerEntity.class, 2, (entity, predicate) -> new NearestAttackableTargetGoal<>(entity, PlayerEntity.class, 10, true, false, predicate), type -> type == EntityType.SKELETON || type == EntityType.STRAY);
}
}
if (event.getEntity() instanceof IronGolemEntity) {
((IronGolemEntity) event.getEntity()).targetSelector.addGoal(4, new GolemTargetNonVillageFactionGoal((IronGolemEntity) event.getEntity()));
Goal mobTarget = null;
for (PrioritizedGoal t : ((IronGolemEntity) event.getEntity()).targetSelector.availableGoals) {
if (t.getGoal() instanceof NearestAttackableTargetGoal && t.getPriority() == 3 && MobEntity.class.equals(((NearestAttackableTargetGoal<?>) t.getGoal()).targetType)) {
mobTarget = t.getGoal();
break;
}
}
if (mobTarget != null) {
((IronGolemEntity) event.getEntity()).targetSelector.removeGoal(mobTarget);
((IronGolemEntity) event.getEntity()).targetSelector.addGoal(3, new NearestAttackableTargetGoal<>((IronGolemEntity) event.getEntity(), MobEntity.class, 5, false, false, entity -> entity instanceof IMob && !(entity instanceof IFactionEntity) && !(entity instanceof CreeperEntity)));
} else {
if (warnAboutGolem) {
LOGGER.warn("Could not replace villager iron golem target task");
warnAboutGolem = false;
}
}
return;
}
if (event.getEntity() instanceof VillagerEntity) {
Optional<TotemTileEntity> tile = TotemHelper.getTotemNearPos(((ServerWorld) event.getWorld()), event.getEntity().blockPosition(), true);
if (tile.filter(t -> VReference.HUNTER_FACTION.equals(t.getControllingFaction())).isPresent()) {
ExtendedCreature.getSafe(event.getEntity()).ifPresent(e -> e.setPoisonousBlood(true));
}
return;
}
}
}
use of net.minecraft.entity.ai.goal.AvoidEntityGoal in project Hostile-Mobs-and-Girls by Mechalopa.
the class ModEvents method onEntityJoinWorld.
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
try {
if (event.getEntity() != null) {
if (event.getEntity() instanceof EndermanEntity) {
EndermanEntity endermanentity = (EndermanEntity) event.getEntity();
endermanentity.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(endermanentity, LivingEntity.class, 10, false, false, (p) -> {
if (!(p instanceof EndermanEntity) && p.hasEffect(ModEffects.ENDER_RAGE.get())) {
final double d0 = 8.0D + p.getEffect(ModEffects.ENDER_RAGE.get()).getAmplifier() * 12.0D;
return p.distanceToSqr(endermanentity) <= d0 * d0;
} else {
return false;
}
}).setUnseenMemoryTicks(30));
} else if (event.getEntity() instanceof CreeperEntity) {
CreeperEntity creeerentity = (CreeperEntity) event.getEntity();
creeerentity.goalSelector.addGoal(3, new AvoidEntityGoal<>(creeerentity, KashaEntity.class, 6.0F, 1.0D, 1.2D));
}
}
} catch (Exception e) {
HMaG.LOGGER.warn("Failed to add goals to mobs", (Throwable) e);
}
}
use of net.minecraft.entity.ai.goal.AvoidEntityGoal in project Hostile-Mobs-and-Girls by Mechalopa.
the class MeltyMonsterEntity method registerGoals.
@Override
protected void registerGoals() {
this.goalSelector.addGoal(2, new AvoidEntityGoal<>(this, StriderEntity.class, 10.0F, 1.0D, 1.5D));
this.goalSelector.addGoal(3, new MeltyMonsterEntity.MoveToLavaGoal(this, 1.5D));
this.goalSelector.addGoal(5, new RangedAttackGoal(this, 1.0D, 30, 40, 8.0F));
this.goalSelector.addGoal(6, new WaterAvoidingRandomWalkingGoal(this, 1.0D));
this.goalSelector.addGoal(7, new LookAtGoal(this, PlayerEntity.class, 8.0F));
this.goalSelector.addGoal(7, new LookRandomlyGoal(this));
this.targetSelector.addGoal(1, new HurtByTargetGoal(this));
this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, 10, true, false, (p) -> {
return !(p.getVehicle() instanceof StriderEntity);
}));
}
Aggregations