Hi guys, I have a TileEntity with only 1 slot and it can contain only 1 item, but those item's max stack size is 4 and when I try to shift-click it transfer all stack. I tried to use overrided mergeItemStack function, but minecraft chrashes. In the console lot of this 2 strings:
2013-08-28 23:40:26 [iNFO] [sTDOUT] at net.minecraft.inventory.Container.retrySlotClick(Container.java:520)
2013-08-28 23:40:26 [iNFO] [sTDOUT] at net.minecraft.inventory.Container.slotClick(Container.java:291)
[spoiler=mergeItemStack]
@Override
public boolean mergeItemStack(ItemStack stack, int begin, int end, boolean backwards)
{
System.out.println("enter");
int i = backwards ? end-1 : begin, increment = backwards ? -1 : 1;
boolean flag = false;
while(stack.stackSize > 0 && i >= begin && i < end)
{
System.out.println(i);
Slot slot = this.getSlot(i);
ItemStack slotStack = slot.getStack();
int slotStacklimit = i < te.getSizeInventory() ? te.getInventoryStackLimit() : 64;
int totalLimit = slotStacklimit < stack.getMaxStackSize() ? slotStacklimit : stack.getMaxStackSize();
System.out.println("Slot Stack Limit: " + slotStacklimit);
System.out.println("Total limit: " + totalLimit);
if(slotStack == null)
{
System.out.println("Empty Stack");
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))
{
System.out.println("Add to stack");
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;
}
System.out.println("exit");
return flag;
}
[spoiler=transferStackInSlot]
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotID)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(slotID);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (slotID < NumVars.CMFTEslotsCount)
{
if (!this.mergeItemStack(itemstack1, NumVars.CMFTEslotsCount, this.inventorySlots.size(), true))
return null;
}
else
{
if (itemstack1.getItem() instanceof AnimusSpall)
{
if (!this.mergeItemStack(itemstack1, 0, NumVars.CMFTEslotsCount, false))
return null;
}
else
return null;
}
if (itemstack1.stackSize == 0)
slot.putStack((ItemStack)null);
else
slot.onSlotChanged();
}
return itemstack;
}