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

The following are Jave code examples for showing how to use clamp_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: EntityMinecart.java   Source Code and License Vote up 6 votes
/**
 * Moves a minecart that is not attached to a rail
 */
protected void moveDerailedMinecart()
{
    double d0 = this.getMaximumSpeed();
    this.motionX = MathHelper.clamp_double(this.motionX, -d0, d0);
    this.motionZ = MathHelper.clamp_double(this.motionZ, -d0, d0);

    if (this.onGround)
    {
        this.motionX *= 0.5D;
        this.motionY *= 0.5D;
        this.motionZ *= 0.5D;
    }

    this.moveEntity(this.motionX, this.motionY, this.motionZ);

    if (!this.onGround)
    {
        this.motionX *= 0.949999988079071D;
        this.motionY *= 0.949999988079071D;
        this.motionZ *= 0.949999988079071D;
    }
}
 
Example 2
Project: BaseClient   File: RealmsMth.java   Source Code and License Vote up 4 votes
public static double clamp(double p_clamp_0_, double p_clamp_2_, double p_clamp_4_)
{
    return MathHelper.clamp_double(p_clamp_0_, p_clamp_2_, p_clamp_4_);
}
 
Example 3
Project: BaseClient   File: SoundManager.java   Source Code and License Vote up 4 votes
/**
 * Normalizes volume level from parameters.  Range [0.0, 1.0]
 */
private float getNormalizedVolume(ISound sound, SoundPoolEntry entry, SoundCategory category)
{
    return (float)MathHelper.clamp_double((double)sound.getVolume() * entry.getVolume(), 0.0D, 1.0D) * this.getSoundCategoryVolume(category);
}
 
Example 4
Project: BaseClient   File: ServerConfigurationManager.java   Source Code and License Vote up 4 votes
/**
 * Transfers an entity from a world to another world.
 */
public void transferEntityToWorld(Entity entityIn, int p_82448_2_, WorldServer p_82448_3_, WorldServer p_82448_4_)
{
    double d0 = entityIn.posX;
    double d1 = entityIn.posZ;
    double d2 = 8.0D;
    float f = entityIn.rotationYaw;
    p_82448_3_.theProfiler.startSection("moving");

    if (entityIn.dimension == -1)
    {
        d0 = MathHelper.clamp_double(d0 / d2, p_82448_4_.getWorldBorder().minX() + 16.0D, p_82448_4_.getWorldBorder().maxX() - 16.0D);
        d1 = MathHelper.clamp_double(d1 / d2, p_82448_4_.getWorldBorder().minZ() + 16.0D, p_82448_4_.getWorldBorder().maxZ() - 16.0D);
        entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);

        if (entityIn.isEntityAlive())
        {
            p_82448_3_.updateEntityWithOptionalForce(entityIn, false);
        }
    }
    else if (entityIn.dimension == 0)
    {
        d0 = MathHelper.clamp_double(d0 * d2, p_82448_4_.getWorldBorder().minX() + 16.0D, p_82448_4_.getWorldBorder().maxX() - 16.0D);
        d1 = MathHelper.clamp_double(d1 * d2, p_82448_4_.getWorldBorder().minZ() + 16.0D, p_82448_4_.getWorldBorder().maxZ() - 16.0D);
        entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);

        if (entityIn.isEntityAlive())
        {
            p_82448_3_.updateEntityWithOptionalForce(entityIn, false);
        }
    }
    else
    {
        BlockPos blockpos;

        if (p_82448_2_ == 1)
        {
            blockpos = p_82448_4_.getSpawnPoint();
        }
        else
        {
            blockpos = p_82448_4_.getSpawnCoordinate();
        }

        d0 = (double)blockpos.getX();
        entityIn.posY = (double)blockpos.getY();
        d1 = (double)blockpos.getZ();
        entityIn.setLocationAndAngles(d0, entityIn.posY, d1, 90.0F, 0.0F);

        if (entityIn.isEntityAlive())
        {
            p_82448_3_.updateEntityWithOptionalForce(entityIn, false);
        }
    }

    p_82448_3_.theProfiler.endSection();

    if (p_82448_2_ != 1)
    {
        p_82448_3_.theProfiler.startSection("placing");
        d0 = (double)MathHelper.clamp_int((int)d0, -29999872, 29999872);
        d1 = (double)MathHelper.clamp_int((int)d1, -29999872, 29999872);

        if (entityIn.isEntityAlive())
        {
            entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);
            p_82448_4_.getDefaultTeleporter().placeInPortal(entityIn, f);
            p_82448_4_.spawnEntityInWorld(entityIn);
            p_82448_4_.updateEntityWithOptionalForce(entityIn, false);
        }

        p_82448_3_.theProfiler.endSection();
    }

    entityIn.setWorld(p_82448_4_);
}
 
