// Override default behavior to use putStack
// instead of manipulating stackSize directly.
ItemStack slotStack = slot.getStack();
ItemStack holding = player.inventory.getItemStack();
if ((slotStack != null) && (holding != null) &&
((holding == null) ? slot.canTakeStack(player) : slot.isItemValid(holding)) &&
StackUtils.matches(slotStack, holding)) {
int amount = ((button == 0) ? holding.stackSize : 1);
amount = Math.min(amount, slot.getSlotStackLimit() - slotStack.stackSize);
amount = Math.min(amount, slotStack.getMaxStackSize() - slotStack.stackSize);
if (amount > 0) {