Search in sources :

Example 1 with EntityAmbientCreature

use of net.minecraft.entity.passive.EntityAmbientCreature in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretHeadUtil method getTarget.

@SuppressWarnings("ConstantConditions")
public static Entity getTarget(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 (target1 != null && EntityList.getEntityString(target1) != null) {
                if (ConfigHandler.validMobBlacklist.contains(EntityList.getEntityString(target1)))
                    continue;
            }
            if (base.isAttacksNeutrals() && ConfigHandler.globalCanTargetNeutrals) {
                if (target1 instanceof EntityAnimal && !target1.isDead) {
                    target = target1;
                }
            }
            if (base.isAttacksNeutrals() && ConfigHandler.globalCanTargetNeutrals) {
                if (target1 instanceof EntityAmbientCreature && !target1.isDead) {
                    target = target1;
                }
            }
            if (base.isAttacksMobs() && ConfigHandler.globalCanTargetMobs) {
                if (target1.isCreatureType(EnumCreatureType.MONSTER, false) && !target1.isDead) {
                    target = target1;
                }
            }
            if (base.isAttacksPlayers() && ConfigHandler.globalCanTargetPlayers) {
                if (target1 instanceof EntityPlayerMP && !target1.isDead) {
                    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) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) EntityAmbientCreature(net.minecraft.entity.passive.EntityAmbientCreature)

Example 2 with EntityAmbientCreature

use of net.minecraft.entity.passive.EntityAmbientCreature in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretHeadUtil method getTargetWithoutSlowEffect.

@SuppressWarnings("ConstantConditions")
public static Entity getTargetWithoutSlowEffect(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.isPotionActive(Potion.getPotionById(2))) {
                    target = target1;
                }
            }
            if (base.isAttacksNeutrals() && ConfigHandler.globalCanTargetNeutrals) {
                if (target1 instanceof EntityAmbientCreature && !target1.isDead && !target1.isPotionActive(Potion.getPotionById(2))) {
                    target = target1;
                }
            }
            if (base.isAttacksMobs() && ConfigHandler.globalCanTargetMobs) {
                if (target1 instanceof IMob && !target1.isDead && !target1.isPotionActive(Potion.getPotionById(2))) {
                    target = target1;
                }
            }
            if (base.isAttacksPlayers() && ConfigHandler.globalCanTargetPlayers) {
                if (target1 instanceof EntityPlayerMP && !target1.isDead && !target1.isPotionActive(Potion.getPotionById(2))) {
                    EntityPlayerMP entity = (EntityPlayerMP) target1;
                    if (!entity.getUniqueID().toString().equals(base.getOwner()) && !isPlayerTrusted(entity, base) && !entity.capabilities.isCreativeMode) {
                        target = target1;
                    }
                }
            }
            if (target != null && turret != null) {
                EntityLivingBase targetELB = (EntityLivingBase) target;
                if (base.isMultiTargeting() && isTargetAlreadyTargeted(base, target)) {
                    continue;
                }
                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)

Example 3 with EntityAmbientCreature

use of net.minecraft.entity.passive.EntityAmbientCreature 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

Entity (net.minecraft.entity.Entity)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)3 EntityAmbientCreature (net.minecraft.entity.passive.EntityAmbientCreature)3 EntityAnimal (net.minecraft.entity.passive.EntityAnimal)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 TileEntity (net.minecraft.tileentity.TileEntity)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 IMob (net.minecraft.entity.monster.IMob)2