WH-Reaper Posted February 19, 2013 Posted February 19, 2013 Hello, I created container with 5 slots following tutorial here on forge forums. I also properly(at least I hope so) modified transferStackInSlot method. The problem is that I want my container to have capacity only 1 per slot (not 64). I set this using getInventoryStackLimit in my TileEntity for the container. The problem is that each time I transfer stack from player inventory into the container holding shift, it removes whole stack from player inventory, but transfers only 1 piece into the container(obviously because the limit per slot is set to 1). I would like to know how to force it to pick only so many pieces that fits into container for transferring(when using shift). If this would be too difficult, I would simply like to do it so it picks only one item even when using shift. I guess I need to rewrite container method mergeItemStack? Or maybe something different? Thanks in advance to anyone who tries to help Here is my transferStackInSlot method if needed Reveal hidden contents public ItemStack transferStackInSlot(EntityPlayer player, int slot) { ItemStack stack = null; Slot slotObject = (Slot) inventorySlots.get(slot); //null checks and checks if the item can be stacked (maxStackSize > 1) if (slotObject != null && slotObject.getHasStack()) { ItemStack stackInSlot = slotObject.getStack(); stack = stackInSlot.copy(); //merges the item into player inventory since its in the tileEntity if (slot < 5) { if (!this.mergeItemStack(stackInSlot, 5, 41, true)) { return null; } } //places it into the tileEntity is possible since its in the player inventory else if (!this.mergeItemStack(stackInSlot, 0, 5, false)) { return null; } if (stackInSlot.stackSize == 0) { slotObject.putStack(null); } else { slotObject.onSlotChanged(); } if (stackInSlot.stackSize == stack.stackSize) { return null; } slotObject.onPickupFromSlot(player, stackInSlot); } return stack; } Quote Sorry for mistakes, English is not my mother tongue
thebest108 Posted February 20, 2013 Posted February 20, 2013 You could try checking the stack size with stack.stackSize, and check if it equals 1, otherwise subtract 1 from the stack, and add a new stack to the slot, then check if there is an empty slot and if there is, the repeat Hope this helps, I'm still newbish to modding Quote "you seem to be THE best modder I've seen imo." ~spynathan ლ(́◉◞౪◟◉‵ლ
WH-Reaper Posted February 20, 2013 Author Posted February 20, 2013 Yes, I thought of this solution. The problem is I don't exactly know how to achieve that Quote Sorry for mistakes, English is not my mother tongue
WH-Reaper Posted February 20, 2013 Author Posted February 20, 2013 bump Quote Sorry for mistakes, English is not my mother tongue
WH-Reaper Posted February 23, 2013 Author Posted February 23, 2013 bump Quote Sorry for mistakes, English is not my mother tongue
WH-Reaper Posted February 25, 2013 Author Posted February 25, 2013 bump Quote Sorry for mistakes, English is not my mother tongue
WH-Reaper Posted February 28, 2013 Author Posted February 28, 2013 bump Quote Sorry for mistakes, English is not my mother tongue
Foivos Posted March 1, 2013 Posted March 1, 2013 I think I figured it out. You don't need to change anything from the defaults except for the following: change the TileEntity.getInventoryStackLimit to return 1, or any value you want. Then in your Container class (ContainerTiny in the tutorial) add the following function: Reveal hidden contents @Override public boolean mergeItemStack(ItemStack stack, int begin, int end, boolean backwards) { int i = backwards ? end-1 : begin, increment = backwards ? -1 : 1; boolean flag = false; while(stack.stackSize > 0 && i >= begin && i < end) { Slot slot = this.getSlot(i); ItemStack slotStack = slot.getStack(); int slotStacklimit = i<tileEntity.getSizeInventory() ? tileEntity.getInventoryStackLimit() : 64; int totalLimit = slotStacklimit < stack.getMaxStackSize() ? slotStacklimit : stack.getMaxStackSize(); if(slotStack==null) { int transfer = totalLimit < stack.stackSize ? totalLimit : stack.stackSize; ItemStack stackToPut = stack.copy(); stackToPut.stackSize = transfer; slot.putStack(stackToPut); slot.onSlotChanged(); stack.stackSize -= transfer; flag = true; } else if(slotStack.itemID == stack.itemID && (!stack.getHasSubtypes() || stack.getItemDamage() == slotStack.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, slotStack)) { int maxTransfer = totalLimit - slotStack.stackSize; int transfer = maxTransfer > stack.stackSize ? stack.stackSize : maxTransfer; slotStack.stackSize += transfer; slot.onSlotChanged(); stack.stackSize -= transfer; flag = true; } i += increment; } return flag; } Basically, this function was called from Container, which did not care about the value of tileEntity.getInventoryStackSize() at all. I made it so when you shift right click the container will be filled as much as possible. You can change that in the code above pretty easily. Hope that helps Quote
WH-Reaper Posted March 5, 2013 Author Posted March 5, 2013 Thanks, works like charm! Quote Sorry for mistakes, English is not my mother tongue
Recommended Posts
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.