Search in sources :

Example 6 with IMob

use of net.minecraft.entity.monster.IMob in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretHeadUtil method getTargetWithMinimumRange.

@SuppressWarnings("ConstantConditions")
public static Entity getTargetWithMinimumRange(TurretBase base, World worldObj, BlockPos pos, int turretRange, TurretHead turret) {
    Entity target = null;
    if (!worldObj.isRemote && base != null && base.getOwner() != null) {
        AxisAlignedBB axis = new AxisAlignedBB(pos.getX() - turretRange - 1, pos.getY() - turretRange - 1, pos.getZ() - turretRange - 1, pos.getX() + turretRange + 1, pos.getY() + turretRange + 1, pos.getZ() + turretRange + 1);
        List<EntityLivingBase> targets = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axis);
        for (EntityLivingBase target1 : targets) {
            if (base.isAttacksNeutrals() && ConfigHandler.globalCanTargetNeutrals) {
                if (target1 instanceof EntityAnimal && !target1.isDead && target1.getDistance(pos.getX(), pos.getY(), pos.getZ()) >= 3) {
                    target = target1;
                }
            }
            if (base.isAttacksNeutrals() && ConfigHandler.globalCanTargetNeutrals) {
                if (target1 instanceof EntityAmbientCreature && !target1.isDead && target1.getDistance(pos.getX(), pos.getY(), pos.getZ()) >= 3) {
                    target = target1;
                }
            }
            if (base.isAttacksMobs() && ConfigHandler.globalCanTargetMobs) {
                if (target1 instanceof IMob && !target1.isDead && target1.getDistance(pos.getX(), pos.getY(), pos.getZ()) >= 3) {
                    target = target1;
                }
            }
            if (base.isAttacksPlayers() && ConfigHandler.globalCanTargetPlayers) {
                if (target1 instanceof EntityPlayerMP && !target1.isDead && target1.getDistance(pos.getX(), pos.getY(), pos.getZ()) >= 3) {
                    EntityPlayerMP entity = (EntityPlayerMP) target1;
                    if (!isPlayerOwner(entity, base) && !isPlayerTrusted(entity, base) && !entity.capabilities.isCreativeMode) {
                        target = target1;
                    }
                }
            }
            if (target != null && turret != null) {
                if (base.isMultiTargeting() && isTargetAlreadyTargeted(base, target)) {
                    continue;
                }
                EntityLivingBase targetELB = (EntityLivingBase) target;
                if (canTurretSeeTarget(turret, targetELB) && targetELB.getHealth() > 0.0F) {
                    return target;
                }
            }
        }
    }
    return null;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IMob(net.minecraft.entity.monster.IMob) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) EntityAmbientCreature(net.minecraft.entity.passive.EntityAmbientCreature)

Aggregations

IMob (net.minecraft.entity.monster.IMob)6 Entity (net.minecraft.entity.Entity)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)3 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)2 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)2 EntityAmbientCreature (net.minecraft.entity.passive.EntityAmbientCreature)2 EntityAnimal (net.minecraft.entity.passive.EntityAnimal)2 IAnimals (net.minecraft.entity.passive.IAnimals)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 TileEntity (net.minecraft.tileentity.TileEntity)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 ItemMobCatcher (convenientadditions.item.tools.mobCatcher.ItemMobCatcher)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 DimensionStorage (mcjty.rftoolsdim.dimensions.DimensionStorage)1 EntityCreature (net.minecraft.entity.EntityCreature)1 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1