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

The following examples show how to use net.minecraft.util.MathHelper#sqrt_double() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public EntityLaser(World par1World, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase, float par4, float par5) {
    super(par1World);
    this.renderDistanceWeight = 10.0D;
    this.shootingEntity = par2EntityLivingBase;

    this.posY = par2EntityLivingBase.posY + (double) par2EntityLivingBase.getEyeHeight() - 0.10000000149011612D;
    double d0 = par3EntityLivingBase.posX - par2EntityLivingBase.posX;
    double d1 = par3EntityLivingBase.boundingBox.minY + (double) (par3EntityLivingBase.height / 3.0F) - this.posY;
    double d2 = par3EntityLivingBase.posZ - par2EntityLivingBase.posZ;
    double d3 = (double) MathHelper.sqrt_double(d0 * d0 + d2 * d2);

    if (d3 >= 1.0E-7D) {
        float f2 = (float) (Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
        float f3 = (float) (-(Math.atan2(d1, d3) * 180.0D / Math.PI));
        double d4 = d0 / d3;
        double d5 = d2 / d3;
        this.setLocationAndAngles(par2EntityLivingBase.posX + d4, this.posY, par2EntityLivingBase.posZ + d5, f2, f3);
        this.yOffset = 0.0F;
        float f4 = (float) d3 * 0.2F;
        this.setThrowableHeading(d0, d1 + (double) f4, d2, par4, par5);
    }
}
 
Example 2
public void setThrowableHeading(double par1, double par3, double par5, float par7, float par8) {
    float f2 = MathHelper.sqrt_double(par1 * par1 + par3 * par3 + par5 * par5);
    par1 /= (double) f2;
    par3 /= (double) f2;
    par5 /= (double) f2;
    par1 += this.rand.nextGaussian() * (double) (this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double) par8;
    par3 += this.rand.nextGaussian() * (double) (this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double) par8;
    par5 += this.rand.nextGaussian() * (double) (this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double) par8;
    par1 *= (double) par7;
    par3 *= (double) par7;
    par5 *= (double) par7;
    this.motionX = par1;
    this.motionY = par3;
    this.motionZ = par5;
    float f3 = MathHelper.sqrt_double(par1 * par1 + par5 * par5);
    this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(par1, par5) * 180.0D / Math.PI);
    this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(par3, (double) f3) * 180.0D / Math.PI);
    this.ticksInGround = 0;
}
 
Example 3
@SideOnly(Side.CLIENT)
public void setVelocity(double par1, double par3, double par5) {
    this.motionX = par1;
    this.motionY = par3;
    this.motionZ = par5;

    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
        float f = MathHelper.sqrt_double(par1 + par5);
        this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(par1, par5) / Math.PI);
        this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(par3, (double) f) / Math.PI);
        this.prevRotationPitch = this.rotationPitch;
        this.prevRotationYaw = this.rotationYaw;
        this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
        this.ticksInGround = 0;
    }
}
 
Example 4
public static void bigsmack(Entity entity, Entity entity1, float force)
{
    double d = entity.posX - entity1.posX;
    double d1 = entity.posZ - entity1.posZ;
    for (d1 = entity.posZ - entity1.posZ; ((d * d) + (d1 * d1)) < 0.0001D; d1 = (Math.random() - Math.random()) * 0.01D)
    {
        d = (Math.random() - Math.random()) * 0.01D;
    }

    float f = MathHelper.sqrt_double((d * d) + (d1 * d1));
    // float f1 = 0.25F;
    /*
     * if(getKittyState() == 10) { f1 = 0.1F; }
     */
    entity1.motionX /= 2D;
    entity1.motionY /= 2D;
    entity1.motionZ /= 2D;
    entity1.motionX -= (d / f) * force;
    entity1.motionY += force;// 0.300000005960465D;
    entity1.motionZ -= (d1 / f) * force;
    if (entity1.motionY > force)// 0.3D)
    {
        entity1.motionY = force;// 0.3D;
    }
}
 
