Search in sources :

Example 1 with IAdjustableLevel

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;
        }
    }
}
Also used : TotemTileEntity(de.teamlapen.vampirism.tileentity.TotemTileEntity) ServerWorld(net.minecraft.world.server.ServerWorld) DifficultyCalculator(de.teamlapen.vampirism.util.DifficultyCalculator) Object2BooleanMap(it.unimi.dsi.fastutil.objects.Object2BooleanMap) BiFunction(java.util.function.BiFunction) HunterBaseEntity(de.teamlapen.vampirism.entity.hunter.HunterBaseEntity) Object2BooleanArrayMap(it.unimi.dsi.fastutil.objects.Object2BooleanArrayMap) Block(net.minecraft.block.Block) GolemTargetNonVillageFactionGoal(de.teamlapen.vampirism.entity.goals.GolemTargetNonVillageFactionGoal) EventPriority(net.minecraftforge.eventbus.api.EventPriority) IFactionEntity(de.teamlapen.vampirism.api.entity.factions.IFactionEntity) Event(net.minecraftforge.eventbus.api.Event) CastleStairsBlock(de.teamlapen.vampirism.blocks.CastleStairsBlock) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) BlockState(net.minecraft.block.BlockState) IFactionSlayerItem(de.teamlapen.vampirism.api.items.IFactionSlayerItem) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) IItemWithTier(de.teamlapen.vampirism.api.items.IItemWithTier) PlayerEntity(net.minecraft.entity.player.PlayerEntity) VampirePlayer(de.teamlapen.vampirism.player.vampire.VampirePlayer) Predicate(java.util.function.Predicate) MinionEntity(de.teamlapen.vampirism.entity.minion.MinionEntity) Set(java.util.Set) EntityJoinWorldEvent(net.minecraftforge.event.entity.EntityJoinWorldEvent) Difficulty(de.teamlapen.vampirism.api.difficulty.Difficulty) CastleSlabBlock(de.teamlapen.vampirism.blocks.CastleSlabBlock) Logger(org.apache.logging.log4j.Logger) EffectiveSide(net.minecraftforge.fml.common.thread.EffectiveSide) Optional(java.util.Optional) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) IFaction(de.teamlapen.vampirism.api.entity.factions.IFaction) VampirismPlayerAttributes(de.teamlapen.vampirism.player.VampirismPlayerAttributes) CastleBricksBlock(de.teamlapen.vampirism.blocks.CastleBricksBlock) PotionItem(net.minecraft.item.PotionItem) IronGolemEntity(net.minecraft.entity.passive.IronGolemEntity) VampirismConfig(de.teamlapen.vampirism.config.VampirismConfig) AbstractVillagerEntity(net.minecraft.entity.merchant.villager.AbstractVillagerEntity) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) Helper(de.teamlapen.vampirism.util.Helper) Goal(net.minecraft.entity.ai.goal.Goal) AvoidEntityGoal(net.minecraft.entity.ai.goal.AvoidEntityGoal) net.minecraft.entity(net.minecraft.entity) IAdjustableLevel(de.teamlapen.vampirism.api.difficulty.IAdjustableLevel) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal) VampirismVampireSword(de.teamlapen.vampirism.items.VampirismVampireSword) net.minecraftforge.event.entity.living(net.minecraftforge.event.entity.living) Nullable(javax.annotation.Nullable) IExtendedCreatureVampirism(de.teamlapen.vampirism.api.entity.IExtendedCreatureVampirism) VampirismAPI(de.teamlapen.vampirism.api.VampirismAPI) VampireBaseEntity(de.teamlapen.vampirism.entity.vampire.VampireBaseEntity) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) TotemHelper(de.teamlapen.vampirism.tileentity.TotemHelper) AttachCapabilitiesEvent(net.minecraftforge.event.AttachCapabilitiesEvent) REFERENCE(de.teamlapen.vampirism.REFERENCE) VReference(de.teamlapen.vampirism.api.VReference) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) net.minecraft.entity.monster(net.minecraft.entity.monster) ResourceLocation(net.minecraft.util.ResourceLocation) EntityEvent(net.minecraftforge.event.entity.EntityEvent) LogManager(org.apache.logging.log4j.LogManager) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) AbstractVillagerEntity(net.minecraft.entity.merchant.villager.AbstractVillagerEntity) Difficulty(de.teamlapen.vampirism.api.difficulty.Difficulty) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbstractVillagerEntity(net.minecraft.entity.merchant.villager.AbstractVillagerEntity) ServerWorld(net.minecraft.world.server.ServerWorld) GolemTargetNonVillageFactionGoal(de.teamlapen.vampirism.entity.goals.GolemTargetNonVillageFactionGoal) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) Goal(net.minecraft.entity.ai.goal.Goal) AvoidEntityGoal(net.minecraft.entity.ai.goal.AvoidEntityGoal) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal) IronGolemEntity(net.minecraft.entity.passive.IronGolemEntity) GolemTargetNonVillageFactionGoal(de.teamlapen.vampirism.entity.goals.GolemTargetNonVillageFactionGoal) IFactionEntity(de.teamlapen.vampirism.api.entity.factions.IFactionEntity) IAdjustableLevel(de.teamlapen.vampirism.api.difficulty.IAdjustableLevel) TotemTileEntity(de.teamlapen.vampirism.tileentity.TotemTileEntity) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

REFERENCE (de.teamlapen.vampirism.REFERENCE)1 VReference (de.teamlapen.vampirism.api.VReference)1 VampirismAPI (de.teamlapen.vampirism.api.VampirismAPI)1 Difficulty (de.teamlapen.vampirism.api.difficulty.Difficulty)1 IAdjustableLevel (de.teamlapen.vampirism.api.difficulty.IAdjustableLevel)1 IExtendedCreatureVampirism (de.teamlapen.vampirism.api.entity.IExtendedCreatureVampirism)1 IFaction (de.teamlapen.vampirism.api.entity.factions.IFaction)1 IFactionEntity (de.teamlapen.vampirism.api.entity.factions.IFactionEntity)1 IFactionSlayerItem (de.teamlapen.vampirism.api.items.IFactionSlayerItem)1 IItemWithTier (de.teamlapen.vampirism.api.items.IItemWithTier)1 CastleBricksBlock (de.teamlapen.vampirism.blocks.CastleBricksBlock)1 CastleSlabBlock (de.teamlapen.vampirism.blocks.CastleSlabBlock)1 CastleStairsBlock (de.teamlapen.vampirism.blocks.CastleStairsBlock)1 VampirismConfig (de.teamlapen.vampirism.config.VampirismConfig)1 GolemTargetNonVillageFactionGoal (de.teamlapen.vampirism.entity.goals.GolemTargetNonVillageFactionGoal)1 HunterBaseEntity (de.teamlapen.vampirism.entity.hunter.HunterBaseEntity)1 MinionEntity (de.teamlapen.vampirism.entity.minion.MinionEntity)1 VampireBaseEntity (de.teamlapen.vampirism.entity.vampire.VampireBaseEntity)1 VampirismVampireSword (de.teamlapen.vampirism.items.VampirismVampireSword)1 VampirismPlayerAttributes (de.teamlapen.vampirism.player.VampirismPlayerAttributes)1