Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.theundertaker11.GeneticsReborn.blocks.cellanalyser;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.gui.inventory.GuiContainer;
- import net.minecraft.client.renderer.GlStateManager;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.util.ResourceLocation;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import java.awt.*;
- import java.util.ArrayList;
- import java.util.List;
- import com.theundertaker11.GeneticsReborn.Reference;
- /**
- * User: brandon3055
- * Date: 06/01/2015
- *
- * GuiInventoryAdvanced is a gui similar to that of a furnace. It has a progress bar and a burn time indicator.
- * Both indicators have mouse over text
- */
- @SideOnly(Side.CLIENT)
- public class GuiCellAnalyser extends GuiContainer {
- // This is the resource location for the background image
- private static final ResourceLocation texture = new ResourceLocation(Reference.MODID, "textures/gui/GuiCellAnalyser_bg.png");
- private GRTileEntityCellAnalyser tileEntity;
- public GuiCellAnalyser(InventoryPlayer invPlayer, GRTileEntityCellAnalyser tileInventory){
- super(new ContainerCellAnalyser(invPlayer, tileInventory));
- // Set the width and height of the gui
- xSize = 176;
- ySize = 207;
- this.tileEntity = tileInventory;
- }
- // some [x,y] coordinates of graphical elements
- final int COOK_BAR_XPOS = 49;
- final int COOK_BAR_YPOS = 60;
- final int COOK_BAR_ICON_U = 0; // texture position of white arrow icon
- final int COOK_BAR_ICON_V = 207;
- final int COOK_BAR_WIDTH = 80;
- final int COOK_BAR_HEIGHT = 17;
- final int FLAME_XPOS = 54;
- final int FLAME_YPOS = 80;
- final int FLAME_ICON_U = 176; // texture position of flame icon
- final int FLAME_ICON_V = 0;
- final int FLAME_WIDTH = 14;
- final int FLAME_HEIGHT = 14;
- final int FLAME_X_SPACING = 18;
- @Override
- protected void drawGuiContainerBackgroundLayer(float partialTicks, int x, int y) {
- // Bind the image texture
- Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
- // Draw the image
- GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
- drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
- // get cook progress as a double between 0 and 1
- double cookProgress = tileEntity.percComplete();
- // draw the cook progress bar
- drawTexturedModalRect(guiLeft + COOK_BAR_XPOS, guiTop + COOK_BAR_YPOS, COOK_BAR_ICON_U, COOK_BAR_ICON_V,
- (int)(cookProgress * COOK_BAR_WIDTH), COOK_BAR_HEIGHT);
- // draw the fuel remaining bar for each fuel slot flame
- double energyRemaining = tileEntity.fractionOfEnergyRemaining();
- int yOffset = (int)((1.0 - energyRemaining) * FLAME_HEIGHT);
- drawTexturedModalRect(guiLeft + FLAME_XPOS + FLAME_X_SPACING * 0, guiTop + FLAME_YPOS + yOffset,
- FLAME_ICON_U, FLAME_ICON_V + yOffset, FLAME_WIDTH, FLAME_HEIGHT - yOffset);
- }
- @Override
- protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
- super.drawGuiContainerForegroundLayer(mouseX, mouseY);
- final int LABEL_XPOS = 5;
- final int LABEL_YPOS = 5;
- fontRendererObj.drawString("Cell Analyser", LABEL_XPOS, LABEL_YPOS, Color.darkGray.getRGB());
- List<String> hoveringText = new ArrayList<String>();
- // If the mouse is over the progress bar add the progress bar hovering text
- if (isInRect(guiLeft + COOK_BAR_XPOS, guiTop + COOK_BAR_YPOS, COOK_BAR_WIDTH, COOK_BAR_HEIGHT, mouseX, mouseY))
- {
- hoveringText.add("Energy:");
- int cookPercentage =(int)(tileEntity.fractionOfEnergyRemaining() * 100);
- hoveringText.add(cookPercentage + "%");
- }
- // If the mouse is over one of the burn time indicator add the burn time indicator hovering text
- if (isInRect(guiLeft + FLAME_XPOS + FLAME_X_SPACING * 0, guiTop + FLAME_YPOS, FLAME_WIDTH, FLAME_HEIGHT, mouseX, mouseY))
- {
- hoveringText.add("Energy:");
- hoveringText.add(tileEntity.getEnergyStored(null) + " RF");
- }
- // If hoveringText is not empty draw the hovering text
- if (!hoveringText.isEmpty()){
- drawHoveringText(hoveringText, mouseX - guiLeft, mouseY - guiTop, fontRendererObj);
- }
- // // You must re bind the texture and reset the colour if you still need to use it after drawing a string
- // Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
- // GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
- }
- // Returns true if the given x,y coordinates are within the given rectangle
- public static boolean isInRect(int x, int y, int xSize, int ySize, int mouseX, int mouseY){
- return ((mouseX >= x && mouseX <= x+xSize) && (mouseY >= y && mouseY <= y+ySize));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment