Search in sources :

Example 1 with AvoidEntityGoal

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

Example 2 with AvoidEntityGoal

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);
    }
}
Also used : AvoidEntityGoal(net.minecraft.entity.ai.goal.AvoidEntityGoal) EndermanEntity(net.minecraft.entity.monster.EndermanEntity) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal) CreeperEntity(net.minecraft.entity.monster.CreeperEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with AvoidEntityGoal

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);
    }));
}
Also used : StriderEntity(net.minecraft.entity.passive.StriderEntity) EntityType(net.minecraft.entity.EntityType) Random(java.util.Random) Direction(net.minecraft.util.Direction) SpawnReason(net.minecraft.entity.SpawnReason) StriderEntity(net.minecraft.entity.passive.StriderEntity) PathType(net.minecraft.pathfinding.PathType) BlockState(net.minecraft.block.BlockState) HurtByTargetGoal(net.minecraft.entity.ai.goal.HurtByTargetGoal) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) Pose(net.minecraft.entity.Pose) MoveToBlockGoal(net.minecraft.entity.ai.goal.MoveToBlockGoal) ForgeEventFactory(net.minecraftforge.event.ForgeEventFactory) GroundPathNavigator(net.minecraft.pathfinding.GroundPathNavigator) AbstractFireBlock(net.minecraft.block.AbstractFireBlock) WaterAvoidingRandomWalkingGoal(net.minecraft.entity.ai.goal.WaterAvoidingRandomWalkingGoal) EntitySize(net.minecraft.entity.EntitySize) IWorldReader(net.minecraft.world.IWorldReader) PathNodeType(net.minecraft.pathfinding.PathNodeType) LookAtGoal(net.minecraft.entity.ai.goal.LookAtGoal) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) RangedAttackGoal(net.minecraft.entity.ai.goal.RangedAttackGoal) Attributes(net.minecraft.entity.ai.attributes.Attributes) IPacket(net.minecraft.network.IPacket) AvoidEntityGoal(net.minecraft.entity.ai.goal.AvoidEntityGoal) NetworkHooks(net.minecraftforge.fml.network.NetworkHooks) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal) ISelectionContext(net.minecraft.util.math.shapes.ISelectionContext) IServerWorld(net.minecraft.world.IServerWorld) Nonnull(javax.annotation.Nonnull) PathNavigator(net.minecraft.pathfinding.PathNavigator) WalkNodeProcessor(net.minecraft.pathfinding.WalkNodeProcessor) FluidTags(net.minecraft.tags.FluidTags) World(net.minecraft.world.World) PathFinder(net.minecraft.pathfinding.PathFinder) BlockPos(net.minecraft.util.math.BlockPos) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) DamageSource(net.minecraft.util.DamageSource) Blocks(net.minecraft.block.Blocks) SoundEvents(net.minecraft.util.SoundEvents) AttributeModifierMap(net.minecraft.entity.ai.attributes.AttributeModifierMap) ParticleTypes(net.minecraft.particles.ParticleTypes) MathHelper(net.minecraft.util.math.MathHelper) ModConfigs(hmag.ModConfigs) Fluid(net.minecraft.fluid.Fluid) LookRandomlyGoal(net.minecraft.entity.ai.goal.LookRandomlyGoal) IRangedAttackMob(net.minecraft.entity.IRangedAttackMob) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) SoundEvent(net.minecraft.util.SoundEvent) LookAtGoal(net.minecraft.entity.ai.goal.LookAtGoal) LookRandomlyGoal(net.minecraft.entity.ai.goal.LookRandomlyGoal) WaterAvoidingRandomWalkingGoal(net.minecraft.entity.ai.goal.WaterAvoidingRandomWalkingGoal) HurtByTargetGoal(net.minecraft.entity.ai.goal.HurtByTargetGoal) RangedAttackGoal(net.minecraft.entity.ai.goal.RangedAttackGoal) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

AvoidEntityGoal (net.minecraft.entity.ai.goal.AvoidEntityGoal)3 NearestAttackableTargetGoal (net.minecraft.entity.ai.goal.NearestAttackableTargetGoal)3 BlockState (net.minecraft.block.BlockState)2 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