Posted July 8, 201411 yr I am just starting to learn how to make GUIs and I have recently made one that has a 2x3 inventory at the top and a 2x1 inventory at the bottom, like the normal inventory just 2 wide. When I put anything in the top left slot it also appears in the bottom left slot and I don't understand why.
July 8, 201411 yr Author Here it is, I am using the one you gave me and I ma trying to adapt it. package com.blocklings.entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class ContainerBlockling extends Container { protected IInventory gear; private int player_inventory_x = 70; private int player_inventory_y = 8; private int loot_x = 8; private int loot_y = 10; public ContainerBlockling(InventoryPlayer inventoryPlayer, IInventory c) { gear = c; { int isize = c.getSizeInventory(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { addSlotToContainer(new Slot(c, j + i * 2, (loot_x + j * 18), (loot_y + i * 18))); } } for (int j = 0; j < 2; j++) { addSlotToContainer(new SlotUpgrade(c, j * 2, (loot_x + j * 18), (loot_y + j + 4 * 18))); } } bindPlayerInventory(inventoryPlayer); } public boolean canInteractWith(EntityPlayer player) { return gear.isUseableByPlayer(player); } protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, player_inventory_x + j * 18, player_inventory_y + i * 18)); } } for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(inventoryPlayer, i, player_inventory_x + i * 18, player_inventory_y + 54 + 4)); } } public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { ItemStack itemstack = null; Slot slot = (Slot) this.inventorySlots.get(par2); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); int s = gear.getSizeInventory(); if (par2 < s) { if (!this.mergeItemStack(itemstack1, s, this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(itemstack1, 0, s, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack(null); } else { slot.onSlotChanged(); } } return itemstack; } public void onContainerClosed(EntityPlayer par1EntityPlayer) { super.onContainerClosed(par1EntityPlayer); this.gear.closeInventory(); } }
July 8, 201411 yr Slots in container numerated from 0 to inventory_size - 1 Let's look at your code. for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { addSlotToContainer(new Slot(c, j + i * 2, (loot_x + j * 18), (loot_y + i * 18))); } This code adds slots: 0, 1, 2, 3, 4, 5 for (int j = 0; j < 2; j++) { addSlotToContainer(new SlotUpgrade(c, j * 2, (loot_x + j * 18), (loot_y + j + 4 * 18))); } This code adds slots: 0 (again), and 5 (again) I think you should edit second part to this: for (int j = 0; j < 2; j++) { addSlotToContainer(new SlotUpgrade(c, 6 + j, (loot_x + j * 18), (loot_y + j + 4 * 18))); } And it will add slots 6 and 7 instead of 0 and 5
July 8, 201411 yr Author Thanks for explaining it and showing me what to do. It makes a lot more sense now. Once last thing though, I want to check the item in a current slot so how would I go about that?
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.