Java Code Examples for net.minecraft.util.MathHelper.sqrt_double()

The following are Jave code examples for showing how to use sqrt_double() of the net.minecraft.util.MathHelper class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: BaseClient   File: EntityFireball.java   Source Code and License Vote up 6 votes
public EntityFireball(World worldIn, EntityLivingBase shooter, double accelX, double accelY, double accelZ)
{
    super(worldIn);
    this.shootingEntity = shooter;
    this.setSize(1.0F, 1.0F);
    this.setLocationAndAngles(shooter.posX, shooter.posY, shooter.posZ, shooter.rotationYaw, shooter.rotationPitch);
    this.setPosition(this.posX, this.posY, this.posZ);
    this.motionX = this.motionY = this.motionZ = 0.0D;
    accelX = accelX + this.rand.nextGaussian() * 0.4D;
    accelY = accelY + this.rand.nextGaussian() * 0.4D;
    accelZ = accelZ + this.rand.nextGaussian() * 0.4D;
    double d0 = (double)MathHelper.sqrt_double(accelX * accelX + accelY * accelY + accelZ * accelZ);
    this.accelerationX = accelX / d0 * 0.1D;
    this.accelerationY = accelY / d0 * 0.1D;
    this.accelerationZ = accelZ / d0 * 0.1D;
}
 
Example 2
Project: BaseClient   File: EntityThrowable.java   Source Code and License Vote up 6 votes
/**
 * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
 */
public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy)
{
    float f = MathHelper.sqrt_double(x * x + y * y + z * z);
    x = x / (double)f;
    y = y / (double)f;
    z = z / (double)f;
    x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
    y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
    z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
    x = x * (double)velocity;
    y = y * (double)velocity;
    z = z * (double)velocity;
    this.motionX = x;
    this.motionY = y;
    this.motionZ = z;
    float f1 = MathHelper.sqrt_double(x * x + z * z);
    this.prevRotationYaw = this.rotationYaw = (float)(MathHelper.func_181159_b(x, z) * 180.0D / Math.PI);
    this.prevRotationPitch = this.rotationPitch = (float)(MathHelper.func_181159_b(y, (double)f1) * 180.0D / Math.PI);
    this.ticksInGround = 0;
}
 
Example 3
Project: BaseClient   File: EntityGhast.java   Source Code and License Vote up 5 votes
public void onUpdateMoveHelper()
{
    if (this.update)
    {
        double d0 = this.posX - this.parentEntity.posX;
        double d1 = this.posY - this.parentEntity.posY;
        double d2 = this.posZ - this.parentEntity.posZ;
        double d3 = d0 * d0 + d1 * d1 + d2 * d2;

        if (this.courseChangeCooldown-- <= 0)
        {
            this.courseChangeCooldown += this.parentEntity.getRNG().nextInt(5) + 2;
            d3 = (double)MathHelper.sqrt_double(d3);

            if (this.isNotColliding(this.posX, this.posY, this.posZ, d3))
            {
                this.parentEntity.motionX += d0 / d3 * 0.1D;
                this.parentEntity.motionY += d1 / d3 * 0.1D;
                this.parentEntity.motionZ += d2 / d3 * 0.1D;
            }
            else
            {
                this.update = false;
            }
        }
    }
}
 
Example 4
Project: BaseClient   File: EntityFireball.java   Source Code and License Vote up 5 votes
public EntityFireball(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ)
{
    super(worldIn);
    this.setSize(1.0F, 1.0F);
    this.setLocationAndAngles(x, y, z, this.rotationYaw, this.rotationPitch);
    this.setPosition(x, y, z);
    double d0 = (double)MathHelper.sqrt_double(accelX * accelX + accelY * accelY + accelZ * accelZ);
    this.accelerationX = accelX / d0 * 0.1D;
    this.accelerationY = accelY / d0 * 0.1D;
    this.accelerationZ = accelZ / d0 * 0.1D;
}
 
Example 5
Project: BaseClient   File: EntityThrowable.java   Source Code and License Vote up 5 votes
/**
 * Sets the velocity to the args. Args: x, y, z
 */
public void setVelocity(double x, double y, double z)
{
    this.motionX = x;
    this.motionY = y;
    this.motionZ = z;

    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
    {
        float f = MathHelper.sqrt_double(x * x + z * z);
        this.prevRotationYaw = this.rotationYaw = (float)(MathHelper.func_181159_b(x, z) * 180.0D / Math.PI);
        this.prevRotationPitch = this.rotationPitch = (float)(MathHelper.func_181159_b(y, (double)f) * 180.0D / Math.PI);
    }
}
 
Example 6
Project: BaseClient   File: EntityFX.java   Source Code and License Vote up 5 votes
public EntityFX(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn)
{
    this(worldIn, xCoordIn, yCoordIn, zCoordIn);
    this.motionX = xSpeedIn + (Math.random() * 2.0D - 1.0D) * 0.4000000059604645D;
    this.motionY = ySpeedIn + (Math.random() * 2.0D - 1.0D) * 0.4000000059604645D;
    this.motionZ = zSpeedIn + (Math.random() * 2.0D - 1.0D) * 0.4000000059604645D;
    float f = (float)(Math.random() + Math.random() + 1.0D) * 0.15F;
    float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
    this.motionX = this.motionX / (double)f1 * (double)f * 0.4000000059604645D;
    this.motionY = this.motionY / (double)f1 * (double)f * 0.4000000059604645D + 0.10000000149011612D;
    this.motionZ = this.motionZ / (double)f1 * (double)f * 0.4000000059604645D;
}
 
Example 7
Project: BaseClient   File: EntityEnderEye.java   Source Code and License Vote up 5 votes
/**
 * Sets the velocity to the args. Args: x, y, z
 */
public void setVelocity(double x, double y, double z)
{
    this.motionX = x;
    this.motionY = y;
    this.motionZ = z;

    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
    {
        float f = MathHelper.sqrt_double(x * x + z * z);
        this.prevRotationYaw = this.rotationYaw = (float)(MathHelper.func_181159_b(x, z) * 180.0D / Math.PI);
        this.prevRotationPitch = this.rotationPitch = (float)(MathHelper.func_181159_b(y, (double)f) * 180.0D / Math.PI);
    }
}
 
Example 8
Project: BaseClient   File: EntitySnowman.java   Source Code and License Vote up 5 votes
/**
 * Attack the specified entity using a ranged attack.
 */
public void attackEntityWithRangedAttack(EntityLivingBase p_82196_1_, float p_82196_2_)
{
    EntitySnowball entitysnowball = new EntitySnowball(this.worldObj, this);
    double d0 = p_82196_1_.posY + (double)p_82196_1_.getEyeHeight() - 1.100000023841858D;
    double d1 = p_82196_1_.posX - this.posX;
    double d2 = d0 - entitysnowball.posY;
    double d3 = p_82196_1_.posZ - this.posZ;
    float f = MathHelper.sqrt_double(d1 * d1 + d3 * d3) * 0.2F;
    entitysnowball.setThrowableHeading(d1, d2 + (double)f, d3, 1.6F, 12.0F);
    this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
    this.worldObj.spawnEntityInWorld(entitysnowball);
}
 
Example 9
Project: BaseClient   File: EntityOtherPlayerMP.java   Source Code and License Vote up 5 votes
/**
 * Called to update the entity's position/logic.
 */
public void onUpdate()
{
    this.renderOffsetY = 0.0F;
    super.onUpdate();
    this.prevLimbSwingAmount = this.limbSwingAmount;
    double d0 = this.posX - this.prevPosX;
    double d1 = this.posZ - this.prevPosZ;
    float f = MathHelper.sqrt_double(d0 * d0 + d1 * d1) * 4.0F;

    if (f > 1.0F)
    {
        f = 1.0F;
    }

    this.limbSwingAmount += (f - this.limbSwingAmount) * 0.4F;
    this.limbSwing += this.limbSwingAmount;

    if (!this.isItemInUse && this.isEating() && this.inventory.mainInventory[this.inventory.currentItem] != null)
    {
        ItemStack itemstack = this.inventory.mainInventory[this.inventory.currentItem];
        this.setItemInUse(this.inventory.mainInventory[this.inventory.currentItem], itemstack.getItem().getMaxItemUseDuration(itemstack));
        this.isItemInUse = true;
    }
    else if (this.isItemInUse && !this.isEating())
    {
        this.clearItemInUse();
        this.isItemInUse = false;
    }
}
 
Example 10
Project: BaseClient   File: EntityGuardian.java   Source Code and License Vote up 4 votes
public void onUpdateMoveHelper()
{
    if (this.update && !this.entityGuardian.getNavigator().noPath())
    {
        double d0 = this.posX - this.entityGuardian.posX;
        double d1 = this.posY - this.entityGuardian.posY;
        double d2 = this.posZ - this.entityGuardian.posZ;
        double d3 = d0 * d0 + d1 * d1 + d2 * d2;
        d3 = (double)MathHelper.sqrt_double(d3);
        d1 = d1 / d3;
        float f = (float)(MathHelper.func_181159_b(d2, d0) * 180.0D / Math.PI) - 90.0F;
        this.entityGuardian.rotationYaw = this.limitAngle(this.entityGuardian.rotationYaw, f, 30.0F);
        this.entityGuardian.renderYawOffset = this.entityGuardian.rotationYaw;
        float f1 = (float)(this.speed * this.entityGuardian.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue());
        this.entityGuardian.setAIMoveSpeed(this.entityGuardian.getAIMoveSpeed() + (f1 - this.entityGuardian.getAIMoveSpeed()) * 0.125F);
        double d4 = Math.sin((double)(this.entityGuardian.ticksExisted + this.entityGuardian.getEntityId()) * 0.5D) * 0.05D;
        double d5 = Math.cos((double)(this.entityGuardian.rotationYaw * (float)Math.PI / 180.0F));
        double d6 = Math.sin((double)(this.entityGuardian.rotationYaw * (float)Math.PI / 180.0F));
        this.entityGuardian.motionX += d4 * d5;
        this.entityGuardian.motionZ += d4 * d6;
        d4 = Math.sin((double)(this.entityGuardian.ticksExisted + this.entityGuardian.getEntityId()) * 0.75D) * 0.05D;
        this.entityGuardian.motionY += d4 * (d6 + d5) * 0.25D;
        this.entityGuardian.motionY += (double)this.entityGuardian.getAIMoveSpeed() * d1 * 0.1D;
        EntityLookHelper entitylookhelper = this.entityGuardian.getLookHelper();
        double d7 = this.entityGuardian.posX + d0 / d3 * 2.0D;
        double d8 = (double)this.entityGuardian.getEyeHeight() + this.entityGuardian.posY + d1 / d3 * 1.0D;
        double d9 = this.entityGuardian.posZ + d2 / d3 * 2.0D;
        double d10 = entitylookhelper.getLookPosX();
        double d11 = entitylookhelper.getLookPosY();
        double d12 = entitylookhelper.getLookPosZ();

        if (!entitylookhelper.getIsLooking())
        {
            d10 = d7;
            d11 = d8;
            d12 = d9;
        }

        this.entityGuardian.getLookHelper().setLookPosition(d10 + (d7 - d10) * 0.125D, d11 + (d8 - d11) * 0.125D, d12 + (d9 - d12) * 0.125D, 10.0F, 40.0F);
        this.entityGuardian.func_175476_l(true);
    }
    else
    {
        this.entityGuardian.setAIMoveSpeed(0.0F);
        this.entityGuardian.func_175476_l(false);
    }
}
 
Example 11
Project: BaseClient   File: EntityFlying.java   Source Code and License Vote up 4 votes
/**
 * Moves the entity based on the specified heading.  Args: strafe, forward
 */
public void moveEntityWithHeading(float strafe, float forward)
{
    if (this.isInWater())
    {
        this.moveFlying(strafe, forward, 0.02F);
        this.moveEntity(this.motionX, this.motionY, this.motionZ);
        this.motionX *= 0.800000011920929D;
        this.motionY *= 0.800000011920929D;
        this.motionZ *= 0.800000011920929D;
    }
    else if (this.isInLava())
    {
        this.moveFlying(strafe, forward, 0.02F);
        this.moveEntity(this.motionX, this.motionY, this.motionZ);
        this.motionX *= 0.5D;
        this.motionY *= 0.5D;
        this.motionZ *= 0.5D;
    }
    else
    {
        float f = 0.91F;

        if (this.onGround)
        {
            f = this.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.getEntityBoundingBox().minY) - 1, MathHelper.floor_double(this.posZ))).getBlock().slipperiness * 0.91F;
        }

        float f1 = 0.16277136F / (f * f * f);
        this.moveFlying(strafe, forward, this.onGround ? 0.1F * f1 : 0.02F);
        f = 0.91F;

        if (this.onGround)
        {
            f = this.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.getEntityBoundingBox().minY) - 1, MathHelper.floor_double(this.posZ))).getBlock().slipperiness * 0.91F;
        }

        this.moveEntity(this.motionX, this.motionY, this.motionZ);
        this.motionX *= (double)f;
        this.motionY *= (double)f;
        this.motionZ *= (double)f;
    }

    this.prevLimbSwingAmount = this.limbSwingAmount;
    double d1 = this.posX - this.prevPosX;
    double d0 = this.posZ - this.prevPosZ;
    float f2 = MathHelper.sqrt_double(d1 * d1 + d0 * d0) * 4.0F;

    if (f2 > 1.0F)
    {
        f2 = 1.0F;
    }

    this.limbSwingAmount += (f2 - this.limbSwingAmount) * 0.4F;
    this.limbSwing += this.limbSwingAmount;
}
 
Example 12
Project: BaseClient   File: EntityFlying.java   Source Code and License Vote up 4 votes
/**
 * Moves the entity based on the specified heading.  Args: strafe, forward
 */
public void moveEntityWithHeading(float strafe, float forward)
{
    if (this.isInWater())
    {
        this.moveFlying(strafe, forward, 0.02F);
        this.moveEntity(this.motionX, this.motionY, this.motionZ);
        this.motionX *= 0.800000011920929D;
        this.motionY *= 0.800000011920929D;
        this.motionZ *= 0.800000011920929D;
    }
    else if (this.isInLava())
    {
        this.moveFlying(strafe, forward, 0.02F);
        this.moveEntity(this.motionX, this.motionY, this.motionZ);
        this.motionX *= 0.5D;
        this.motionY *= 0.5D;
        this.motionZ *= 0.5D;
    }
    else
    {
        float f = 0.91F;

        if (this.onGround)
        {
            f = this.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.getEntityBoundingBox().minY) - 1, MathHelper.floor_double(this.posZ))).getBlock().slipperiness * 0.91F;
        }

        float f1 = 0.16277136F / (f * f * f);
        this.moveFlying(strafe, forward, this.onGround ? 0.1F * f1 : 0.02F);
        f = 0.91F;

        if (this.onGround)
        {
            f = this.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.getEntityBoundingBox().minY) - 1, MathHelper.floor_double(this.posZ))).getBlock().slipperiness * 0.91F;
        }

        this.moveEntity(this.motionX, this.motionY, this.motionZ);
        this.motionX *= (double)f;
        this.motionY *= (double)f;
        this.motionZ *= (double)f;
    }

    this.prevLimbSwingAmount = this.limbSwingAmount;
    double d1 = this.posX - this.prevPosX;
    double d0 = this.posZ - this.prevPosZ;
    float f2 = MathHelper.sqrt_double(d1 * d1 + d0 * d0) * 4.0F;

    if (f2 > 1.0F)
    {
        f2 = 1.0F;
    }

    this.limbSwingAmount += (f2 - this.limbSwingAmount) * 0.4F;
    this.limbSwing += this.limbSwingAmount;
}
 
Example 13
Project: BaseClient   File: Entity.java   Source Code and License Vote up 4 votes
/**
 * Applies a velocity to each of the entities pushing them away from each other. Args: entity
 */
public void applyEntityCollision(Entity entityIn)
{
    if (entityIn.riddenByEntity != this && entityIn.ridingEntity != this)
    {
        if (!entityIn.noClip && !this.noClip)
        {
            double d0 = entityIn.posX - this.posX;
            double d1 = entityIn.posZ - this.posZ;
            double d2 = MathHelper.abs_max(d0, d1);

            if (d2 >= 0.009999999776482582D)
            {
                d2 = (double)MathHelper.sqrt_double(d2);
                d0 = d0 / d2;
                d1 = d1 / d2;
                double d3 = 1.0D / d2;

                if (d3 > 1.0D)
                {
                    d3 = 1.0D;
                }

                d0 = d0 * d3;
                d1 = d1 * d3;
                d0 = d0 * 0.05000000074505806D;
                d1 = d1 * 0.05000000074505806D;
                d0 = d0 * (double)(1.0F - this.entityCollisionReduction);
                d1 = d1 * (double)(1.0F - this.entityCollisionReduction);

                if (this.riddenByEntity == null)
                {
                    this.addVelocity(-d0, 0.0D, -d1);
                }

                if (entityIn.riddenByEntity == null)
                {
                    entityIn.addVelocity(d0, 0.0D, d1);
                }
            }
        }
    }
}
 
Example 14
Project: BaseClient   File: RealmsMth.java   Source Code and License Vote up 4 votes
public static float sqrt(double p_sqrt_0_)
{
    return MathHelper.sqrt_double(p_sqrt_0_);
}