int sum = itemStack.stackSize + stackInSlot.stackSize;
int maxStackSize = Math.min( stackInSlot.getMaxStackSize(), targetSlot.getSlotStackLimit() );
if( sum <= maxStackSize ) {
stackInSlot.stackSize = sum;
targetSlot.onSlotChanged();
return true;
} else if( stackInSlot.stackSize < maxStackSize ) {
itemStack.stackSize -= maxStackSize - stackInSlot.stackSize;
stackInSlot.stackSize = maxStackSize;
targetSlot.onSlotChanged();