Example 5
Project: BaseClient   File: TextureClock.java   Source Code and License Vote up 4 votes
public void updateAnimation()
{
    if (!this.framesTextureData.isEmpty())
    {
        Minecraft minecraft = Minecraft.getMinecraft();
        double d0 = 0.0D;

        if (minecraft.theWorld != null && minecraft.thePlayer != null)
        {
            d0 = (double)minecraft.theWorld.getCelestialAngle(1.0F);

            if (!minecraft.theWorld.provider.isSurfaceWorld())
            {
                d0 = Math.random();
            }
        }

        double d1;

        for (d1 = d0 - this.field_94239_h; d1 < -0.5D; ++d1)
        {
            ;
        }

        while (d1 >= 0.5D)
        {
            --d1;
        }

        d1 = MathHelper.clamp_double(d1, -1.0D, 1.0D);
        this.field_94240_i += d1 * 0.1D;
        this.field_94240_i *= 0.8D;
        this.field_94239_h += this.field_94240_i;
        int i;

        for (i = (int)((this.field_94239_h + 1.0D) * (double)this.framesTextureData.size()) % this.framesTextureData.size(); i < 0; i = (i + this.framesTextureData.size()) % this.framesTextureData.size())
        {
            ;
        }

        if (i != this.frameCounter)
        {
            this.frameCounter = i;
            TextureUtil.uploadTextureMipmap((int[][])this.framesTextureData.get(this.frameCounter), this.width, this.height, this.originX, this.originY, false, false);
        }
    }
}
 
Example 6
Project: BaseClient   File: SoundManager.java   Source Code and License Vote up 4 votes
/**
 * Normalizes volume level from parameters.  Range [0.0, 1.0]
 */
private float getNormalizedVolume(ISound sound, SoundPoolEntry entry, SoundCategory category)
{
    return (float)MathHelper.clamp_double((double)sound.getVolume() * entry.getVolume(), 0.0D, 1.0D) * this.getSoundCategoryVolume(category);
}
 
Example 7
Project: BaseClient   File: RangedAttribute.java   Source Code and License Vote up 4 votes
public double clampValue(double p_111109_1_)
{
    p_111109_1_ = MathHelper.clamp_double(p_111109_1_, this.minimumValue, this.maximumValue);
    return p_111109_1_;
}
 
Example 8
Project: BaseClient   File: RangedAttribute.java   Source Code and License Vote up 4 votes
public double clampValue(double p_111109_1_)
{
    p_111109_1_ = MathHelper.clamp_double(p_111109_1_, this.minimumValue, this.maximumValue);
    return p_111109_1_;
}
 
Example 9
Project: BaseClient   File: ServerConfigurationManager.java   Source Code and License Vote up 4 votes
/**
 * Transfers an entity from a world to another world.
 */
public void transferEntityToWorld(Entity entityIn, int p_82448_2_, WorldServer p_82448_3_, WorldServer p_82448_4_)
{
    double d0 = entityIn.posX;
    double d1 = entityIn.posZ;
    double d2 = 8.0D;
    float f = entityIn.rotationYaw;
    p_82448_3_.theProfiler.startSection("moving");

    if (entityIn.dimension == -1)
    {
        d0 = MathHelper.clamp_double(d0 / d2, p_82448_4_.getWorldBorder().minX() + 16.0D, p_82448_4_.getWorldBorder().maxX() - 16.0D);
        d1 = MathHelper.clamp_double(d1 / d2, p_82448_4_.getWorldBorder().minZ() + 16.0D, p_82448_4_.getWorldBorder().maxZ() - 16.0D);
        entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);

        if (entityIn.isEntityAlive())
        {
            p_82448_3_.updateEntityWithOptionalForce(entityIn, false);
        }
    }
    else if (entityIn.dimension == 0)
    {
        d0 = MathHelper.clamp_double(d0 * d2, p_82448_4_.getWorldBorder().minX() + 16.0D, p_82448_4_.getWorldBorder().maxX() - 16.0D);
        d1 = MathHelper.clamp_double(d1 * d2, p_82448_4_.getWorldBorder().minZ() + 16.0D, p_82448_4_.getWorldBorder().maxZ() - 16.0D);
        entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);

        if (entityIn.isEntityAlive())
        {
            p_82448_3_.updateEntityWithOptionalForce(entityIn, false);
        }
    }
    else
    {
        BlockPos blockpos;

        if (p_82448_2_ == 1)
        {
            blockpos = p_82448_4_.getSpawnPoint();
        }
        else
        {
            blockpos = p_82448_4_.getSpawnCoordinate();
        }

        d0 = (double)blockpos.getX();
        entityIn.posY = (double)blockpos.getY();
        d1 = (double)blockpos.getZ();
        entityIn.setLocationAndAngles(d0, entityIn.posY, d1, 90.0F, 0.0F);

        if (entityIn.isEntityAlive())
        {
            p_82448_3_.updateEntityWithOptionalForce(entityIn, false);
        }
    }

    p_82448_3_.theProfiler.endSection();

    if (p_82448_2_ != 1)
    {
        p_82448_3_.theProfiler.startSection("placing");
        d0 = (double)MathHelper.clamp_int((int)d0, -29999872, 29999872);
        d1 = (double)MathHelper.clamp_int((int)d1, -29999872, 29999872);

        if (entityIn.isEntityAlive())
        {
            entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);
            p_82448_4_.getDefaultTeleporter().placeInPortal(entityIn, f);
            p_82448_4_.spawnEntityInWorld(entityIn);
            p_82448_4_.updateEntityWithOptionalForce(entityIn, false);
        }

        p_82448_3_.theProfiler.endSection();
    }

    entityIn.setWorld(p_82448_4_);
}
 
