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

The following are Jave code examples for showing how to use clamp_float() 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: GuiOptionSlider.java   Source Code and License Vote up 6 votes
/**
 * Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
 * e).
 */
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
    if (super.mousePressed(mc, mouseX, mouseY))
    {
        this.sliderValue = (float)(mouseX - (this.xPosition + 4)) / (float)(this.width - 8);
        this.sliderValue = MathHelper.clamp_float(this.sliderValue, 0.0F, 1.0F);
        mc.gameSettings.setOptionFloatValue(this.options, this.options.denormalizeValue(this.sliderValue));
        this.displayString = mc.gameSettings.getKeyBinding(this.options);
        this.dragging = true;
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 2
Project: BaseClient   File: GuiContainerCreative.java   Source Code and License Vote up 6 votes
/**
 * Handles mouse input.
 */
public void handleMouseInput() throws IOException
{
    super.handleMouseInput();
    int i = Mouse.getEventDWheel();

    if (i != 0 && this.needsScrollBars())
    {
        int j = ((GuiContainerCreative.ContainerCreative)this.inventorySlots).itemList.size() / 9 - 5;

        if (i > 0)
        {
            i = 1;
        }

        if (i < 0)
        {
            i = -1;
        }

        this.currentScroll = (float)((double)this.currentScroll - (double)i / (double)j);
        this.currentScroll = MathHelper.clamp_float(this.currentScroll, 0.0F, 1.0F);
        ((GuiContainerCreative.ContainerCreative)this.inventorySlots).scrollTo(this.currentScroll);
    }
}
 
Example 3
Project: BaseClient   File: DifficultyInstance.java   Source Code and License Vote up 6 votes
private float calculateAdditionalDifficulty(EnumDifficulty difficulty, long worldTime, long chunkInhabitedTime, float moonPhaseFactor)
{
    if (difficulty == EnumDifficulty.PEACEFUL)
    {
        return 0.0F;
    }
    else
    {
        boolean flag = difficulty == EnumDifficulty.HARD;
        float f = 0.75F;
        float f1 = MathHelper.clamp_float(((float)worldTime + -72000.0F) / 1440000.0F, 0.0F, 1.0F) * 0.25F;
        f = f + f1;
        float f2 = 0.0F;
        f2 = f2 + MathHelper.clamp_float((float)chunkInhabitedTime / 3600000.0F, 0.0F, 1.0F) * (flag ? 1.0F : 0.75F);
        f2 = f2 + MathHelper.clamp_float(moonPhaseFactor * 0.25F, 0.0F, f1);

        if (difficulty == EnumDifficulty.EASY)
        {
            f2 *= 0.5F;
        }

        f = f + f2;
        return (float)difficulty.getDifficultyId() * f;
    }
}
 
Example 4
Project: BaseClient   File: EntityCloudFX.java   Source Code and License Vote up 5 votes
/**
 * Renders the particle
 */
public void renderParticle(WorldRenderer worldRendererIn, Entity entityIn, float partialTicks, float p_180434_4_, float p_180434_5_, float p_180434_6_, float p_180434_7_, float p_180434_8_)
{
    float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge * 32.0F;
    f = MathHelper.clamp_float(f, 0.0F, 1.0F);
    this.particleScale = this.field_70569_a * f;
    super.renderParticle(worldRendererIn, entityIn, partialTicks, p_180434_4_, p_180434_5_, p_180434_6_, p_180434_7_, p_180434_8_);
}
 
Example 5
Project: BaseClient   File: WorldProviderEnd.java   Source Code and License Vote up 5 votes
/**
 * Return Vec3D with biome specific fog color
 */
public Vec3 getFogColor(float p_76562_1_, float p_76562_2_)
{
    int i = 10518688;
    float f = MathHelper.cos(p_76562_1_ * (float)Math.PI * 2.0F) * 2.0F + 0.5F;
    f = MathHelper.clamp_float(f, 0.0F, 1.0F);
    float f1 = (float)(i >> 16 & 255) / 255.0F;
    float f2 = (float)(i >> 8 & 255) / 255.0F;
    float f3 = (float)(i & 255) / 255.0F;
    f1 = f1 * (f * 0.0F + 0.15F);
    f2 = f2 * (f * 0.0F + 0.15F);
    f3 = f3 * (f * 0.0F + 0.15F);
    return new Vec3((double)f1, (double)f2, (double)f3);
}
 
Example 6
Project: BaseClient   File: RealmsSliderButton.java   Source Code and License Vote up 5 votes
public void clicked(int p_clicked_1_, int p_clicked_2_)
{
    this.value = (float)(p_clicked_1_ - (this.getProxy().xPosition + 4)) / (float)(this.getProxy().getButtonWidth() - 8);
    this.value = MathHelper.clamp_float(this.value, 0.0F, 1.0F);
    this.clicked(this.toValue(this.value));
    this.getProxy().displayString = this.getMessage();
    this.sliding = true;
}
 
Example 7
Project: BaseClient   File: RenderCreeper.java   Source Code and License Vote up 5 votes
/**
 * Allows the render to do any OpenGL state modifications necessary before the model is rendered. Args:
 * entityLiving, partialTickTime
 */
protected void preRenderCallback(EntityCreeper entitylivingbaseIn, float partialTickTime)
{
    float f = entitylivingbaseIn.getCreeperFlashIntensity(partialTickTime);
    float f1 = 1.0F + MathHelper.sin(f * 100.0F) * f * 0.01F;
    f = MathHelper.clamp_float(f, 0.0F, 1.0F);
    f = f * f;
    f = f * f;
    float f2 = (1.0F + f * 0.4F) * f1;
    float f3 = (1.0F + f * 0.1F) / f1;
    GlStateManager.scale(f2, f3, f2);
}
 
Example 8
Project: BaseClient   File: ItemTransformVec3f.java   Source Code and License Vote up 5 votes
public ItemTransformVec3f deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
    Vector3f vector3f = this.parseVector3f(jsonobject, "rotation", ROTATION_DEFAULT);
    Vector3f vector3f1 = this.parseVector3f(jsonobject, "translation", TRANSLATION_DEFAULT);
    vector3f1.scale(0.0625F);
    vector3f1.x = MathHelper.clamp_float(vector3f1.x, -1.5F, 1.5F);
    vector3f1.y = MathHelper.clamp_float(vector3f1.y, -1.5F, 1.5F);
    vector3f1.z = MathHelper.clamp_float(vector3f1.z, -1.5F, 1.5F);
    Vector3f vector3f2 = this.parseVector3f(jsonobject, "scale", SCALE_DEFAULT);
    vector3f2.x = MathHelper.clamp_float(vector3f2.x, -4.0F, 4.0F);
    vector3f2.y = MathHelper.clamp_float(vector3f2.y, -4.0F, 4.0F);
    vector3f2.z = MathHelper.clamp_float(vector3f2.z, -4.0F, 4.0F);
    return new ItemTransformVec3f(vector3f, vector3f1, vector3f2);
}
 
Example 9
Project: BaseClient   File: EntityNoteFX.java   Source Code and License Vote up 5 votes
/**
 * Renders the particle
 */
public void renderParticle(WorldRenderer worldRendererIn, Entity entityIn, float partialTicks, float p_180434_4_, float p_180434_5_, float p_180434_6_, float p_180434_7_, float p_180434_8_)
{
    float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge * 32.0F;
    f = MathHelper.clamp_float(f, 0.0F, 1.0F);
    this.particleScale = this.noteParticleScale * f;
    super.renderParticle(worldRendererIn, entityIn, partialTicks, p_180434_4_, p_180434_5_, p_180434_6_, p_180434_7_, p_180434_8_);
}
 
Example 10
Project: BaseClient   File: RenderTntMinecart.java   Source Code and License Vote up 5 votes
protected void func_180560_a(EntityMinecartTNT minecart, float partialTicks, IBlockState state)
{
    int i = minecart.getFuseTicks();

    if (i > -1 && (float)i - partialTicks + 1.0F < 10.0F)
    {
        float f = 1.0F - ((float)i - partialTicks + 1.0F) / 10.0F;
        f = MathHelper.clamp_float(f, 0.0F, 1.0F);
        f = f * f;
        f = f * f;
        float f1 = 1.0F + f * 0.3F;
        GlStateManager.scale(f1, f1, f1);
    }

    super.func_180560_a(minecart, partialTicks, state);

    if (i > -1 && i / 5 % 2 == 0)
    {
        BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
        GlStateManager.disableTexture2D();
        GlStateManager.disableLighting();
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(770, 772);
        GlStateManager.color(1.0F, 1.0F, 1.0F, (1.0F - ((float)i - partialTicks + 1.0F) / 100.0F) * 0.8F);
        GlStateManager.pushMatrix();
        blockrendererdispatcher.renderBlockBrightness(Blocks.tnt.getDefaultState(), 1.0F);
        GlStateManager.popMatrix();
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.disableBlend();
        GlStateManager.enableLighting();
        GlStateManager.enableTexture2D();
    }
}
 
Example 11
Project: BaseClient   File: BiomeGenBase.java   Source Code and License Vote up 5 votes
/**
 * takes temperature, returns color
 */
public int getSkyColorByTemp(float p_76731_1_)
{
    p_76731_1_ = p_76731_1_ / 3.0F;
    p_76731_1_ = MathHelper.clamp_float(p_76731_1_, -1.0F, 1.0F);
    return MathHelper.func_181758_c(0.62222224F - p_76731_1_ * 0.05F, 0.5F + p_76731_1_ * 0.1F, 1.0F);
}
 
Example 12
Project: BaseClient   File: EntityLavaFX.java   Source Code and License Vote up 5 votes
public int getBrightnessForRender(float partialTicks)
{
    float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge;
    f = MathHelper.clamp_float(f, 0.0F, 1.0F);
    int i = super.getBrightnessForRender(partialTicks);
    int j = 240;
    int k = i >> 16 & 255;
    return j | k << 16;
}
 
Example 13
Project: BaseClient   File: GuiSpectator.java   Source Code and License Vote up 4 votes
private float func_175265_c()
{
    long i = this.field_175270_h - Minecraft.getSystemTime() + 5000L;
    return MathHelper.clamp_float((float)i / 2000.0F, 0.0F, 1.0F);
}
 
Example 14
Project: BaseClient   File: BiomeGenBase.java   Source Code and License Vote up 4 votes
public int getGrassColorAtPos(BlockPos pos)
{
    double d0 = (double)MathHelper.clamp_float(this.getFloatTemperature(pos), 0.0F, 1.0F);
    double d1 = (double)MathHelper.clamp_float(this.getFloatRainfall(), 0.0F, 1.0F);
    return ColorizerGrass.getGrassColor(d0, d1);
}