slot = (Slot) this.inventorySlots.get(k);
stackInSlot = slot.getStack();
if (slot.isItemValid(stack) && stackInSlot == null) {
slot.putStack(ItemHelper.cloneStack(stack, Math.min(stack.stackSize, slot.getSlotStackLimit())));
slot.onSlotChanged();
if (slot.getStack() != null) {
stack.stackSize -= slot.getStack().stackSize;
slotFound = true;
}