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

The following examples show how to use net.minecraft.util.MathHelper#clamp_int() . 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
Source File: WidgetTemperature.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void render(int mouseX, int mouseY, float partialTick){
    GL11.glDisable(GL11.GL_LIGHTING);
    Minecraft.getMinecraft().getTextureManager().bindTexture(Textures.WIDGET_TEMPERATURE);
    GL11.glColor4d(1, 1, 1, 1);
    Gui.func_146110_a(x + 6, y, 6, 0, 7, 50, 18, 50);

    int barLength = ((int)logic.getTemperature() - minTemp) * 48 / maxTemp;
    barLength = MathHelper.clamp_int(barLength, 0, 48);
    Gui.func_146110_a(x + 7, y + 1 + 48 - barLength, 13, 48 - barLength, 5, barLength, 18, 50);

    for(int scale : scales) {
        int scaleY = 48 - (scale - minTemp) * 48 / maxTemp;
        Gui.func_146110_a(x, y - 1 + scaleY, 0, 0, 6, 5, 18, 50);
    }
}
 
Example 2
Source File: GuiAnimatedStat.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public boolean handleMouseWheel(int mouseWheel){
    for(IGuiWidget widget : widgets) {
        widget.handleMouseInput();
        if(widget.getID() == -1000) {
            int wheel = -mouseWheel;
            wheel = MathHelper.clamp_int(wheel, -1, 1);
            ((WidgetVerticalScrollbar)widget).currentScroll += (float)wheel / (textList.size() - MAX_LINES);
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: GuiSaveSlotButton.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
private void updatePosition() {
    this.width = Wrapper.INSTANCE.fontRenderer().getStringWidth(this.text) + 24;
    if (this.width % 2 == 1) {
        ++this.width;
    }
    this.width = MathHelper.clamp_int(this.width, 82, 150);
    this.x = this.rightX - this.width;
}
 
Example 4
Source File: WidgetVerticalScrollbar.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleMouseInput(){
    if(listening) {
        int wheel = -Mouse.getDWheel();
        wheel = MathHelper.clamp_int(wheel, -1, 1);
        currentScroll += (float)wheel / states;
    }
}
 
Example 5
Source File: GuiSaveSlotButton.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
private void updatePosition(){
	width = mc.fontRenderer.getStringWidth(text)+24;
	if (width % 2 == 1)
		++width;
	width = MathHelper.clamp_int(width, MIN_WIDTH, MAX_WIDTH);
	x = rightX - width;
}
 
Example 6
Source File: BlockLightChain.java    From GardenCollection with MIT License 4 votes vote down vote up
@Override
public IIcon getIcon (int side, int meta) {
    return icons[MathHelper.clamp_int(meta, 0, types.length - 1)];
}
 
Example 7
Source File: WidgetTextFieldNumber.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public int getValue(){
    return MathHelper.clamp_int(NumberUtils.toInt(getText()), minValue, maxValue);
}
 
Example 8
Source File: AmadronOfferPeriodicConfig.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void readFromJsonCustom(JsonObject object){
    timesPerDay = object.get("timesPerDay").getAsInt();
    offersPer = object.get("offersPer").getAsInt();
    timesPerDay = MathHelper.clamp_int(timesPerDay, 1, 24000);
}
 
Example 9
Source File: ItemDeadlyShard.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
@Override
public String getUnlocalizedName(ItemStack stack) {
    int i = MathHelper.clamp_int(stack.getItemDamage(), 0, 6);
    return super.getUnlocalizedName() + "." + vices[i];
}
 
Example 10
Source File: BlockHeavyChain.java    From GardenCollection with MIT License 4 votes vote down vote up
@Override
public IIcon getIcon (int side, int meta) {
    return icons[MathHelper.clamp_int(meta, 0, types.length - 1)];
}
 
Example 11
Source File: ItemProgrammingPuzzle.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getUnlocalizedName(ItemStack stack){
    return super.getUnlocalizedName(stack) + "." + ItemDye.field_150923_a[MathHelper.clamp_int(stack.getItemDamage(), 0, 15)];
}
 
Example 12
Source File: MixinGuiSlot.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @author CCBlueX
 */
@Overwrite
public void drawScreen(int mouseXIn, int mouseYIn, float p_148128_3_) {
    if(this.field_178041_q) {
        this.mouseX = mouseXIn;
        this.mouseY = mouseYIn;
        this.drawBackground();
        int i = this.getScrollBarX();
        int j = i + 6;
        this.bindAmountScrolled();
        GlStateManager.disableLighting();
        GlStateManager.disableFog();
        Tessellator tessellator = Tessellator.getInstance();
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
        int k = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
        int l = this.top + 4 - (int) this.amountScrolled;
        if (this.hasListHeader) {
            this.drawListHeader(k, l, tessellator);
        }

        RenderUtils.makeScissorBox(left, top, right, bottom);

        GL11.glEnable(GL11.GL_SCISSOR_TEST);

        this.drawSelectionBox(k, l + 2, mouseXIn, mouseYIn + 2);

        GL11.glDisable(GL11.GL_SCISSOR_TEST);

        GlStateManager.disableDepth();
        int i1 = 4;

        // ClientCode
        ScaledResolution scaledResolution = new ScaledResolution(mc);
        Gui.drawRect(0, 0, scaledResolution.getScaledWidth(), this.top, Integer.MIN_VALUE);
        Gui.drawRect(0, this.bottom, scaledResolution.getScaledWidth(), this.height, Integer.MIN_VALUE);

        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(770, 771, 0, 1);
        GlStateManager.disableAlpha();
        GlStateManager.shadeModel(7425);
        GlStateManager.disableTexture2D();
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
        worldrenderer.pos(this.left, this.top + i1, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 0).endVertex();
        worldrenderer.pos(this.right, this.top + i1, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 0).endVertex();
        worldrenderer.pos(this.right, this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
        worldrenderer.pos(this.left, this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
        tessellator.draw();
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
        worldrenderer.pos(this.left, this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
        worldrenderer.pos(this.right, this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
        worldrenderer.pos(this.right, this.bottom - i1, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 0).endVertex();
        worldrenderer.pos(this.left, this.bottom - i1, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 0).endVertex();
        tessellator.draw();
        int j1 = this.func_148135_f();
        if (j1 > 0) {
            int k1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight();
            k1 = MathHelper.clamp_int(k1, 32, this.bottom - this.top - 8);
            int l1 = (int) this.amountScrolled * (this.bottom - this.top - k1) / j1 + this.top;
            if (l1 < this.top) {
                l1 = this.top;
            }

            worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
            worldrenderer.pos(i, this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
            worldrenderer.pos(j, this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
            worldrenderer.pos(j, this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
            worldrenderer.pos(i, this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
            tessellator.draw();
            worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
            worldrenderer.pos(i, l1 + k1, 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
            worldrenderer.pos(j, l1 + k1, 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
            worldrenderer.pos(j, l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
            worldrenderer.pos(i, l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
            tessellator.draw();
            worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
            worldrenderer.pos(i, l1 + k1 - 1, 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
            worldrenderer.pos(j - 1, l1 + k1 - 1, 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
            worldrenderer.pos(j - 1, l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex();
            worldrenderer.pos(i, l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex();
            tessellator.draw();
        }

        this.func_148142_b(mouseXIn, mouseYIn);
        GlStateManager.enableTexture2D();
        GlStateManager.shadeModel(7424);
        GlStateManager.enableAlpha();
        GlStateManager.disableBlend();
    }
}
 
Example 13
Source File: TileEntityAdvancedAirCompressor.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public static int getEfficiency(double temperature){
    return MathHelper.clamp_int((int)((625 - temperature) / 3), 0, 100);//0% efficiency at > 350 degree C, 100% at < 50 degree C.
}
 
Example 14
Source File: TileEntityCandelabra.java    From GardenCollection with MIT License 4 votes vote down vote up
public int getDirection () {
    return MathHelper.clamp_int(direction & 7, 2, 5);
}
 
Example 15
Source File: ItemChainLink.java    From GardenCollection with MIT License 4 votes vote down vote up
@Override
public String getUnlocalizedName (ItemStack item) {
    return super.getUnlocalizedName(item) + "." + types[MathHelper.clamp_int(item.getItemDamage(), 0, types.length - 1)];
}
 
Example 16
Source File: ItemChainLink.java    From GardenCollection with MIT License 4 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
public IIcon getIconFromDamage (int damage) {
    return iconArray[MathHelper.clamp_int(damage, 0, types.length - 1)];
}
 
Example 17
Source File: BlockGTSapling.java    From GardenCollection with MIT License 4 votes vote down vote up
@Override
public int damageDropped (int meta) {
    return MathHelper.clamp_int(meta & 7, 0, types.length);
}
 
Example 18
Source File: ItemStorageFluid.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@SideOnly(Side.CLIENT)
public Icon getIconFromDamage(int par1)
{
	int j = MathHelper.clamp_int(par1, 0, 7);
	return this.icons[j];
}
 
Example 19
Source File: SeaLantern.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@Override
public int quantityDroppedWithBonus(int fortune, Random random) {
	return MathHelper.clamp_int(this.quantityDropped(random) + random.nextInt(fortune + 1), 1, 5);
}
 
Example 20
Source File: MixinGuiSlot.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @author CCBlueX
 */
@Overwrite
public void drawScreen(int mouseXIn, int mouseYIn, float p_148128_3_) {
    if(this.field_178041_q) {
        this.mouseX = mouseXIn;
        this.mouseY = mouseYIn;
        this.drawBackground();
        int i = this.getScrollBarX();
        int j = i + 6;
        this.bindAmountScrolled();
        GlStateManager.disableLighting();
        GlStateManager.disableFog();
        Tessellator tessellator = Tessellator.getInstance();
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
        int k = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
        int l = this.top + 4 - (int) this.amountScrolled;
        if(this.hasListHeader) {
            this.drawListHeader(k, l, tessellator);
        }

        this.drawSelectionBox(k, l + 2, mouseXIn, mouseYIn + 2);
        GlStateManager.disableDepth();
        int i1 = 4;

        // ClientCode
        ScaledResolution scaledResolution = new ScaledResolution(mc);
        Gui.drawRect(0, 0, scaledResolution.getScaledWidth(), this.top, Integer.MIN_VALUE);
        Gui.drawRect(0, this.bottom, scaledResolution.getScaledWidth(), this.height, Integer.MIN_VALUE);

        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(770, 771, 0, 1);
        GlStateManager.disableAlpha();
        GlStateManager.shadeModel(7425);
        GlStateManager.disableTexture2D();
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
        worldrenderer.pos((double) this.left, (double) (this.top + i1), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 0).endVertex();
        worldrenderer.pos((double) this.right, (double) (this.top + i1), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 0).endVertex();
        worldrenderer.pos((double) this.right, (double) this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
        worldrenderer.pos((double) this.left, (double) this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
        tessellator.draw();
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
        worldrenderer.pos((double) this.left, (double) this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
        worldrenderer.pos((double) this.right, (double) this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
        worldrenderer.pos((double) this.right, (double) (this.bottom - i1), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 0).endVertex();
        worldrenderer.pos((double) this.left, (double) (this.bottom - i1), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 0).endVertex();
        tessellator.draw();
        int j1 = this.func_148135_f();
        if(j1 > 0) {
            int k1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight();
            k1 = MathHelper.clamp_int(k1, 32, this.bottom - this.top - 8);
            int l1 = (int) this.amountScrolled * (this.bottom - this.top - k1) / j1 + this.top;
            if(l1 < this.top) {
                l1 = this.top;
            }

            worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
            worldrenderer.pos((double) i, (double) this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
            worldrenderer.pos((double) j, (double) this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
            worldrenderer.pos((double) j, (double) this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
            worldrenderer.pos((double) i, (double) this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
            tessellator.draw();
            worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
            worldrenderer.pos((double) i, (double) (l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
            worldrenderer.pos((double) j, (double) (l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
            worldrenderer.pos((double) j, (double) l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
            worldrenderer.pos((double) i, (double) l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
            tessellator.draw();
            worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
            worldrenderer.pos((double) i, (double) (l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
            worldrenderer.pos((double) (j - 1), (double) (l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
            worldrenderer.pos((double) (j - 1), (double) l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex();
            worldrenderer.pos((double) i, (double) l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex();
            tessellator.draw();
        }

        this.func_148142_b(mouseXIn, mouseYIn);
        GlStateManager.enableTexture2D();
        GlStateManager.shadeModel(7424);
        GlStateManager.enableAlpha();
        GlStateManager.disableBlend();
    }
}