Search in sources :

Example 11 with EntityAnimal

use of net.minecraft.entity.passive.EntityAnimal in project ImmersiveEngineering by BluSunrize.

the class TileEntityTurret method getTarget.

private EntityLivingBase getTarget() {
    double range = getRange();
    List<EntityLivingBase> list = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(getPos().getX() - range, getPos().getY(), getPos().getZ() - range, getPos().getX() + range, getPos().getY() + 3, getPos().getZ() + range));
    if (list.isEmpty())
        return null;
    EntityLivingBase target = null;
    for (EntityLivingBase entity : list) {
        if (entity == null || entity.isDead || entity.getHealth() <= 0 || !canSeeEntity(entity))
            continue;
        //Continue if blacklist and name is in list, or whitelist and name is not in list
        if (whitelist ^ isListedName(targetList, entity.getName()))
            continue;
        //Same as above but for the owner of the pet, to prevent shooting wolves
        if (entity instanceof IEntityOwnable) {
            Entity entityOwner = ((IEntityOwnable) entity).getOwner();
            if (entityOwner != null && (whitelist ^ isListedName(targetList, entityOwner.getName())))
                continue;
        }
        if (entity instanceof EntityAnimal && !attackAnimals)
            continue;
        if (entity instanceof EntityPlayer && !attackPlayers)
            continue;
        if (!(entity instanceof EntityPlayer) && !(entity instanceof EntityAnimal) && !entity.isCreatureType(EnumCreatureType.MONSTER, false) && !attackNeutrals)
            continue;
        if (target == null || entity.getDistanceSq(getPos()) < target.getDistanceSq(getPos()))
            target = entity;
    }
    return target;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IEntityOwnable(net.minecraft.entity.IEntityOwnable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityAnimal(net.minecraft.entity.passive.EntityAnimal)

Example 12 with EntityAnimal

use of net.minecraft.entity.passive.EntityAnimal 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 13 with EntityAnimal

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

Example 14 with EntityAnimal

use of net.minecraft.entity.passive.EntityAnimal in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class CallRunnerClient method onOrientCamera.

public static void onOrientCamera(EntityRenderer renderer, float partialTicks) {
    Entity entity = renderer.mc.getRenderViewEntity();
    BlockPos playerPos = new BlockPos(entity);
    PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(entity.worldObj, playerPos);
    if (wrapper != null) {
        Vector playerPosNew = new Vector(entity.posX, entity.posY, entity.posZ);
        RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.lToWTransform, playerPosNew);
        entity.posX = entity.prevPosX = entity.lastTickPosX = playerPosNew.X;
        entity.posY = entity.prevPosY = entity.lastTickPosY = playerPosNew.Y;
        entity.posZ = entity.prevPosZ = entity.lastTickPosZ = playerPosNew.Z;
    }
    Vector eyeVector = new Vector(0, entity.getEyeHeight(), 0);
    if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
        eyeVector.Y += .7D;
    }
    double d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double) partialTicks;
    double d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double) partialTicks;
    double d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) partialTicks;
    PhysicsWrapperEntity fixedOnto = ValkyrienWarfareMod.physicsManager.getShipFixedOnto(entity);
    //Probably overkill, but this should 100% fix the crash in issue #78
    if (fixedOnto != null && fixedOnto.wrapping != null && fixedOnto.wrapping.renderer != null && fixedOnto.wrapping.renderer.offsetPos != null) {
        Quaternion orientationQuat = fixedOnto.wrapping.renderer.getSmoothRotationQuat(partialTicks);
        double[] radians = orientationQuat.toRadians();
        float moddedPitch = (float) Math.toDegrees(radians[0]);
        float moddedYaw = (float) Math.toDegrees(radians[1]);
        float moddedRoll = (float) Math.toDegrees(radians[2]);
        double[] orientationMatrix = RotationMatrices.getRotationMatrix(moddedPitch, moddedYaw, moddedRoll);
        RotationMatrices.applyTransform(orientationMatrix, eyeVector);
        Vector playerPosition = new Vector(fixedOnto.wrapping.getLocalPositionForEntity(entity));
        RotationMatrices.applyTransform(fixedOnto.wrapping.coordTransform.RlToWTransform, playerPosition);
        d0 = playerPosition.X;
        d1 = playerPosition.Y;
        d2 = playerPosition.Z;
    //			entity.posX = entity.prevPosX = entity.lastTickPosX = d0;
    //			entity.posY = entity.prevPosY = entity.lastTickPosY = d1;
    //			entity.posZ = entity.prevPosZ = entity.lastTickPosZ = d2;
    }
    d0 += eyeVector.X;
    d1 += eyeVector.Y;
    d2 += eyeVector.Z;
    if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
        if (!renderer.mc.gameSettings.debugCamEnable) {
            //VW code starts here
            if (fixedOnto != null) {
                Vector playerPosInLocal = new Vector(fixedOnto.wrapping.getLocalPositionForEntity(entity));
                playerPosInLocal.subtract(.5D, .6875, .5);
                playerPosInLocal.roundToWhole();
                BlockPos bedPos = new BlockPos(playerPosInLocal.X, playerPosInLocal.Y, playerPosInLocal.Z);
                IBlockState state = renderer.mc.theWorld.getBlockState(bedPos);
                Block block = state.getBlock();
                float angleYaw = 0;
                if (block != null && block.isBed(state, entity.worldObj, bedPos, entity)) {
                    angleYaw = (float) (block.getBedDirection(state, entity.worldObj, bedPos).getHorizontalIndex() * 90);
                    angleYaw += 180;
                }
                entity.rotationYaw = entity.prevRotationYaw = angleYaw;
                entity.rotationPitch = entity.prevRotationPitch = 0;
            } else {
                BlockPos blockpos = new BlockPos(entity);
                IBlockState iblockstate = renderer.mc.theWorld.getBlockState(blockpos);
                net.minecraftforge.client.ForgeHooksClient.orientBedCamera(renderer.mc.theWorld, blockpos, iblockstate, entity);
                GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F, 0.0F, -1.0F, 0.0F);
                GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, -1.0F, 0.0F, 0.0F);
            }
        }
    } else if (renderer.mc.gameSettings.thirdPersonView > 0) {
        double d3 = (double) (renderer.thirdPersonDistancePrev + (4.0F - renderer.thirdPersonDistancePrev) * partialTicks);
        if (ClientPilotingManager.isPlayerPilotingShip()) {
            //TODO: Make this number scale with the Ship
            d3 = 15D;
        }
        if (renderer.mc.gameSettings.debugCamEnable) {
            GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
        } else {
            float f1 = entity.rotationYaw;
            float f2 = entity.rotationPitch;
            if (renderer.mc.gameSettings.thirdPersonView == 2) {
                f2 += 180.0F;
            }
            double d4 = (double) (-MathHelper.sin(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F)) * d3;
            double d5 = (double) (MathHelper.cos(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F)) * d3;
            double d6 = (double) (-MathHelper.sin(f2 * 0.017453292F)) * d3;
            for (int i = 0; i < 8; ++i) {
                float f3 = (float) ((i & 1) * 2 - 1);
                float f4 = (float) ((i >> 1 & 1) * 2 - 1);
                float f5 = (float) ((i >> 2 & 1) * 2 - 1);
                f3 = f3 * 0.1F;
                f4 = f4 * 0.1F;
                f5 = f5 * 0.1F;
                RayTraceResult raytraceresult = CallRunnerClient.rayTraceBlocksIgnoreShip(Minecraft.getMinecraft().theWorld, new Vec3d(d0 + (double) f3, d1 + (double) f4, d2 + (double) f5), new Vec3d(d0 - d4 + (double) f3 + (double) f5, d1 - d6 + (double) f4, d2 - d5 + (double) f5), false, false, false, ClientPilotingManager.getPilotedWrapperEntity());
                if (raytraceresult != null) {
                    double d7 = raytraceresult.hitVec.distanceTo(new Vec3d(d0, d1, d2));
                    if (d7 < d3) {
                        d3 = d7;
                    }
                }
            }
            if (renderer.mc.gameSettings.thirdPersonView == 2) {
                GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
            }
            GlStateManager.rotate(entity.rotationPitch - f2, 1.0F, 0.0F, 0.0F);
            GlStateManager.rotate(entity.rotationYaw - f1, 0.0F, 1.0F, 0.0F);
            GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
            GlStateManager.rotate(f1 - entity.rotationYaw, 0.0F, 1.0F, 0.0F);
            GlStateManager.rotate(f2 - entity.rotationPitch, 1.0F, 0.0F, 0.0F);
        }
    } else {
        GlStateManager.translate(0.0F, 0.0F, 0.05F);
    }
    if (!renderer.mc.gameSettings.debugCamEnable) {
        float yaw = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F;
        float pitch = entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks;
        float roll = 0.0F;
        if (entity instanceof EntityAnimal) {
            EntityAnimal entityanimal = (EntityAnimal) entity;
            yaw = entityanimal.prevRotationYawHead + (entityanimal.rotationYawHead - entityanimal.prevRotationYawHead) * partialTicks + 180.0F;
        }
        IBlockState state = ActiveRenderInfo.getBlockStateAtEntityViewpoint(renderer.mc.theWorld, entity, partialTicks);
        net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup event = new net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup(renderer, entity, state, partialTicks, yaw, pitch, roll);
        net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
        GlStateManager.rotate(event.getRoll(), 0.0F, 0.0F, 1.0F);
        GlStateManager.rotate(event.getPitch(), 1.0F, 0.0F, 0.0F);
        GlStateManager.rotate(event.getYaw(), 0.0F, 1.0F, 0.0F);
    }
    if (fixedOnto != null && fixedOnto.wrapping != null && fixedOnto.wrapping.renderer != null && fixedOnto.wrapping.renderer.offsetPos != null) {
        Quaternion orientationQuat = fixedOnto.wrapping.renderer.getSmoothRotationQuat(partialTicks);
        double[] radians = orientationQuat.toRadians();
        float moddedPitch = (float) Math.toDegrees(radians[0]);
        float moddedYaw = (float) Math.toDegrees(radians[1]);
        float moddedRoll = (float) Math.toDegrees(radians[2]);
        GlStateManager.rotate(-moddedRoll, 0.0F, 0.0F, 1.0F);
        GlStateManager.rotate(-moddedYaw, 0.0F, 1.0F, 0.0F);
        GlStateManager.rotate(-moddedPitch, 1.0F, 0.0F, 0.0F);
    }
    GlStateManager.translate(-eyeVector.X, -eyeVector.Y, -eyeVector.Z);
    d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double) partialTicks + eyeVector.X;
    d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double) partialTicks + eyeVector.Y;
    d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) partialTicks + eyeVector.Z;
    renderer.cloudFog = renderer.mc.renderGlobal.hasCloudFog(d0, d1, d2, partialTicks);
}
Also used : PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) Quaternion(ValkyrienWarfareBase.Math.Quaternion) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block) EnumSkyBlock(net.minecraft.world.EnumSkyBlock) BlockPos(net.minecraft.util.math.BlockPos) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) Vector(ValkyrienWarfareBase.API.Vector)

Aggregations

EntityAnimal (net.minecraft.entity.passive.EntityAnimal)14 Entity (net.minecraft.entity.Entity)7 EntityLivingBase (net.minecraft.entity.EntityLivingBase)7 TileEntity (net.minecraft.tileentity.TileEntity)7 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 EntityAmbientCreature (net.minecraft.entity.passive.EntityAmbientCreature)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemStack (net.minecraft.item.ItemStack)3 AMParticle (am2.particles.AMParticle)2 ParticleFloatUpward (am2.particles.ParticleFloatUpward)2 HashMap (java.util.HashMap)2 Block (net.minecraft.block.Block)2 IBlockState (net.minecraft.block.state.IBlockState)2 EntityLiving (net.minecraft.entity.EntityLiving)2 IMob (net.minecraft.entity.monster.IMob)2 Vector (ValkyrienWarfareBase.API.Vector)1 Quaternion (ValkyrienWarfareBase.Math.Quaternion)1 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)1 BuffEffectCharmed (am2.buffs.BuffEffectCharmed)1