package me.km.networking; import me.km.KajetansMod; import me.km.inventory.CustomContainer; import me.km.inventory.InventoryBase; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.Minecraft; import net.minecraft.inventory.IInventory; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraft.client.gui.inventory.GuiContainer; @SideOnly(Side.CLIENT) public class CustomInventoryGui extends GuiContainer { /** The ResourceLocation containing the chest GUI texture. */ private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("textures/gui/container/generic_54.png"); private static final ResourceLocation EMPTY_TILE = new ResourceLocation(KajetansMod.MODID, "textures/gui/container/empty_tile.png"); private final IInventory pInv; private final InventoryBase inv; private final int inventoryRows; public CustomInventoryGui(IInventory pInv, InventoryBase inv) { super(new CustomContainer(inv, Minecraft.getMinecraft().player)); this.pInv = pInv; this.inv = inv; this.allowUserInput = false; this.inventoryRows = inv.getRows(); this.ySize = 114 + this.inventoryRows * 18; } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawDefaultBackground(); super.drawScreen(mouseX, mouseY, partialTicks); this.renderHoveredToolTip(mouseX, mouseY); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { this.fontRenderer.drawString(this.inv.getDisplayName().getUnformattedText(), 8, 6, 4210752); this.fontRenderer.drawString(this.pInv.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(CHEST_GUI_TEXTURE); int i = (this.width - this.xSize) / 2; int j = (this.height - this.ySize) / 2; this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.inventoryRows * 18 + 17); this.drawTexturedModalRect(i, j + this.inventoryRows * 18 + 17, 0, 126, this.xSize, 96); i += 7; j += 17; this.mc.getTextureManager().bindTexture(EMPTY_TILE); for(int x = 0; x < 9; x++) { for(int y = 0; y < inventoryRows; y++) { if(inv.shouldRenderOverlay(x, y)) { this.drawTexturedModalRect(i + 18 * x, j + 18 * y, 0, 0, 18, 18); } } } } }