Posted September 17, 201411 yr My question: How to make container don't drop items after close and how to pass container slot limit (max. 9)? Thanks for help!
September 17, 201411 yr Author Still can't place item into inventory when more than 9 slots (you are thinking about slot stacksize, but i'm thinking about same slot (as I see there's a limiter to 9 slots in container)). There's my classes (GUI class not neccesary): xxx
September 18, 201411 yr Author Still have a problem. When do't have 9 slots then i can't pickup the item from inventory:(
September 18, 201411 yr Author Container: package sokaya.client.gui; 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 KociolekContainer extends Container { protected IInventory tileEntity; public KociolekContainer(InventoryPlayer inventoryPlayer, IInventory tileEntity2){ tileEntity = tileEntity2; addSlotToContainer(new Slot(inventoryPlayer, 0, 17, 27)); addSlotToContainer(new Slot(inventoryPlayer, 1, 17, 45)); addSlotToContainer(new Slot(inventoryPlayer, 2, 35, 36)); bindPlayerInventory(inventoryPlayer); } /*@Override public void onContainerClosed(EntityPlayer par1EntityPlayer) { super.onContainerClosed(par1EntityPlayer); }*/ @Override public boolean canInteractWith(EntityPlayer player) { return true; } protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) { for (int i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (int i = 0; i < 9; ++i) { this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142)); } } } TileEntity: package sokaya.tileentities; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; public class TileEntityKociolek extends TileEntity implements IInventory{ private final String name = "Kociolek"; private final String tagName = "kociolekCreate"; public static final int INV_SIZE = 3; private ItemStack[] inventory = new ItemStack[iNV_SIZE]; public TileEntityKociolek(){} @Override public int getSizeInventory() { return inventory.length; } @Override public ItemStack getStackInSlot(int var1) { return inventory[var1]; } @Override public ItemStack decrStackSize(int var1, int var2) { ItemStack stack = getStackInSlot(var1); if (stack != null) { if (stack.stackSize > var2) { stack = stack.splitStack(var2); if (stack.stackSize == 0) { setInventorySlotContents(var1, null); } } else { setInventorySlotContents(var1, null); } this.markDirty(); } return stack; } @Override public ItemStack getStackInSlotOnClosing(int var1) { ItemStack stack = getStackInSlot(var1); if (stack != null) { setInventorySlotContents(var1, null); } return stack; } @Override public void setInventorySlotContents(int var1, ItemStack var2) { this.inventory[var1] = var2; if (var2 != null && var2.stackSize > this.getInventoryStackLimit()) { var2.stackSize = this.getInventoryStackLimit(); } this.markDirty(); } @Override public String getInventoryName() { return name; } @Override public boolean hasCustomInventoryName() { return false; } @Override public int getInventoryStackLimit() { return 1; } @Override public void markDirty() { for (int i = 0; i < this.getSizeInventory(); ++i) { if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0) this.setInventorySlotContents(i, null); } } @Override public boolean isUseableByPlayer(EntityPlayer var1) { return true; } @Override public void openInventory(){} @Override public void closeInventory(){} @Override public boolean isItemValidForSlot(int var1, ItemStack var2) { return true; } public void writeToNBT(NBTTagCompound compound) { NBTTagList items = new NBTTagList(); for (int i = 0; i < getSizeInventory(); ++i) { if (getStackInSlot(i) != null) { NBTTagCompound item = new NBTTagCompound(); item.setByte("Slot", (byte) i); getStackInSlot(i).writeToNBT(item); items.appendTag(item); } } compound.setTag(tagName, items); } public void readFromNBT(NBTTagCompound compound) { NBTTagList items = compound.getTagList(tagName,compound.getId()); for (int i = 0; i < items.tagCount(); ++i) { NBTTagCompound item = (NBTTagCompound) items.getCompoundTagAt(i); byte slot = item.getByte("Slot"); if (slot >= 0 && slot < getSizeInventory()) { inventory[slot] = ItemStack.loadItemStackFromNBT(item); } } } }
September 18, 201411 yr These are wrong. You do not want inventoryPlayer here. You want tileEntity as the first argument. addSlotToContainer(new Slot(inventoryPlayer, 0, 17, 27)); addSlotToContainer(new Slot(inventoryPlayer, 1, 17, 45)); addSlotToContainer(new Slot(inventoryPlayer, 2, 35, 36)); Also, please read what was said. You TileEntity only has 3 slots. You must make the array bigger for more than 3 or 9 or 100. Then use that number in your container code to add the slots. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
September 18, 201411 yr Author Ehh, changed it to 64 and still i can't click on the item in slot and move it to another:(
September 18, 201411 yr Author When i want draw the item, it get out for a while from place and back to normal.
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.