Mrhand3

BaseGuiContainer

Jan 30th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. package Mrhand3.SOARYN.InventoryReg.gui;
  2.  
  3. import net.minecraft.client.gui.inventory.GuiContainer;
  4. import net.minecraft.client.renderer.RenderHelper;
  5. import net.minecraft.util.StatCollector;
  6.  
  7. import org.lwjgl.opengl.GL11;
  8. import org.lwjgl.opengl.GL12;
  9.  
  10. public abstract class BaseGuiContainer < T extends Mrhand3.SOARYN.Gui.ContainerInventory<? >> extends
  11. GuiContainer
  12. {
  13. protected Base root;
  14. protected String name;
  15.  
  16. public BaseGuiContainer(T container, int width, int height, String name)
  17. {
  18. super(container);
  19. xSize = width;
  20. ySize = height;
  21. root = createRoot();
  22. this.name = name;
  23. }
  24.  
  25. protected Base createRoot()
  26. {
  27. return new Panel(0, 0, xSize, ySize, getContainer());
  28. }
  29.  
  30. @SuppressWarnings("unchecked")
  31. public T getContainer()
  32. {
  33. return (T)inventorySlots;
  34. }
  35.  
  36. @Override
  37. protected void mouseClickMove(int mouseX, int mouseY, int button, long time)
  38. {
  39. super.mouseClickMove(mouseX, mouseY, button, time);
  40. root.mouseClickMove(mouseX - this.guiLeft, mouseY - this.guiTop, button, time);
  41. }
  42.  
  43. public void preRender(float mouseX, float mouseY)
  44. {
  45. root.mouseMovedOrUp((int)mouseX - this.guiLeft, (int)mouseY - this.guiTop, -1);
  46. }
  47.  
  48. @Override
  49. protected void keyTyped(char par1, int par2)
  50. {
  51. super.keyTyped(par1, par2);
  52. root.keyTyped(par1, par2);
  53. }
  54.  
  55. public void postRender(int mouseX, int mouseY) {}
  56.  
  57. @Override
  58. protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY)
  59. {
  60. this.preRender(mouseX, mouseY);
  61. GL11.glPushMatrix();
  62. GL11.glTranslated(this.guiLeft, this.guiTop, 0);
  63. Base.IS_OVERLAY_PASS = false;
  64. root.render(this.mc, 0, 0, mouseX - this.guiLeft, mouseY - this.guiTop);
  65. GL11.glPopMatrix();
  66. }
  67.  
  68. @Override
  69. protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
  70. {
  71. this.postRender(mouseX, mouseY);
  72. String machineName = StatCollector.translateToLocal(name);
  73. int x = this.xSize / 2 - (fontRenderer.getStringWidth(machineName) / 2);
  74. fontRenderer.drawString(machineName, x, 6, 4210752);
  75. String translatedName = StatCollector.translateToLocal("container.inventory");
  76. fontRenderer.drawString(translatedName, 8, this.ySize - 96 + 2, 4210752);
  77. }
  78.  
  79. @Override
  80. public void drawScreen(int par1, int par2, float par3)
  81. {
  82. super.drawScreen(par1, par2, par3);
  83. GL11.glDisable(GL12.GL_RESCALE_NORMAL);
  84. RenderHelper.disableStandardItemLighting();
  85. GL11.glDisable(GL11.GL_LIGHTING);
  86. GL11.glDisable(GL11.GL_DEPTH_TEST);
  87. GL11.glPushMatrix();
  88. Base.IS_OVERLAY_PASS = true;
  89. root.render(this.mc, this.guiLeft, this.guiTop, par1 - this.guiLeft, par2 - this.guiTop);
  90. GL11.glPopMatrix();
  91. GL11.glEnable(GL12.GL_RESCALE_NORMAL);
  92. GL11.glEnable(GL11.GL_LIGHTING);
  93. GL11.glEnable(GL11.GL_DEPTH_TEST);
  94. RenderHelper.enableStandardItemLighting();
  95. }
  96.  
  97. public void sendButtonClick(int buttonId)
  98. {
  99. this.mc.playerController.sendEnchantPacket(getContainer().windowId, buttonId);
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment