Advertisement
Guest User

GuiCharger

a guest
May 21st, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.29 KB | None | 0 0
  1. package me.onVoid.helpfuladdons.charger;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import org.lwjgl.opengl.GL11;
  7.  
  8. import me.onVoid.helpfuladdons.HelpfulAddons;
  9. import me.onVoid.helpfuladdons.References;
  10. import net.minecraft.client.Minecraft;
  11. import net.minecraft.client.gui.inventory.GuiContainer;
  12. import net.minecraft.client.resources.I18n;
  13. import net.minecraft.entity.player.EntityPlayer;
  14. import net.minecraft.entity.player.InventoryPlayer;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.util.ResourceLocation;
  17.  
  18. public class GuiCharger extends GuiContainer {
  19.    
  20.     public static int chargeProgress = 0;
  21.    
  22.     public static final ResourceLocation guiImg = new ResourceLocation(References.MODID + ":" + "textures/gui/multichargergui.png");
  23.    
  24.     public ChargerTileEntity charger;
  25.    
  26.     public GuiCharger(InventoryPlayer pi, ChargerTileEntity ent) {
  27.         super(new ContainerCharger(pi, ent));
  28.        
  29.         this.charger = ent;
  30.        
  31.         this.xSize = 176;
  32.         this.ySize = 166;
  33.     }
  34.  
  35.  
  36.    
  37.     @Override
  38.     protected void drawGuiContainerBackgroundLayer(float arg0, int mouseX, int mouseY) {
  39.         GL11.glColor4f(1F, 1F, 1F, 1F);
  40.         Minecraft.getMinecraft().getTextureManager().bindTexture(guiImg);
  41.         drawTexturedModalRect(guiLeft, guiTop, 0,0, xSize, ySize);
  42.         if (ChargerTileEntity.storage.getEnergyStored() > 0){
  43.             int le = ChargerTileEntity.storage.getMaxEnergyStored() / 40;
  44.             HelpfulAddons.amountOutOfForty = ChargerTileEntity.storage.getEnergyStored() / le;
  45.             drawTexturedModalRect(guiLeft + 10, guiTop + 9 + (40 - Math.round(HelpfulAddons.amountOutOfForty)), 176, 0, 13, Math.round(HelpfulAddons.amountOutOfForty));
  46.         }
  47.     }
  48.    
  49.     public void drawGuiContainerForegroundLayer(int mouseX, int mouseY){
  50.         GL11.glColor4f(1, 1, 1, 1);
  51.         String name = this.charger.hasCustomInventoryName() ? this.charger.getInventoryName() :
  52.             I18n.format(this.charger.getInventoryName(), new Object[0]);
  53.        
  54.         this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
  55.         this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
  56.         drawToolTips(mouseX, mouseY);
  57.     }
  58.    
  59.     public void drawToolTips(int mouseX, int mouseY) {
  60.         int boxX = guiLeft + 10; //These are just like the center of the screen.
  61.         int boxY = guiTop + 9; //You make these in order to get a starting point on where to check (With these, it would be the top left of your GUI)
  62.        
  63.         int defaultX = 12; //These are like the boxes of the area to check.
  64.         int defaultY = 40; //So, if you're rendering an Item to hover over, it would be 16x16.
  65.  
  66.         //This checks if the mouse is in the correct position on screen. You can add and subtract from boxX and Y to determine where to be.
  67.         if(mouseX > boxX && mouseX < boxX + defaultX && mouseY > boxY && mouseY < boxY + defaultY) {
  68.                            List list = new ArrayList(); //Just the list of text to be added. It is just like the addInformation method now. :P
  69.                            list.add(ChargerTileEntity.storage.getEnergyStored() + " / " + ChargerTileEntity.storage.getMaxEnergyStored() + " RF"); //Each time you add something, it's gonna be a new line in the tooltip.
  70.                            this.drawHoveringText(list, mouseX - guiLeft, mouseY - guiTop, fontRendererObj);
  71.         }
  72.     }
  73.    
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement