Posted March 28, 20178 yr Hey everyone, I am working on a custom GuiContainer in 1.11. I know that my problem is related to adding Slots to the Container. I added the code for my Custom Container, if you think the problem is elsewhere I will post related files public class ContainerBackpack extends Container{ private final int HOTBAR_SLOT_COUNT = 9; private final int PLAYER_INVENTORY_ROW_COUNT = 3; private final int PLAYER_INVENTORY_COLUMN_COUNT = 9; private final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT; private final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT; private final int VANILLA_FIRST_SLOT_INDEX = 0; private final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT; private final int TE_INVENTORY_SLOT_COUNT = 27; public ContainerBackpack(IItemHandler itemHandler, EntityPlayer player) { this.itemHandler = itemHandler; for (int l = 0; l < 3; ++l) { for (int j1 = 0; j1 < 9; ++j1) { this.addSlotToContainer(new SlotItemHandler(itemHandler, j1 + l * 9, 8 + j1 * 18, 18 + l * 18)); } } for (int i = 9; i < player.inventory.getSizeInventory()-5; i++) { addSlotToContainer(new Slot(player.inventory, i, 8 + i % 9 * 18, 61 + 18 * (i / 9))); } } @Override public boolean canInteractWith(EntityPlayer playerIn) { return true; } public static ContainerBackpack build(EntityPlayer player, World world, int x, int y, int z) { ItemStack stack; if(x == 0) { stack = player.getHeldItem(EnumHand.MAIN_HAND); } else { stack = player.getHeldItem(EnumHand.OFF_HAND); } IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); return new ContainerBackpack(handler,player); } @Override public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { Slot sourceSlot = (Slot)inventorySlots.get(index); if (sourceSlot == null || !sourceSlot.getHasStack()) return null; ItemStack sourceStack = sourceSlot.getStack(); ItemStack copyOfSourceStack = sourceStack.copy(); if (index >= VANILLA_FIRST_SLOT_INDEX && index < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) { // This is a vanilla container slot so merge the stack into the tile inventory if (!mergeItemStack(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT, false)){ return null; } } else if (index >= TE_INVENTORY_FIRST_SLOT_INDEX && index < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT) { // This is a TE slot so merge the stack into the players inventory if (!mergeItemStack(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) { return null; } } else { System.err.print("Invalid slotIndex:" + index); return null; } if (sourceStack.getCount() == 0) { sourceSlot.putStack(null); } else { sourceSlot.onSlotChanged(); } return copyOfSourceStack; } } Greetz Failender Edited March 28, 20178 yr by Failender changed title to solved
March 28, 20178 yr You might want to take a look at this: https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/hardlib/api/internal/CommonContainer.java#L23-L33 Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
March 28, 20178 yr Author Your code looks way cleaner than mine Thank you! Found the error, it was me only opening the GUI on Client-Side so yeah. Just me beeing stupid.
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.