Posted September 18, 201510 yr I am making a mod and I have coded a very simple GUI to appear when I open a chest. Now I need help adding slots to the gui. If you could help me that would be great. Also it would be great if you could let me know about any extra code I need to add so I can properly make the chest work. My coding for the chest looks like this public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) { if (p_149727_1_.isRemote) { return true; } else { IInventory iinventory = this.func_149951_m(p_149727_1_, p_149727_2_, p_149727_3_, p_149727_4_); if (iinventory != null) { Minecraft.getMinecraft().displayGuiScreen(new GuiChest()); } return true; } My coding for the gui looks like this public class GuiChest extends GuiScreen{ int guiWidth = 182; int guiHeight = 187; @Override public void drawScreen(int x, int y, float ticks) { int guiX = (width - guiWidth) / 2; int guiY = (height - guiHeight) / 2; GL11.glColor4f(1, 1, 1, 1); drawDefaultBackground(); mc.renderEngine.bindTexture(new ResourceLocation(RefStrings.MODID, "textures/gui/chestGui.png")); drawTexturedModalRect(guiX, guiY, 35, 39, guiWidth, guiHeight); fontRendererObj.drawString("Grass Chest", guiX + 40, guiY + 5, 0x601959); super.drawScreen(x, y, ticks); } protected void keyTyped(char c, int key) { switch(key){ case Keyboard.KEY_E: mc.displayGuiScreen(null); super.keyTyped(c, key); } } }
September 19, 201510 yr You will need to add the slots in your Container class in the constructor by calling this.addSlotToContainer(new Slot(...)); Here's an example of adding the player's inventory and hotbar to the Container: // ADD PLAYER's INVENTORY TO SLOTS for(int i=0;i<3;i++) { for(int j=0;j<9;j++) { this.addSlotToContainer(new Slot(ep.inventory, j + i * 9 + 9,16+j*20, 149+i*20)); } } // ADD PLAYER's HOTBAR for(int i=0;i<9;i++) { this.addSlotToContainer(new Slot(ep.inventory, i, 16+i*20, 213)); } PS: You will also need to override the transferStackInSlot(...) method. It's called whenever a player is pressing SHIFT on an Item. PPS: Noone wants to see a Thread like yours. Please use the BB-Codes spoiler+code to make the Thread much easier to read.[/code]
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.