Advertisement
Guest User

GuiCompressor.java

a guest
Jan 18th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. package com.TechDweebGaming.MystTech.client.gui;
  2.  
  3. import java.util.List;
  4.  
  5. import net.minecraft.client.gui.inventory.GuiContainer;
  6. import net.minecraft.client.renderer.GlStateManager;
  7. import net.minecraft.inventory.IInventory;
  8. import net.minecraft.util.ResourceLocation;
  9. import net.minecraft.util.StatCollector;
  10.  
  11. import com.TechDweebGaming.MystTech.gui.ContainerCompressor;
  12. import com.TechDweebGaming.MystTech.reference.Reference;
  13. import com.TechDweebGaming.MystTech.tileentity.CompressorTileEntity;
  14. import com.google.common.collect.Lists;
  15.  
  16. public class GuiCompressor extends GuiContainer {
  17.  
  18. private IInventory playerInv;
  19. private CompressorTileEntity te;
  20.  
  21. //Power Things
  22. private static final int bar1x = 1;
  23. private static final int bar2x = 17;
  24. private static final int barWidth = 14;
  25. private static final int barHeight = 42;
  26.  
  27. public GuiCompressor(IInventory playerInv, CompressorTileEntity te) {
  28. super(new ContainerCompressor(playerInv, te));
  29.  
  30. this.playerInv = playerInv;
  31. this.te = te;
  32.  
  33. this.xSize = 175;
  34. this.ySize = 165;
  35. }
  36.  
  37. @Override
  38. protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
  39. GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
  40. this.mc.getTextureManager().bindTexture(new ResourceLocation("mysttech:textures/gui/Compressor.png"));
  41. this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
  42.  
  43. //Energy Bar
  44. int x = (width - xSize) / 2;
  45. drawEnergyBar(x + xSize - 14 - 8, 7 + 20, te.getPowerLevel(), te.EnergyLimit);
  46. }
  47.  
  48. @Override
  49. protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
  50. String s = this.te.getDisplayName().getUnformattedText();
  51. this.fontRendererObj.drawString(s, 82 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
  52. this.fontRendererObj.drawString(this.playerInv.getDisplayName().getUnformattedText(), 8, 72, 4210752);
  53.  
  54. //Bar Tool-Tip
  55. drawBarTooltip(mouseX, mouseY, xSize - 14 - 8, 20);
  56. }
  57.  
  58. private void drawEnergyBar(int x, int y, int powerLevel, int powerLimit) {
  59. int bar2height = 1 + powerLevel * (barHeight - 2) / powerLimit;
  60. int bar1height = barHeight - bar2height;
  61.  
  62. mc.renderEngine.bindTexture(new ResourceLocation("mysttech:/textures/gui/Energy.png"));
  63. drawModalRectWithCustomSizedTexture(x, y, bar1x, 0, barWidth, bar1height, 32, 64);
  64. drawModalRectWithCustomSizedTexture(x, y + bar1height, bar2x, bar1height, barWidth, bar2height, 32, 64);
  65. }
  66.  
  67. private void drawBarTooltip(int mx, int my, int ox, int oy){
  68. int x = (width - xSize) / 2;
  69. int y = (height - ySize) / 2;
  70. int rx = mx - ox - x;
  71. int ry = my - oy - y;
  72.  
  73. if (rx < 0 || ry < 0 || rx > barWidth || ry > barHeight)
  74. return;
  75.  
  76. List<String> tooltip = Lists.newArrayList();
  77. tooltip.add(StatCollector.translateToLocal("text." + Reference.MOD_ID + ".compressor.energy.label"));
  78. tooltip.add(String.format("%d / %d RF", te.getPowerLevel(), te.EnergyLimit));
  79.  
  80. drawHoveringText(tooltip, mx - x, my - y);
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement