CustomInventoryGui.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package me.km.networking;
  2. import me.km.KajetansMod;
  3. import me.km.inventory.CustomContainer;
  4. import me.km.inventory.InventoryBase;
  5. import net.minecraft.client.renderer.GlStateManager;
  6. import net.minecraft.client.Minecraft;
  7. import net.minecraft.inventory.IInventory;
  8. import net.minecraft.util.ResourceLocation;
  9. import net.minecraftforge.fml.relauncher.Side;
  10. import net.minecraftforge.fml.relauncher.SideOnly;
  11. import net.minecraft.client.gui.inventory.GuiContainer;
  12. @SideOnly(Side.CLIENT)
  13. public class CustomInventoryGui extends GuiContainer
  14. {
  15. /** The ResourceLocation containing the chest GUI texture. */
  16. private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("textures/gui/container/generic_54.png");
  17. private static final ResourceLocation EMPTY_TILE = new ResourceLocation(KajetansMod.MODID, "textures/gui/container/empty_tile.png");
  18. private final IInventory pInv;
  19. private final InventoryBase inv;
  20. private final int inventoryRows;
  21. public CustomInventoryGui(IInventory pInv, InventoryBase inv)
  22. {
  23. super(new CustomContainer(inv, Minecraft.getMinecraft().player));
  24. this.pInv = pInv;
  25. this.inv = inv;
  26. this.allowUserInput = false;
  27. this.inventoryRows = inv.getRows();
  28. this.ySize = 114 + this.inventoryRows * 18;
  29. }
  30. @Override
  31. public void drawScreen(int mouseX, int mouseY, float partialTicks)
  32. {
  33. this.drawDefaultBackground();
  34. super.drawScreen(mouseX, mouseY, partialTicks);
  35. this.renderHoveredToolTip(mouseX, mouseY);
  36. }
  37. @Override
  38. protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
  39. {
  40. this.fontRenderer.drawString(this.inv.getDisplayName().getUnformattedText(), 8, 6, 4210752);
  41. this.fontRenderer.drawString(this.pInv.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
  42. }
  43. @Override
  44. protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
  45. {
  46. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  47. this.mc.getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
  48. int i = (this.width - this.xSize) / 2;
  49. int j = (this.height - this.ySize) / 2;
  50. this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.inventoryRows * 18 + 17);
  51. this.drawTexturedModalRect(i, j + this.inventoryRows * 18 + 17, 0, 126, this.xSize, 96);
  52. i += 7;
  53. j += 17;
  54. this.mc.getTextureManager().bindTexture(EMPTY_TILE);
  55. for(int x = 0; x < 9; x++)
  56. {
  57. for(int y = 0; y < inventoryRows; y++)
  58. {
  59. if(inv.shouldRenderOverlay(x, y))
  60. {
  61. this.drawTexturedModalRect(i + 18 * x, j + 18 * y, 0, 0, 18, 18);
  62. }
  63. }
  64. }
  65. }
  66. }