Example 5
public void setThrowableHeading(double par1, double par3, double par5, float par7, float par8) {
	float f2 = MathHelper.sqrt_double(par1 * par1 + par3 * par3 + par5 * par5);
	par1 /= (double) f2;
	par3 /= (double) f2;
	par5 /= (double) f2;
	par1 += this.rand.nextGaussian() * (double) (this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double) par8;
	par3 += this.rand.nextGaussian() * (double) (this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double) par8;
	par5 += this.rand.nextGaussian() * (double) (this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double) par8;
	par1 *= (double) par7;
	par3 *= (double) par7;
	par5 *= (double) par7;
	this.motionX = par1;
	this.motionY = par3;
	this.motionZ = par5;
	float f3 = MathHelper.sqrt_double(par1 * par1 + par5 * par5);
	this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(par1, par5) * 180.0D / Math.PI);
	this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(par3, (double) f3) * 180.0D / Math.PI);
	this.ticksInGround = 0;
}
 
Example 6
Source Project: WirelessRedstone   File: EntityREP.java    License: MIT License 6 votes vote down vote up
public void setREPHeading(double d, double d1, double d2, float f,
                          float f1) {
    float f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2);
    d /= f2;
    d1 /= f2;
    d2 /= f2;
    d += rand.nextGaussian() * 0.0074999998323619366D * f1;
    d1 += rand.nextGaussian() * 0.0074999998323619366D * f1;
    d2 += rand.nextGaussian() * 0.0074999998323619366D * f1;
    d *= f;
    d1 *= f;
    d2 *= f;
    motionX = d;
    motionY = d1;
    motionZ = d2;
    float f3 = MathHelper.sqrt_double(d * d + d2 * d2);
    prevRotationYaw = rotationYaw = (float) ((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
    prevRotationPitch = rotationPitch = (float) ((Math.atan2(d1, f3) * 180D) / 3.1415927410125732D);
    ticksInGroundREP = 0;
}
 
Example 7
@Override
protected void attackEntity(Entity entity, float f)
{
    if (getIsHumanForm())
    {
        entityToAttack = null;
        return;
    }
    if ((f > 2.0F) && (f < 6F) && (rand.nextInt(15) == 0))
    {
        if (onGround)
        {
            setHunched(true);
            double d = entity.posX - posX;
            double d1 = entity.posZ - posZ;
            float f1 = MathHelper.sqrt_double((d * d) + (d1 * d1));
            motionX = ((d / f1) * 0.5D * 0.80000001192092896D) + (motionX * 0.20000000298023221D);
            motionZ = ((d1 / f1) * 0.5D * 0.80000001192092896D) + (motionZ * 0.20000000298023221D);
            motionY = 0.40000000596046448D;
        }
    }
    else
    {
        if (attackTime <= 0 && (f < 2.5D) && (entity.boundingBox.maxY > boundingBox.minY) && (entity.boundingBox.minY < boundingBox.maxY))
        {
            attackTime = 20;
            entity.attackEntityFrom(DamageSource.causeMobDamage(this), 2);
            if (this.getType() == 4)
            {
                ((EntityLiving) entity).setFire(10);
            }
        }

    }
}
 
Example 8
Source Project: ehacks-pro   File: AimBot.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void faceEntity(Entity e) {
    double x = e.posX - Wrapper.INSTANCE.player().posX;
    double y = e.posY - Wrapper.INSTANCE.player().posY;
    double z = e.posZ - Wrapper.INSTANCE.player().posZ;
    double d1 = Wrapper.INSTANCE.player().posY + Wrapper.INSTANCE.player().getEyeHeight() - (e.posY + e.getEyeHeight());
    double d3 = MathHelper.sqrt_double((x * x + z * z));
    float f = (float) (Math.atan2(z, x) * 180.0 / 3.141592653589793) - 90.0f;
    float f1 = (float) (-Math.atan2(d1, d3) * 180.0 / 3.141592653589793);
    Wrapper.INSTANCE.player().setPositionAndRotation(Wrapper.INSTANCE.player().posX, Wrapper.INSTANCE.player().posY, Wrapper.INSTANCE.player().posZ, f, -f1);
}
 
Example 9
@Override
protected void attackEntity(Entity entity, float f)
{
    if (attackTime <= 0 && (f > 2.0F) && (f < 6F) && (rand.nextInt(50) == 0))
    {
        if (onGround)
        {
            double d = entity.posX - posX;
            double d1 = entity.posZ - posZ;
            float f1 = MathHelper.sqrt_double((d * d) + (d1 * d1));
            motionX = ((d / f1) * 0.5D * 0.8D) + (motionX * 0.2D);
            motionZ = ((d1 / f1) * 0.5D * 0.8D) + (motionZ * 0.2D);
            motionY = 0.4D;
        }
        return;

    }

    if (this.attackTime <= 0 && (f < 2.5D) && (entity.boundingBox.maxY > boundingBox.minY) && (entity.boundingBox.minY < boundingBox.maxY))
    {
        attackTime = 20;
        entity.attackEntityFrom(DamageSource.causeMobDamage(this), getForce());
        if (!(entity instanceof EntityPlayer))
        {
            MoCTools.destroyDrops(this, 3D);
        }
    }
}
 
Example 10
public void setDirection(Vector direction) {
    Validate.notNull(direction, "Direction can not be null");
    double x = direction.getX();
    double y = direction.getY();
    double z = direction.getZ();
    double magnitude = (double) MathHelper.sqrt_double(x * x + y * y + z * z);
    getHandle().accelerationX = x / magnitude;
    getHandle().accelerationY = y / magnitude;
    getHandle().accelerationZ = z / magnitude;
}
 
Example 11
Source Project: TickDynamic   File: Entity.java    License: MIT License 5 votes vote down vote up
/**
 * Applies a velocity to each of the entities pushing them away from each other. Args: entity
 */
public void applyEntityCollision(Entity p_70108_1_)
{
    if (p_70108_1_.riddenByEntity != this && p_70108_1_.ridingEntity != this)
    {
        double d0 = p_70108_1_.posX - this.posX;
        double d1 = p_70108_1_.posZ - this.posZ;
        double d2 = MathHelper.abs_max(d0, d1);

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

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

            d0 *= d3;
            d1 *= d3;
            d0 *= 0.05000000074505806D;
            d1 *= 0.05000000074505806D;
            d0 *= (double)(1.0F - this.entityCollisionReduction);
            d1 *= (double)(1.0F - this.entityCollisionReduction);
            this.addVelocity(-d0, 0.0D, -d1);
            p_70108_1_.addVelocity(d0, 0.0D, d1);
        }
    }
}
 
Example 12
@Override
public void onUpdate(){
    double endX = targetEntity.posX;
    double endY = targetEntity.posY;
    double endZ = targetEntity.posZ;
    prevRotationYaw = rotationYaw;
    prevRotationPitch = rotationPitch;

    if(ring == null) {
        ring = new RenderRing(posX, posY, posZ, endX, endY, endZ, color);
    } else {
        if(oldRing == null) {
            oldRing = new RenderRing(ring.startX, ring.startY, ring.startZ, ring.endX, ring.endY, ring.endZ, color);
        } else {
            oldRing.endX = ring.endX;
            oldRing.endY = ring.endY;
            oldRing.endZ = ring.endZ;
        }
        ring.endX = endX;
        ring.endY = endY;
        ring.endZ = endZ;

        double dx = endX - posX;
        double dy = endY - posY;
        double dz = endZ - posZ;
        float f = MathHelper.sqrt_double(dx * dx + dz * dz);
        rotationYaw = (float)(Math.atan2(dx, dz) * 180.0D / Math.PI);
        rotationPitch = (float)(Math.atan2(dy, f) * 180.0D / Math.PI);

        oldRing.setProgress(ring.getProgress());
        if(ring.incProgress(0.05F)) {
            setDead();
        }
    }
}
 
Example 13
Source Project: WirelessRedstone   File: EntityREP.java    License: MIT License 5 votes vote down vote up
public void setVelocity(double d, double d1, double d2) {
    motionX = d;
    motionY = d1;
    motionZ = d2;
    if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) {
        float f = MathHelper.sqrt_double(d * d + d2 * d2);
        prevRotationYaw = rotationYaw = (float) ((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
        prevRotationPitch = rotationPitch = (float) ((Math.atan2(d1, f) * 180D) / 3.1415927410125732D);
    }
}
 
Example 14
public void faceLocation(int i, int j, int k, float f)
{
	double var4 = i + 0.5D - posX;
	double var8 = k + 0.5D - posZ;
	double var6 = j + 0.5D - posY;
	double var14 = (double) MathHelper.sqrt_double(var4 * var4 + var8 * var8);
	float var12 = (float) (Math.atan2(var8, var4) * 180.0D / Math.PI) - 90.0F;
	float var13 = (float) (-(Math.atan2(var6, var14) * 180.0D / Math.PI));
	this.rotationPitch = -this.updateRotation(this.rotationPitch, var13, f);
	this.rotationYaw = this.updateRotation(this.rotationYaw, var12, f);
}
 
Example 15
public void faceLocation(int i, int j, int k, float f)
{
	double var4 = i + 0.5D - posX;
	double var8 = k + 0.5D - posZ;
	double var6 = j + 0.5D - posY;
	double var14 = (double) MathHelper.sqrt_double(var4 * var4 + var8 * var8);
	float var12 = (float) (Math.atan2(var8, var4) * 180.0D / Math.PI) - 90.0F;
	float var13 = (float) (-(Math.atan2(var6, var14) * 180.0D / Math.PI));
	this.rotationPitch = -this.updateRotation(this.rotationPitch, var13, f);
	this.rotationYaw = this.updateRotation(this.rotationYaw, var12, f);
}
 
Example 16
private double getDistance(double x1, double y1, double z1, double x2, double y2, double z2) {
    double d0 = x1 - x2;
    double d1 = y1 - y2;
    double d2 = z1 - z2;
    return MathHelper.sqrt_double(d0 * d0 + d1 * d1 + d2 * d2);
}
 
Example 17
Source Project: TickDynamic   File: Entity.java    License: MIT License 4 votes vote down vote up
/**
 * Returns if this entity is in water and will end up adding the waters velocity to the entity
 */
public boolean handleWaterMovement()
{
    if (this.worldObj.handleMaterialAcceleration(this.boundingBox.expand(0.0D, -0.4000000059604645D, 0.0D).contract(0.001D, 0.001D, 0.001D), Material.water, this))
    {
        if (!this.inWater && !this.firstUpdate)
        {
            float f = MathHelper.sqrt_double(this.motionX * this.motionX * 0.20000000298023224D + this.motionY * this.motionY + this.motionZ * this.motionZ * 0.20000000298023224D) * 0.2F;

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

            this.playSound(this.getSplashSound(), f, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F);
            float f1 = (float)MathHelper.floor_double(this.boundingBox.minY);
            int i;
            float f2;
            float f3;

            for (i = 0; (float)i < 1.0F + this.width * 20.0F; ++i)
            {
                f2 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width;
                f3 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width;
                this.worldObj.spawnParticle("bubble", this.posX + (double)f2, (double)(f1 + 1.0F), this.posZ + (double)f3, this.motionX, this.motionY - (double)(this.rand.nextFloat() * 0.2F), this.motionZ);
            }

            for (i = 0; (float)i < 1.0F + this.width * 20.0F; ++i)
            {
                f2 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width;
                f3 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width;
                this.worldObj.spawnParticle("splash", this.posX + (double)f2, (double)(f1 + 1.0F), this.posZ + (double)f3, this.motionX, this.motionY, this.motionZ);
            }
        }

        this.fallDistance = 0.0F;
        this.inWater = true;
        this.fire = 0;
    }
    else
    {
        this.inWater = false;
    }

    return this.inWater;
}
 
Example 18
@Override
public void moveEntityWithHeading(float f, float f1)
{
    if (handleWaterMovement())
    {
        double d = posY;
        moveFlying(f, f1, 0.02F);
        moveEntity(motionX, motionY, motionZ);
        motionX *= 0.80000001192092896D;
        motionY *= 0.80000001192092896D;
        motionZ *= 0.80000001192092896D;
    }
    else if (handleLavaMovement())
    {
        double d1 = posY;
        moveFlying(f, f1, 0.02F);
        moveEntity(motionX, motionY, motionZ);
        motionX *= 0.5D;
        motionY *= 0.5D;
        motionZ *= 0.5D;
    }
    else
    {
        float f2 = 0.91F;
        if (onGround)
        {
            f2 = 0.5460001F;
            int i = worldObj.getBlockId(MathHelper.floor_double(posX), MathHelper.floor_double(boundingBox.minY) - 1, MathHelper.floor_double(posZ));
            if (i > 0)
            {
                f2 = Block.blocksList[i].slipperiness * 0.91F;
            }
        }
        float f3 = 0.162771F / (f2 * f2 * f2);
        moveFlying(f, f1, onGround ? 0.1F * f3 : 0.02F);
        f2 = 0.91F;
        if (onGround)
        {
            f2 = 0.5460001F;
            int j = worldObj.getBlockId(MathHelper.floor_double(posX), MathHelper.floor_double(boundingBox.minY) - 1, MathHelper.floor_double(posZ));
            if (j > 0)
            {
                f2 = Block.blocksList[j].slipperiness * 0.91F;
            }
        }
        moveEntity(motionX, motionY, motionZ);
        motionX *= f2;
        motionY *= f2;
        motionZ *= f2;
        if (isCollidedHorizontally)
        {
            motionY = 0.20000000000000001D;
        }
        if (rand.nextInt(30) == 0)
        {
            motionY = -0.25D;
        }
    }
    double d2 = posX - prevPosX;
    double d3 = posZ - prevPosZ;
    float f4 = MathHelper.sqrt_double((d2 * d2) + (d3 * d3)) * 4F;
    if (f4 > 1.0F)
    {
        f4 = 1.0F;
    }
}
 
Example 19
@Override
protected void attackEntity(Entity entity, float f)
{
    if ((f > 2.0F) && (f < 6F) && (rand.nextInt(50) == 0))
    {
        if (onGround)
        {
            double d = entity.posX - posX;
            double d1 = entity.posZ - posZ;
            float f1 = MathHelper.sqrt_double((d * d) + (d1 * d1));
            motionX = ((d / f1) * 0.5D * 0.8D) + (motionX * 0.2D);
            motionZ = ((d1 / f1) * 0.5D * 0.8D) + (motionZ * 0.2D);
            motionY = 0.4D;
        }
    }
    else if (attackTime <= 0 && (f < 3.0D) && (entity.boundingBox.maxY > boundingBox.minY) && (entity.boundingBox.minY < boundingBox.maxY))
    {
        attackTime = 20;
        boolean flag = (entity instanceof EntityPlayer);
        if (!getIsPoisoning() && rand.nextInt(5) == 0)
        {
            setPoisoning(true);
            if (getType() <= 2)// regular scorpions
            {
                if (flag)
                {
                    MoCreatures.poisonPlayer((EntityPlayer) entity);
                }
                ((EntityLiving) entity).addPotionEffect(new PotionEffect(Potion.poison.id, 70, 0));
            }
            else if (getType() == 4)// blue scorpions
            {
                if (flag)
                {
                    MoCreatures.freezePlayer((EntityPlayer) entity);
                }
                ((EntityLiving) entity).addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 70, 0));

            }
            else if (getType() == 3)// red scorpions
            {
                if (flag && MoCreatures.isServer() && !worldObj.provider.isHellWorld)
                {
                    MoCreatures.burnPlayer((EntityPlayer) entity);
                    ((EntityLiving) entity).setFire(15);

                }

            }

        }
        else
        {
            entity.attackEntityFrom(DamageSource.causeMobDamage(this), 1);
            swingArm();
        }
    }
}
 
Example 20
@Override
protected void attackEntity(Entity entity, float f)
{
    if ((f > 2.0F) && (f < 6F) && (rand.nextInt(50) == 0))
    {
        if (onGround)
        {
            double d = entity.posX - posX;
            double d1 = entity.posZ - posZ;
            float f1 = MathHelper.sqrt_double((d * d) + (d1 * d1));
            motionX = ((d / f1) * 0.5D * 0.8D) + (motionX * 0.2D);
            motionZ = ((d1 / f1) * 0.5D * 0.8D) + (motionZ * 0.2D);
            motionY = 0.4D;
        }
    }
    else if (attackTime <= 0 && (f < 3.0D) && (entity.boundingBox.maxY > boundingBox.minY) && (entity.boundingBox.minY < boundingBox.maxY))
    {
        attackTime = 20;
        boolean flag = (entity instanceof EntityPlayer);
        if (!getIsPoisoning() && rand.nextInt(5) == 0)
        {
            setPoisoning(true);
            if (getType() <= 2)// regular scorpions
            {
                if (flag)
                {
                    MoCreatures.poisonPlayer((EntityPlayer) entity);
                }
                ((EntityLiving) entity).addPotionEffect(new PotionEffect(Potion.poison.id, 70, 0));
            }
            else if (getType() == 4)// blue scorpions
            {
                if (flag)
                {
                    MoCreatures.freezePlayer((EntityPlayer) entity);
                }
                ((EntityLiving) entity).addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 70, 0));

            }
            else if (getType() == 3)// red scorpions
            {
                if (flag && MoCreatures.isServer() && !worldObj.provider.isHellWorld)
                {
                    MoCreatures.burnPlayer((EntityPlayer) entity);
                    ((EntityLiving) entity).setFire(15);

                }

            }

        }
        else
        {
            entity.attackEntityFrom(DamageSource.causeMobDamage(this), 1);
            swingArm();
        }
    }
}