use of de.teamlapen.vampirism.api.difficulty.IAdjustableLevel 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;
}
}
}
Aggregations