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

The following are Jave code examples for showing how to use abs() 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: BlockPistonBase.java   Source Code and License Vote up 6 votes
public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn)
{
    if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F)
    {
        double d0 = entityIn.posY + (double)entityIn.getEyeHeight();

        if (d0 - (double)clickedBlock.getY() > 2.0D)
        {
            return EnumFacing.UP;
        }

        if ((double)clickedBlock.getY() - d0 > 0.0D)
        {
            return EnumFacing.DOWN;
        }
    }

    return entityIn.getHorizontalFacing().getOpposite();
}
 
Example 2
Project: BaseClient   File: ItemRenderer.java   Source Code and License Vote up 6 votes
private void func_178104_a(AbstractClientPlayer clientPlayer, float p_178104_2_)
{
    float f = (float)clientPlayer.getItemInUseCount() - p_178104_2_ + 1.0F;
    float f1 = f / (float)this.itemToRender.getMaxItemUseDuration();
    float f2 = MathHelper.abs(MathHelper.cos(f / 4.0F * (float)Math.PI) * 0.1F);

    if (f1 >= 0.8F)
    {
        f2 = 0.0F;
    }

    GlStateManager.translate(0.0F, f2, 0.0F);
    float f3 = 1.0F - (float)Math.pow((double)f1, 27.0D);
    GlStateManager.translate(f3 * 0.6F, f3 * -0.5F, f3 * 0.0F);
    GlStateManager.rotate(f3 * 90.0F, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(f3 * 10.0F, 1.0F, 0.0F, 0.0F);
    GlStateManager.rotate(f3 * 30.0F, 0.0F, 0.0F, 1.0F);
}
 
Example 3
Project: BaseClient   File: BlockPistonBase.java   Source Code and License Vote up 6 votes
public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn)
{
    if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F)
    {
        double d0 = entityIn.posY + (double)entityIn.getEyeHeight();

        if (d0 - (double)clickedBlock.getY() > 2.0D)
        {
            return EnumFacing.UP;
        }

        if ((double)clickedBlock.getY() - d0 > 0.0D)
        {
            return EnumFacing.DOWN;
        }
    }

    return entityIn.getHorizontalFacing().getOpposite();
}
 
Example 4
Project: BaseClient   File: ItemRenderer.java   Source Code and License Vote up 6 votes
private void func_178104_a(AbstractClientPlayer clientPlayer, float p_178104_2_)
{
    float f = (float)clientPlayer.getItemInUseCount() - p_178104_2_ + 1.0F;
    float f1 = f / (float)this.itemToRender.getMaxItemUseDuration();
    float f2 = MathHelper.abs(MathHelper.cos(f / 4.0F * (float)Math.PI) * 0.1F);

    if (f1 >= 0.8F)
    {
        f2 = 0.0F;
    }

    GlStateManager.translate(0.0F, f2, 0.0F);
    float f3 = 1.0F - (float)Math.pow((double)f1, 27.0D);
    GlStateManager.translate(f3 * 0.6F, f3 * -0.5F, f3 * 0.0F);
    GlStateManager.rotate(f3 * 90.0F, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(f3 * 10.0F, 1.0F, 0.0F, 0.0F);
    GlStateManager.rotate(f3 * 30.0F, 0.0F, 0.0F, 1.0F);
}
 
Example 5
Project: BaseClient   File: BlockPart.java   Source Code and License Vote up 5 votes
private float parseAngle(JsonObject p_178255_1_)
{
    float f = JsonUtils.getFloat(p_178255_1_, "angle");

    if (f != 0.0F && MathHelper.abs(f) != 22.5F && MathHelper.abs(f) != 45.0F)
    {
        throw new JsonParseException("Invalid rotation " + f + " found, only -45/-22.5/0/22.5/45 allowed");
    }
    else
    {
        return f;
    }
}
 
Example 6
Project: BaseClient   File: BlockPart.java   Source Code and License Vote up 5 votes
private float parseAngle(JsonObject p_178255_1_)
{
    float f = JsonUtils.getFloat(p_178255_1_, "angle");

    if (f != 0.0F && MathHelper.abs(f) != 22.5F && MathHelper.abs(f) != 45.0F)
    {
        throw new JsonParseException("Invalid rotation " + f + " found, only -45/-22.5/0/22.5/45 allowed");
    }
    else
    {
        return f;
    }
}
 
Example 7
Project: BaseClient   File: NaturalProperties.java   Source Code and License Vote up 4 votes
private boolean equalsDelta(float p_equalsDelta_1_, float p_equalsDelta_2_, float p_equalsDelta_3_)
{
    float f = MathHelper.abs(p_equalsDelta_1_ - p_equalsDelta_2_);
    return f < p_equalsDelta_3_;
}
 
Example 8
Project: BaseClient   File: RealmsMth.java   Source Code and License Vote up 4 votes
public static float abs(float p_abs_0_)
{
    return MathHelper.abs(p_abs_0_);
}
 
Example 9
Project: BaseClient   File: GuiMainMenu.java   Source Code and License Vote up 4 votes
/**
 * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
 */
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
    GlStateManager.disableAlpha();
    this.renderSkybox(mouseX, mouseY, partialTicks);
    GlStateManager.enableAlpha();
    Tessellator tessellator = Tessellator.getInstance();
    WorldRenderer worldrenderer = tessellator.getWorldRenderer();
    int i = 274;
    int j = this.width / 2 - i / 2;
    int k = 30;
    this.drawGradientRect(0, 0, this.width, this.height, -2130706433, 16777215);
    this.drawGradientRect(0, 0, this.width, this.height, 0, Integer.MIN_VALUE);
    this.mc.getTextureManager().bindTexture(minecraftTitleTextures);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

    if ((double)this.updateCounter < 1.0E-4D)
    {
        this.drawTexturedModalRect(j + 0, k + 0, 0, 0, 99, 44);
        this.drawTexturedModalRect(j + 99, k + 0, 129, 0, 27, 44);
        this.drawTexturedModalRect(j + 99 + 26, k + 0, 126, 0, 3, 44);
        this.drawTexturedModalRect(j + 99 + 26 + 3, k + 0, 99, 0, 26, 44);
        this.drawTexturedModalRect(j + 155, k + 0, 0, 45, 155, 44);
    }
    else
    {
        this.drawTexturedModalRect(j + 0, k + 0, 0, 0, 155, 44);
        this.drawTexturedModalRect(j + 155, k + 0, 0, 45, 155, 44);
    }

    GlStateManager.pushMatrix();
    GlStateManager.translate((float)(this.width / 2 + 90), 70.0F, 0.0F);
    GlStateManager.rotate(-20.0F, 0.0F, 0.0F, 1.0F);
    float f = 1.8F - MathHelper.abs(MathHelper.sin((float)(Minecraft.getSystemTime() % 1000L) / 1000.0F * (float)Math.PI * 2.0F) * 0.1F);
    f = f * 100.0F / (float)(this.fontRendererObj.getStringWidth(this.splashText) + 32);
    GlStateManager.scale(f, f, f);
    this.drawCenteredString(this.fontRendererObj, this.splashText, 0, -8, -256);
    GlStateManager.popMatrix();
    String s = "Minecraft 1.8.8";

    if (this.mc.isDemo())
    {
        s = s + " Demo";
    }

    this.drawString(this.fontRendererObj, s, 2, this.height - 10, -1);
    String s1 = "Copyright Mojang AB. Do not distribute!";
    this.drawString(this.fontRendererObj, s1, this.width - this.fontRendererObj.getStringWidth(s1) - 2, this.height - 10, -1);

    if (this.openGLWarning1 != null && this.openGLWarning1.length() > 0)
    {
        drawRect(this.field_92022_t - 2, this.field_92021_u - 2, this.field_92020_v + 2, this.field_92019_w - 1, 1428160512);
        this.drawString(this.fontRendererObj, this.openGLWarning1, this.field_92022_t, this.field_92021_u, -1);
        this.drawString(this.fontRendererObj, this.openGLWarning2, (this.width - this.field_92024_r) / 2, ((GuiButton)this.buttonList.get(0)).yPosition - 12, -1);
    }

    super.drawScreen(mouseX, mouseY, partialTicks);
}
 
Example 10
Project: BaseClient   File: RealmsMth.java   Source Code and License Vote up 4 votes
public static float abs(float p_abs_0_)
{
    return MathHelper.abs(p_abs_0_);
}
 
Example 11
Project: BaseClient   File: GuiMainMenu.java   Source Code and License Vote up 4 votes
/**
 * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
 */
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
    GlStateManager.disableAlpha();
    this.renderSkybox(mouseX, mouseY, partialTicks);
    GlStateManager.enableAlpha();
    Tessellator tessellator = Tessellator.getInstance();
    WorldRenderer worldrenderer = tessellator.getWorldRenderer();
    int i = 274;
    int j = this.width / 2 - i / 2;
    int k = 30;
    this.drawGradientRect(0, 0, this.width, this.height, -2130706433, 16777215);
    this.drawGradientRect(0, 0, this.width, this.height, 0, Integer.MIN_VALUE);
    this.mc.getTextureManager().bindTexture(minecraftTitleTextures);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

    if ((double)this.updateCounter < 1.0E-4D)
    {
        this.drawTexturedModalRect(j + 0, k + 0, 0, 0, 99, 44);
        this.drawTexturedModalRect(j + 99, k + 0, 129, 0, 27, 44);
        this.drawTexturedModalRect(j + 99 + 26, k + 0, 126, 0, 3, 44);
        this.drawTexturedModalRect(j + 99 + 26 + 3, k + 0, 99, 0, 26, 44);
        this.drawTexturedModalRect(j + 155, k + 0, 0, 45, 155, 44);
    }
    else
    {
        this.drawTexturedModalRect(j + 0, k + 0, 0, 0, 155, 44);
        this.drawTexturedModalRect(j + 155, k + 0, 0, 45, 155, 44);
    }

    GlStateManager.pushMatrix();
    GlStateManager.translate((float)(this.width / 2 + 90), 70.0F, 0.0F);
    GlStateManager.rotate(-20.0F, 0.0F, 0.0F, 1.0F);
    float f = 1.8F - MathHelper.abs(MathHelper.sin((float)(Minecraft.getSystemTime() % 1000L) / 1000.0F * (float)Math.PI * 2.0F) * 0.1F);
    f = f * 100.0F / (float)(this.fontRendererObj.getStringWidth(this.splashText) + 32);
    GlStateManager.scale(f, f, f);
    this.drawCenteredString(this.fontRendererObj, this.splashText, 0, -8, -256);
    GlStateManager.popMatrix();
    String s = "Minecraft 1.8.8";

    if (this.mc.isDemo())
    {
        s = s + " Demo";
    }

    this.drawString(this.fontRendererObj, s, 2, this.height - 10, -1);
    String s1 = "Copyright Mojang AB. Do not distribute!";
    this.drawString(this.fontRendererObj, s1, this.width - this.fontRendererObj.getStringWidth(s1) - 2, this.height - 10, -1);

    if (this.openGLWarning1 != null && this.openGLWarning1.length() > 0)
    {
        drawRect(this.field_92022_t - 2, this.field_92021_u - 2, this.field_92020_v + 2, this.field_92019_w - 1, 1428160512);
        this.drawString(this.fontRendererObj, this.openGLWarning1, this.field_92022_t, this.field_92021_u, -1);
        this.drawString(this.fontRendererObj, this.openGLWarning2, (this.width - this.field_92024_r) / 2, ((GuiButton)this.buttonList.get(0)).yPosition - 12, -1);
    }

    super.drawScreen(mouseX, mouseY, partialTicks);
}