Search in sources :

Example 51 with Vec3

use of net.minecraft.util.Vec3 in project ArsMagica2 by Mithion.

the class ModelFireGuardian method setModelRotations.

@SuppressWarnings("incomplete-switch")
private void setModelRotations(EntityFireGuardian entity, float f, float f1, float f2, float f3, float f4, float f5) {
    float entityOffset = 0;
    float leftArmRotation = 0;
    float rightArmRotation = 0;
    switch(entity.getCurrentAction()) {
        case SPINNING:
            /*entityOffset = (float) Math.cos((entity.getTicksInCurrentAction() + 10) / 10f) * 5;
			GL11.glTranslatef(0, entityOffset, 0);*/
            float stage = 35;
            if (!entity.getIsUnderground()) {
                if (entity.getTicksInCurrentAction() > stage) {
                    float offset = 3 * ((entity.getTicksInCurrentAction() + (f2 - entity.ticksExisted) - stage) / 5);
                    GL11.glTranslatef(0, -offset, 0);
                }
            } else {
                GL11.glTranslatef(0, 2, 0);
            }
            stage = 10;
            if (entity.getTicksInCurrentAction() > stage) {
                float rotation = 180 * ((entity.getTicksInCurrentAction() + (f2 - entity.ticksExisted) - stage) / 20);
                if (rotation > 180)
                    rotation = 180;
                Vec3 look = entity.getLook(1.0f);
                GL11.glRotatef(rotation, 0.5f, 0, 0);
            }
            rightArmRotation = leftArmRotation = (float) Math.toRadians(180);
            break;
        case LONG_CASTING:
            float max_degrees_x = 160;
            float final_degrees_x = 80;
            float max_pants_degrees = 45;
            float action_ticks = 10;
            float fast_action_ticks = 3;
            float final_action_ticks = 6;
            if (entity.getTicksInCurrentAction() < action_ticks) {
                rightArmRotation = (float) Math.toRadians(-max_degrees_x * ((entity.getTicksInCurrentAction() + (f2 - entity.ticksExisted)) / action_ticks));
            } else if (entity.getTicksInCurrentAction() < action_ticks + fast_action_ticks) {
                rightArmRotation = (float) Math.toRadians(-max_degrees_x + (final_degrees_x * ((entity.getTicksInCurrentAction() + (f2 - entity.ticksExisted) - action_ticks) / fast_action_ticks)));
            } else {
                rightArmRotation = final_degrees_x;
            }
            leftArmRotation = rightArmRotation;
            break;
        case CASTING:
            max_degrees_x = 160;
            final_degrees_x = 80;
            max_pants_degrees = 45;
            action_ticks = 10;
            fast_action_ticks = 3;
            final_action_ticks = 6;
            if (entity.getTicksInCurrentAction() < action_ticks) {
                rightArmRotation = (float) Math.toRadians(-max_degrees_x * ((entity.getTicksInCurrentAction() + (f2 - entity.ticksExisted)) / action_ticks));
            } else if (entity.getTicksInCurrentAction() < action_ticks + fast_action_ticks) {
                rightArmRotation = (float) Math.toRadians(-max_degrees_x + (final_degrees_x * ((entity.getTicksInCurrentAction() + (f2 - entity.ticksExisted) - action_ticks) / fast_action_ticks)));
            } else {
                rightArmRotation = final_degrees_x;
            }
            break;
    }
    RightArm1.rotateAngleX = RightArm1.getRestRotationX() + rightArmRotation;
    RightArm2.rotateAngleX = RightArm2.getRestRotationX() + rightArmRotation;
    LeftArm1.rotateAngleX = LeftArm1.getRestRotationX() + leftArmRotation;
    LeftArm2.rotateAngleX = LeftArm2.getRestRotationX() + leftArmRotation;
    float angle = (entity.ticksExisted % 33f) / 10f;
    float ambient = (float) Math.sin(angle) / 10f;
    RightArm1.rotateAngleZ = ambient;
    RightArm2.rotateAngleZ = ambient;
    LeftArm1.rotateAngleZ = -ambient;
    LeftArm2.rotateAngleZ = -ambient;
}
Also used : Vec3(net.minecraft.util.Vec3)

Example 52 with Vec3