Example 10
Project: BaseClient   File: RealmsMth.java   Source Code and License Vote up 4 votes
public static double clamp(double p_clamp_0_, double p_clamp_2_, double p_clamp_4_)
{
    return MathHelper.clamp_double(p_clamp_0_, p_clamp_2_, p_clamp_4_);
}
 
Example 11
Project: BaseClient   File: TextureCompass.java   Source Code and License Vote up 4 votes
/**
 * Updates the compass based on the given x,z coords and camera direction
 */
public void updateCompass(World worldIn, double p_94241_2_, double p_94241_4_, double p_94241_6_, boolean p_94241_8_, boolean p_94241_9_)
{
    if (!this.framesTextureData.isEmpty())
    {
        double d0 = 0.0D;

        if (worldIn != null && !p_94241_8_)
        {
            BlockPos blockpos = worldIn.getSpawnPoint();
            double d1 = (double)blockpos.getX() - p_94241_2_;
            double d2 = (double)blockpos.getZ() - p_94241_4_;
            p_94241_6_ = p_94241_6_ % 360.0D;
            d0 = -((p_94241_6_ - 90.0D) * Math.PI / 180.0D - Math.atan2(d2, d1));

            if (!worldIn.provider.isSurfaceWorld())
            {
                d0 = Math.random() * Math.PI * 2.0D;
            }
        }

        if (p_94241_9_)
        {
            this.currentAngle = d0;
        }
        else
        {
            double d3;

            for (d3 = d0 - this.currentAngle; d3 < -Math.PI; d3 += (Math.PI * 2D))
            {
                ;
            }

            while (d3 >= Math.PI)
            {
                d3 -= (Math.PI * 2D);
            }

            d3 = MathHelper.clamp_double(d3, -1.0D, 1.0D);
            this.angleDelta += d3 * 0.1D;
            this.angleDelta *= 0.8D;
            this.currentAngle += this.angleDelta;
        }

        int i;

        for (i = (int)((this.currentAngle / (Math.PI * 2D) + 1.0D) * (double)this.framesTextureData.size()) % this.framesTextureData.size(); i < 0; i = (i + this.framesTextureData.size()) % this.framesTextureData.size())
        {
            ;
        }

        if (i != this.frameCounter)
        {
            this.frameCounter = i;

            if (Config.isShaders())
            {
                ShadersTex.uploadTexSub((int[][])((int[][])this.framesTextureData.get(this.frameCounter)), this.width, this.height, this.originX, this.originY, false, false);
            }
            else
            {
                TextureUtil.uploadTextureMipmap((int[][])((int[][])this.framesTextureData.get(this.frameCounter)), this.width, this.height, this.originX, this.originY, false, false);
            }
        }
    }
}
 
Example 12
Project: BaseClient   File: TextureClock.java   Source Code and License Vote up 4 votes
public void updateAnimation()
{
    if (!this.framesTextureData.isEmpty())
    {
        Minecraft minecraft = Minecraft.getMinecraft();
        double d0 = 0.0D;

        if (minecraft.theWorld != null && minecraft.thePlayer != null)
        {
            d0 = (double)minecraft.theWorld.getCelestialAngle(1.0F);

            if (!minecraft.theWorld.provider.isSurfaceWorld())
            {
                d0 = Math.random();
            }
        }

        double d1;

        for (d1 = d0 - this.field_94239_h; d1 < -0.5D; ++d1)
        {
            ;
        }

        while (d1 >= 0.5D)
        {
            --d1;
        }

        d1 = MathHelper.clamp_double(d1, -1.0D, 1.0D);
        this.field_94240_i += d1 * 0.1D;
        this.field_94240_i *= 0.8D;
        this.field_94239_h += this.field_94240_i;
        int i;

        for (i = (int)((this.field_94239_h + 1.0D) * (double)this.framesTextureData.size()) % this.framesTextureData.size(); i < 0; i = (i + this.framesTextureData.size()) % this.framesTextureData.size())
        {
            ;
        }

        if (i != this.frameCounter)
        {
            this.frameCounter = i;

            if (Config.isShaders())
            {
                ShadersTex.uploadTexSub((int[][])((int[][])this.framesTextureData.get(this.frameCounter)), this.width, this.height, this.originX, this.originY, false, false);
            }
            else
            {
                TextureUtil.uploadTextureMipmap((int[][])((int[][])this.framesTextureData.get(this.frameCounter)), this.width, this.height, this.originX, this.originY, false, false);
            }
        }
    }
}
 
Example 13
Project: BaseClient   File: SoundManager.java   Source Code and License Vote up 4 votes
/**
 * Normalizes pitch from parameters and clamps to [0.5, 2.0]
 */
private float getNormalizedPitch(ISound sound, SoundPoolEntry entry)
{
    return (float)MathHelper.clamp_double((double)sound.getPitch() * entry.getPitch(), 0.5D, 2.0D);
}