use of net.minecraft.util.Vec3 in project ArsMagica2 by Mithion.

the class MathUtilities method getPointedEntity.

public static Entity getPointedEntity(World world, EntityLivingBase entityplayer, double range, double collideRadius, boolean nonCollide) {
    Entity pointedEntity = null;
    double d = range;
    Vec3 vec3d = Vec3.createVectorHelper(entityplayer.posX, entityplayer.posY + entityplayer.getEyeHeight(), entityplayer.posZ);
    Vec3 vec3d1 = entityplayer.getLookVec();
    Vec3 vec3d2 = vec3d.addVector(vec3d1.xCoord * d, vec3d1.yCoord * d, vec3d1.zCoord * d);
    double f1 = collideRadius;
    List list = world.getEntitiesWithinAABBExcludingEntity(entityplayer, entityplayer.boundingBox.addCoord(vec3d1.xCoord * d, vec3d1.yCoord * d, vec3d1.zCoord * d).expand(f1, f1, f1));
    double d2 = 0.0D;
    for (int i = 0; i < list.size(); i++) {
        Entity entity = (Entity) list.get(i);
        MovingObjectPosition mop = world.rayTraceBlocks(Vec3.createVectorHelper(entityplayer.posX, entityplayer.posY + entityplayer.getEyeHeight(), entityplayer.posZ), Vec3.createVectorHelper(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ), false);
        if (((entity.canBeCollidedWith()) || (nonCollide)) && mop == null) {
            float f2 = Math.max(0.8F, entity.getCollisionBorderSize());
            AxisAlignedBB axisalignedbb = entity.boundingBox.expand(f2, f2, f2);
            MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3d, vec3d2);
            if (axisalignedbb.isVecInside(vec3d)) {
                if ((0.0D < d2) || (d2 == 0.0D)) {
                    pointedEntity = entity;
                    d2 = 0.0D;
                }
            } else if (movingobjectposition != null) {
                double d3 = vec3d.distanceTo(movingobjectposition.hitVec);
                if ((d3 < d2) || (d2 == 0.0D)) {
                    pointedEntity = entity;
                    d2 = d3;
                }
            }
        }
    }
    return pointedEntity;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3) List(java.util.List) ArrayList(java.util.ArrayList)

Example 53 with Vec3

use of net.minecraft.util.Vec3 in project ArsMagica2 by Mithion.

the class MathUtilities method extrapolateEntityLook.

public static Vec3 extrapolateEntityLook(World par1World, EntityLivingBase entity, double range) {
    float var4 = 1.0F;
    float var5 = entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * var4;
    float var6 = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * var4;
    double var7 = entity.prevPosX + (entity.posX - entity.prevPosX) * var4;
    double var9 = entity.prevPosY + (entity.posY - entity.prevPosY) * var4 + 1.6D - entity.yOffset;
    double var11 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * var4;
    Vec3 var13 = Vec3.createVectorHelper(var7, var9, var11);
    float var14 = MathHelper.cos(-var6 * 0.017453292F - (float) Math.PI);
    float var15 = MathHelper.sin(-var6 * 0.017453292F - (float) Math.PI);
    float var16 = -MathHelper.cos(-var5 * 0.017453292F);
    float var17 = MathHelper.sin(-var5 * 0.017453292F);
    float var18 = var15 * var16;
    float var20 = var14 * var16;
    double var21 = range;
    Vec3 var23 = var13.addVector(var18 * var21, var17 * var21, var20 * var21);
    return var23;
}
Also used : Vec3(net.minecraft.util.Vec3)

Example 54 with Vec3

use of net.minecraft.util.Vec3 in project SecurityCraft by Geforce132.

the class TileEntitySCTE method updateEntity.

public void updateEntity() {
    if (viewActivated) {
        if (blockPlaceCooldown > 0) {
            blockPlaceCooldown--;
            return;
        }
        if (viewCooldown > 0) {
            viewCooldown--;
            return;
        }
        int i = xCoord;
        int j = yCoord;
        int k = zCoord;
        AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(i, j, k, i, j, k).expand(5, 5, 5);
        List<?> list = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
        Iterator<?> iterator = list.iterator();
        EntityLivingBase entity;
        while (iterator.hasNext()) {
            entity = (EntityLivingBase) iterator.next();
            double eyeHeight = entity.getEyeHeight();
            boolean isPlayer = (entity instanceof EntityPlayer);
            Vec3 lookVec = Vec3.createVectorHelper((entity.posX + (entity.getLookVec().xCoord * 5)), ((eyeHeight + entity.posY) + (entity.getLookVec().yCoord * 5)), (entity.posZ + (entity.getLookVec().zCoord * 5)));
            MovingObjectPosition mop = worldObj.rayTraceBlocks(Vec3.createVectorHelper(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ), lookVec);
            if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
                if (mop.blockX == xCoord && mop.blockY == yCoord && mop.blockZ == zCoord) {
                    if ((isPlayer && activatedOnlyByPlayer()) || !activatedOnlyByPlayer()) {
                        entityViewed(entity);
                        viewCooldown = getViewCooldown();
                    }
                }
            }
        }
    }
    if (attacks) {
        if (attackCooldown < getTicksBetweenAttacks()) {
            attackCooldown++;
            return;
        }
        if (canAttack()) {
            int i = xCoord;
            int j = yCoord;
            int k = zCoord;
            AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(i, j, k, i + 1, j + 1, k + 1).expand(getAttackRange(), getAttackRange(), getAttackRange());
            List<?> list = this.worldObj.getEntitiesWithinAABB(entityTypeToAttack(), axisalignedbb);
            Iterator<?> iterator = list.iterator();
            if (!worldObj.isRemote) {
                boolean attacked = false;
                while (iterator.hasNext()) {
                    Entity mobToAttack = (Entity) iterator.next();
                    if (mobToAttack == null || mobToAttack instanceof EntityItem || !shouldAttackEntityType(mobToAttack)) {
                        continue;
                    }
                    if (attackEntity(mobToAttack)) {
                        attacked = true;
                    }
                }
                if (attacked || shouldRefreshAttackCooldown()) {
                    attackCooldown = 0;
                }
                if (attacked || shouldSyncToClient()) {
                    sync();
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) S35PacketUpdateTileEntity(net.minecraft.network.play.server.S35PacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem)

Example 55 with Vec3

use of net.minecraft.util.Vec3 in project SecurityCraft by Geforce132.

the class ForgeEventHandler method getMovingObjectPositionFromPlayer.

private MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean flag, double reach) {
    float f = 1.0F;
    float playerPitch = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * f;
    float playerYaw = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * f;
    double playerPosX = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * f;
    double playerPosY = (par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * f + 1.6200000000000001D) - par2EntityPlayer.yOffset;
    double playerPosZ = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * f;
    Vec3 vecPlayer = Vec3.createVectorHelper(playerPosX, playerPosY, playerPosZ);
    float cosYaw = MathHelper.cos(-playerYaw * 0.01745329F - 3.141593F);
    float sinYaw = MathHelper.sin(-playerYaw * 0.01745329F - 3.141593F);
    float cosPitch = -MathHelper.cos(-playerPitch * 0.01745329F);
    float sinPitch = -MathHelper.sin(-playerPitch * 0.01745329F);
    float pointX = sinYaw * cosPitch;
    float pointY = sinPitch;
    float pointZ = cosYaw * cosPitch;
    Vec3 vecPoint = vecPlayer.addVector(pointX * reach, pointY * reach, pointZ * reach);
    MovingObjectPosition movingobjectposition = par1World.rayTraceBlocks(vecPlayer, vecPoint, flag);
    return movingobjectposition;
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3)

Aggregations

Vec3 (net.minecraft.util.Vec3)58 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)19 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)12 Entity (net.minecraft.entity.Entity)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)11 ItemStack (net.minecraft.item.ItemStack)7 ArrayList (java.util.ArrayList)5 Random (java.util.Random)5 EntityItem (net.minecraft.entity.item.EntityItem)5 TileEntity (net.minecraft.tileentity.TileEntity)5 List (java.util.List)4 Block (net.minecraft.block.Block)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 ChunkPosition (net.minecraft.world.ChunkPosition)3 World (net.minecraft.world.World)3 Linear (com.microsoft.Malmo.Schemas.AnimationDecorator.Linear)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)2 IBlockState (net.minecraft.block.state.IBlockState)2 BlockPos (net.minecraft.util.BlockPos)2