public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
   Slot slot = getSlot(par2);
   if (slot != null && slot.getHasStack()) {
     ItemStack stack = slot.getStack().copy();
     if (par2 == 0) {
       if (!mergeItemStack(slot.getStack(), 9, this.inventorySlots.size(), true)) {
         return null;
       } else {
         if (slot.getStack().stackSize == 0) {
           putStackInSlot(par2, null);
         } else {
           slot.onSlotChanged();
         }
         return stack;
       }
     } else if (par2 >= 9) {
       if (!mergeItemStack(slot.getStack(), 0, 1, true)) {
         return null;
       } else {
         if (slot.getStack().stackSize == 0) {
           slot.putStack(null);
         } else {
           slot.onSlotChanged();
         }
         return stack;
       }
     }
   }
   return null;
 }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {

    ItemStack newItemStack = null;
    Slot slot = (Slot) inventorySlots.get(slotIndex);

    if (slot != null && slot.getHasStack()) {
      ItemStack itemStack = slot.getStack();
      newItemStack = itemStack.copy();

      if (slotIndex < BAG_INVENTORY_ROWS * BAG_INVENTORY_COLUMNS) {
        if (!this.mergeItemStack(
            itemStack, BAG_INVENTORY_ROWS * BAG_INVENTORY_COLUMNS, inventorySlots.size(), false))
          return null;
      } else if (!this.mergeItemStack(
          itemStack, 0, BAG_INVENTORY_ROWS * BAG_INVENTORY_COLUMNS, false)) return null;

      if (itemStack.stackSize == 0) {
        slot.putStack((ItemStack) null);
      } else {
        slot.onSlotChanged();
      }
    }

    return newItemStack;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
    ItemStack itemstack = null;
    Slot slot = (Slot) this.inventorySlots.get(par2);

    if (slot != null && slot.getHasStack()) {
      ItemStack itemstack1 = slot.getStack();
      itemstack = itemstack1.copy();

      if (par2 == 0) {
        if (!this.mergeItemStack(itemstack1, 1, 37, true)) {
          return null;
        }
      } else if (par2 != 0) {
        if (par2 >= 1 && par2 < 37) {
          if (!this.mergeItemStack(itemstack1, 0, 1, false)) {
            return null;
          }
        }
      }
      slot.onSlotChanged();
      if (itemstack1.stackSize == 0) {
        slot.putStack((ItemStack) null);
      }

      slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
    }

    return itemstack;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
    ItemStack itemstack = null;
    Slot slot = (Slot) inventorySlots.get(slotIndex);

    if (slot != null && slot.getHasStack()) {
      ItemStack itemstack1 = slot.getStack();
      itemstack = itemstack1.copy();

      if ((slotIndex < 0 || slotIndex > 2) && slotIndex != 3) {
        if (!ingredientSlot.getHasStack() && ingredientSlot.isItemValid(itemstack1)) {
          if (!mergeItemStack(itemstack1, 3, 4, false)) return null;
        } else if (PotionSlot.canHoldPotion(itemstack)) {
          if (!mergeItemStack(itemstack1, 0, 3, false)) return null;
        } else if (slotIndex >= 4 && slotIndex < 31) {
          if (!mergeItemStack(itemstack1, 31, 40, false)) return null;
        } else if (slotIndex >= 31 && slotIndex < 40) {
          if (!mergeItemStack(itemstack1, 4, 31, false)) return null;
        } else if (!mergeItemStack(itemstack1, 4, 40, false)) return null;
      } else {
        if (!mergeItemStack(itemstack1, 4, 40, true)) return null;

        slot.onSlotChange(itemstack1, itemstack);
      }

      if (itemstack1.stackSize == 0) slot.putStack((ItemStack) null);
      else slot.onSlotChanged();

      if (itemstack1.stackSize == itemstack.stackSize) return null;

      slot.onPickupFromSlot(player, itemstack1);
    }

    return itemstack;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
    ItemStack newItemStack = null;
    Slot slot = (Slot) inventorySlots.get(slotIndex);

    if (slot != null && slot.getHasStack()) {
      ItemStack itemStack = slot.getStack();
      newItemStack = itemStack.copy();

      if (slotIndex < chestInventoryRows * chestInventoryColumns) {
        if (!this.mergeItemStack(
            itemStack, chestInventoryRows * chestInventoryColumns, inventorySlots.size(), false)) {
          return null;
        }
      } else if (!this.mergeItemStack(
          itemStack, 0, chestInventoryRows * chestInventoryColumns, false)) {
        return null;
      }

      if (itemStack.stackSize == 0) {
        slot.putStack(null);
      } else {
        slot.onSlotChanged();
      }
    }

    return newItemStack;
  }
 @Override
 public ItemStack transferStackInSlot(EntityPlayer entityplayer, int i) {
   ItemStack itemstack = null;
   Slot slot = (Slot) inventorySlots.get(i);
   if (slot != null && slot.getHasStack()) {
     ItemStack itemstack1 = slot.getStack();
     itemstack = itemstack1.copy();
     if (i == 0) {
       if (!mergeItemStack(itemstack1, 10, 46, true)) {
         return null;
       }
     } else if (i >= 10 && i < 37) {
       if (!mergeItemStack(itemstack1, 37, 46, false)) {
         return null;
       }
     } else if (i >= 37 && i < 46) {
       if (!mergeItemStack(itemstack1, 10, 37, false)) {
         return null;
       }
     } else if (!mergeItemStack(itemstack1, 10, 46, false)) {
       return null;
     }
     if (itemstack1.stackSize == 0) {
       slot.putStack(null);
     } else {
       slot.onSlotChanged();
     }
     if (itemstack1.stackSize != itemstack.stackSize) {
       slot.onPickupFromSlot(entityplayer, itemstack1);
     } else {
       return null;
     }
   }
   return itemstack;
 }
  public ItemStack handle(EntityPlayer player, int mouseButton, Slot slot) {
    if (mouseButton > 0) {
      slot.putStack(null);
    } else if (mouseButton == 0) {
      ItemStack stack;
      InventoryPlayer playerInv = player.inventory;
      slot.onSlotChanged();
      ItemStack stackSlot = slot.getStack();
      ItemStack stackHeld = playerInv.getItemStack();

      if (stackSlot == null && stackHeld != null && slot.slotNumber != 22) {
        if (isItemValid(stackHeld)) {
          ItemStack copy = stackHeld.copy();
          copy.stackSize = 1;
          slot.putStack(copy);
        }
      }

      if (stackHeld == null) {
        if (tile instanceof TileFishSorter) {
          ((TileFishSorter) tile).swapSide(slot.slotNumber);
        }
      }
    }

    return null;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
    ItemStack stack = null;
    Slot slotObject = inventorySlots.get(slot);

    if (slotObject != null && slotObject.getHasStack()) {
      ItemStack stackInSlot = slotObject.getStack();
      stack = stackInSlot.copy();

      if (slot < slotCount) {
        if (!this.mergeItemStack(stackInSlot, slotCount, (slotCount + 36), true)) return null;
      } else {
        boolean b = false;
        for (int i = 0; i < slotCount; i++)
          if (this.getSlot(i).isItemValid(stackInSlot))
            if (this.mergeItemStack(stackInSlot, i, i + 1, false)) {
              b = true;
              break;
            }
        if (!b) 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;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int slotID) {
    ItemStack itemstack = null;
    Slot slot = this.inventorySlots.get(slotID);

    if (slot != null && slot.getHasStack()) {
      ItemStack itemstack1 = slot.getStack();
      itemstack = itemstack1.copy();

      if (slotID == 2) {
        if (!this.mergeItemStack(itemstack1, 3, 39, true)) return null;

        slot.onSlotChange(itemstack1, itemstack);
      } else if (slotID != 1 && slotID != 0) {
        if (TileScribe.isValidForScribe(itemstack1)) {
          if (!this.mergeItemStack(itemstack1, 0, 1, false)) return null;
        } else if (TileScribe.isBook(itemstack1)) {
          if (!this.mergeItemStack(itemstack1, 1, 2, false)) return null;
        } else if (slotID >= 3 && slotID < 30) {
          if (!this.mergeItemStack(itemstack1, 30, 39, false)) return null;
        } else if (slotID >= 30 && slotID < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
          return null;
      } else if (!this.mergeItemStack(itemstack1, 3, 39, false)) return null;

      if (itemstack1.stackSize == 0) slot.putStack((ItemStack) null);
      else slot.onSlotChanged();

      if (itemstack1.stackSize == itemstack.stackSize) return null;

      slot.onPickupFromSlot(player, itemstack1);
    }

    return itemstack;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
    ItemStack var3 = null;
    final Slot var4 = (Slot) this.inventorySlots.get(par2);

    if (var4 != null && var4.getHasStack()) {
      final ItemStack var5 = var4.getStack();
      var3 = var5.copy();

      if (par2 < 27) {
        if (!this.mergeItemStack(var5, 27, this.inventorySlots.size(), true)) {
          return null;
        }
      } else if (!this.mergeItemStack(var5, 0, 27, false)) {
        return null;
      }

      if (var5.stackSize == 0) {
        var4.putStack((ItemStack) null);
      } else {
        var4.onSlotChanged();
      }
    }

    return var3;
  }
  public ItemStack transferStackInSlot(EntityPlayer player, int slotID) {
    ItemStack stack = null;
    Slot slot = (Slot) this.inventorySlots.get(slotID);

    if (slot != null && slot.getHasStack()) {
      ItemStack slotStack = slot.getStack();
      stack = slotStack.copy();

      if (slotID < logic.getSizeInventory()) {
        if (!this.mergeItemStack(
            slotStack, logic.getSizeInventory(), this.inventorySlots.size(), true)) {
          return null;
        }
      } else if (!this.mergeItemStack(slotStack, 0, logic.getSizeInventory(), false)) {
        return null;
      }

      if (slotStack.stackSize == 0) {
        slot.putStack((ItemStack) null);
      } else {
        slot.onSlotChanged();
      }
    }

    return stack;
  }
  /** Called to transfer a stack from one inventory to the other eg. when shift clicking. */
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int i) {
    ItemStack itemstack = null;
    Slot slot = (Slot) inventorySlots.get(i);

    if (slot != null && slot.getHasStack()) {
      ItemStack itemstack1 = slot.getStack();
      itemstack = itemstack1.copy();

      if (i < 3 * 5) {
        if (!mergeItemStack(itemstack1, 3 * 5, inventorySlots.size(), true)) {
          return null;
        }
      } else if (!mergeItemStack(itemstack1, 0, 3 * 5, false)) {
        return null;
      }

      if (itemstack1.stackSize == 0) {
        slot.putStack(null);
      } else {
        slot.onSlotChanged();
      }
    }

    return itemstack;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int index) {
    Slot slot = getSlot(index);
    if (!this.getSlot(currentSlot).getHasStack()) return null;

    if (slot != null && slot.getHasStack()) {
      ItemStack stack = slot.getStack();
      ItemStack result = stack.copy();
      if (index >= 9) { // To player
        if (!mergeItemStack(stack, 0, 9, false)) {
          return null;
        }
      } else {
        return null;
      }

      if (stack.stackSize == 0) {
        slot.putStack(null);
      } else {
        slot.onSlotChanged();
      }

      slot.onPickupFromSlot(player, stack);

      return result;
    }

    return null;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int slotID) {
    ItemStack stack = null;
    Slot currentSlot = (Slot) inventorySlots.get(slotID);

    if (currentSlot != null && currentSlot.getHasStack()) {
      ItemStack slotStack = currentSlot.getStack();
      stack = slotStack.copy();

      if (slotID < 27) {
        if (!mergeItemStack(slotStack, 27, inventorySlots.size(), true)) {
          return null;
        }
      } else if (!mergeItemStack(slotStack, 0, 27, false)) {
        return null;
      }

      if (slotStack.stackSize == 0) {
        currentSlot.putStack((ItemStack) null);
      } else {
        currentSlot.onSlotChanged();
      }

      if (slotStack.stackSize == stack.stackSize) {
        return null;
      }

      currentSlot.onPickupFromSlot(player, slotStack);
    }

    return stack;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int par2) {

    ItemStack itemstack = null;
    Slot slot = (Slot) inventorySlots.get(par2);
    if (slot != null && slot.getHasStack()) {
      ItemStack itemstack1 = slot.getStack();
      itemstack = itemstack1.copy();
      if (par2 >= 9 && par2 < 18) {
        if (!mergeItemStack(itemstack1, 27, 63, true)) return null;
      } else if (par2 >= 27 && !mergeItemStack(itemstack1, 9, 18, false)) {
        return null;
      }
      if (itemstack1.stackSize == 0) {
        slot.putStack(null);
      } else {
        slot.onSlotChanged();
      }
      if (itemstack1.stackSize != itemstack.stackSize) {
        slot.onPickupFromSlot(player, itemstack1);
      } else {
        return null;
      }
    }
    return itemstack;
  }
  /**
   * Called when a player shift-clicks on a slot. You must override this or you will crash when
   * someone does that.
   */
  public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
    ItemStack itemstack = null;
    Slot slot = (Slot) this.inventorySlots.get(par2);

    if (slot != null && slot.getHasStack()) {
      ItemStack itemstack1 = slot.getStack();
      itemstack = itemstack1.copy();

      if (par2 < this.numRows * 9) {
        if (!this.mergeItemStack(itemstack1, this.numRows * 9, this.inventorySlots.size(), true)) {
          return null;
        }
      } else if (!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false)) {
        return null;
      }

      if (itemstack1.stackSize == 0) {
        slot.putStack((ItemStack) null);
      } else {
        slot.onSlotChanged();
      }
    }

    return itemstack;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int clickedIndex) {
    ItemStack returnedStack = null;
    Slot clickedSlot = (Slot) this.inventorySlots.get(clickedIndex);

    if (clickedSlot != null
        && clickedSlot.getHasStack()
        && (clickedSlot.getStack().getItem() instanceof IFood
            || clickedSlot.getStack().itemID == Item.bowlEmpty.itemID)) {
      ItemStack clickedStack = clickedSlot.getStack();
      returnedStack = clickedStack.copy();

      if (clickedIndex < 6) {
        if (!this.mergeItemStack(clickedStack, 6, inventorySlots.size(), true)) return null;
      } else if (clickedIndex >= 6 && clickedIndex < inventorySlots.size()) {
        if (!this.mergeItemStack(clickedStack, 0, 6, false)) return null;
      } else if (!this.mergeItemStack(clickedStack, 6, inventorySlots.size(), false)) return null;

      if (clickedStack.stackSize == 0) clickedSlot.putStack((ItemStack) null);
      else clickedSlot.onSlotChanged();

      if (clickedStack.stackSize == returnedStack.stackSize) return null;
      clickedSlot.onPickupFromSlot(player, clickedStack);
    }
    return returnedStack;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int id) {
    ItemStack stack = null;
    Slot slot = (Slot) this.inventorySlots.get(id);

    if (slot != null && slot.getHasStack()) {
      ItemStack stack1 = slot.getStack();
      stack = stack1.copy();

      ItemMatterUnit unit = ModuleCrafting.matterUnit;

      if (id < 4) { // tileInv->playerInv
        if (!this.mergeItemStack(stack1, 4, this.inventorySlots.size(), true)) return null;
      } else {
        // playerInv->tileInv
        if (unit.getMaterial(stack) == ModuleCrafting.imagPhase.mat) {
          if (!this.mergeItemStack(stack1, 2, 3, false)) return null;
        } else if (IFItemManager.instance.isSupported(stack)) {
          if (!this.mergeItemStack(stack1, 3, 4, false)) return null;
        } else {
          if (!this.mergeItemStack(stack1, 0, 1, false)) return null;
        }
      }

      if (stack1.stackSize == 0) {
        slot.putStack((ItemStack) null);
      } else {
        slot.onSlotChanged();
      }
    }

    return stack;
  }
 @Override
 public void onSlotChanged() {
   if (container.needCraftingUpdate) {
     container.updateCrafting();
   }
   super.onSlotChanged();
 }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
    if (slotIndex == 0) {
      return null;
    }

    Slot slot = this.getSlot(slotIndex);

    if (slot == null || !slot.getHasStack()) {
      return null;
    }

    ItemStack stack = slot.getStack();
    ItemStack newStack = stack.copy();

    if (slotIndex <= 91) {
      if (!this.mergeItemStack(stack, 92, 127, false)) {
        return null;
      }
    } else if (!EMCHelper.doesItemHaveEmc(stack) || !this.mergeItemStack(stack, 1, 91, false)) {
      return null;
    }

    if (stack.stackSize == 0) {
      slot.putStack(null);
    } else slot.onSlotChanged();
    slot.onPickupFromSlot(player, stack);
    return newStack;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int slot_index) {
    ItemStack stack = null;
    Slot slot_object = (Slot) inventorySlots.get(slot_index);

    if (slot_object != null && slot_object.getHasStack()) {
      ItemStack stack_in_slot = slot_object.getStack();
      stack = stack_in_slot.copy();

      if (slot_index == 0) {
        if (!mergeItemStack(stack_in_slot, 1, inventorySlots.size(), true)) {
          return null;
        }
      } else if (!mergeItemStack(stack_in_slot, 0, 1, false)) {
        return null;
      }

      if (stack_in_slot.stackSize == 0) {
        slot_object.putStack(null);
      } else {
        slot_object.onSlotChanged();
      }
    }

    return stack;
  }
 public ItemStack getStackInSlot(int i) {
   ItemStack itemstack = null;
   Slot slot = (Slot) this.inventorySlots.get(i);
   if (slot != null && slot.getHasStack()) {
     ItemStack itemstack1 = slot.getStack();
     itemstack = itemstack1.copy();
     if (i == 0) {
       this.mergeItemStack(itemstack1, 9, 45, true);
     } else if (i >= 9 && i < 36) {
       this.mergeItemStack(itemstack1, 36, 45, false);
     } else if (i >= 36 && i < 45) {
       this.mergeItemStack(itemstack1, 9, 36, false);
     } else {
       this.mergeItemStack(itemstack1, 9, 45, false);
     }
     if (itemstack1.stackSize == 0) {
       slot.putStack(null);
     } else {
       slot.onSlotChanged();
     }
     if (itemstack1.stackSize != itemstack.stackSize) {
       slot.onPickupFromSlot(
           null, // Entityplayer
           itemstack1);
     } else {
       return null;
     }
   }
   return itemstack;
 }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
    ItemStack var3 = null;
    Slot var4 = (Slot) this.inventorySlots.get(par2);

    if (var4 != null && var4.getHasStack()) {
      ItemStack var5 = var4.getStack();
      var3 = var5.copy();

      if (par2 == 2) {
        if (!this.mergeItemStack(var5, 3, 39, true)) return null;

        var4.onSlotChange(var5, var3);
      } else if (par2 != 0 && par2 != 1) {
        if (par2 >= 3 && par2 < 30) {
          if (!this.mergeItemStack(var5, 30, 39, false)) return null;
        } else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(var5, 3, 30, false)) return null;
      } else if (!this.mergeItemStack(var5, 3, 39, false)) return null;

      if (var5.stackSize == 0) {
        var4.putStack((ItemStack) null);
      } else {
        var4.onSlotChanged();
      }

      if (var5.stackSize == var3.stackSize) return null;

      var4.onPickupFromSlot(par1EntityPlayer, var5);
    }

    return var3;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int slotID) {
    ItemStack stack = null;
    Slot slot = (Slot) inventorySlots.get(slotID);

    // null checks and checks if the item can be stacked (maxStackSize > 1)
    if (slot != null && slot.getHasStack()) {
      ItemStack stackInSlot = slot.getStack();
      stack = stackInSlot.copy();

      // merges the item into player inventory since its in the tileEntity
      if (slotID < tileEntity.getSizeInventory()) {
        if (!this.mergeItemStack(
            stackInSlot, tileEntity.getSizeInventory(), this.inventorySlots.size(), true)) {
          return null;
        }
      }
      // merge into tileEntity inventory, since it is in player's inventory
      else if (!this.mergeItemStack(stackInSlot, 0, tileEntity.getSizeInventory(), false)) {
        return null;
      }

      if (stackInSlot.stackSize == 0) {
        slot.putStack(null);
      } else {
        slot.onSlotChanged();
      }
    }
    return stack;
  }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotNum) {
    ItemStack itemCopy = null;
    Slot slot = (Slot) this.inventorySlots.get(slotNum);

    if (slot != null && slot.getHasStack()) {
      ItemStack item = slot.getStack();
      itemCopy = item.copy();

      if (slotNum < 9) {
        if (!this.mergeItemStack(item, 9, this.inventorySlots.size(), true)) {
          return null;
        }
      } else if (!this.mergeItemStack(item, 0, 9, false)) {
        return null;
      }

      if (item.stackSize == 0) {
        slot.putStack((ItemStack) null);
      } else {
        slot.onSlotChanged();
      }
    }

    return itemCopy;
  }
 private ItemStack slotClickPhantom(
     Slot slot, int mouseButton, int modifier, EntityPlayer player) {
   ItemStack stack = null;
   if (mouseButton == 2) {
     if (((IPhantomSlot) slot).canAdjust()) slot.putStack(null);
   } else if (mouseButton == 0 || mouseButton == 1) {
     InventoryPlayer playerInv = player.inventory;
     slot.onSlotChanged();
     ItemStack stackSlot = slot.getStack();
     ItemStack stackHeld = playerInv.getItemStack();
     if (stackSlot != null) stack = stackSlot.copy();
     if (stackSlot == null) {
       if (stackHeld != null && slot.isItemValid(stackHeld))
         fillPhantomSlot(slot, stackHeld, mouseButton);
     } else if (stackHeld == null) {
       adjustPhantomSlot(slot, mouseButton, modifier);
       slot.onPickupFromSlot(player, playerInv.getItemStack());
     } else if (slot.isItemValid(stackHeld)) {
       if (ItemUtil.canStacksMerge(stackSlot, stackHeld))
         adjustPhantomSlot(slot, mouseButton, modifier);
       else fillPhantomSlot(slot, stackHeld, mouseButton);
     }
   }
   return stack;
 }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slot) {
    Slot slotObject = (Slot) inventorySlots.get(slot);
    if (slotObject != null && slotObject.getHasStack()) {
      ItemStack stackInSlot = slotObject.getStack();
      ItemStack stack = stackInSlot.copy();
      if (slot >= 0 && slot < kDecomposerInventoryEnd) {
        if (!mergeItemStack(stackInSlot, kPlayerInventorySlotStart, inventorySlots.size(), true))
          return null;
      } else if (stackInSlot.itemID == MinechemItems.testTube.itemID) {
        if (!mergeItemStack(
            stackInSlot,
            decomposer.kEmptyTestTubeSlotStart,
            decomposer.kEmptyTestTubeSlotEnd + 1,
            false)) return null;
      } else if (slot >= kPlayerInventorySlotStart) {
        if (!mergeItemStack(stackInSlot, decomposer.kInputSlot, decomposer.kInputSlot + 1, false))
          return null;
      } else if (!mergeItemStack(
          stackInSlot, kPlayerInventorySlotStart, inventorySlots.size(), true)) return null;

      if (stackInSlot.stackSize == 0) slotObject.putStack(null);
      else slotObject.onSlotChanged();

      return stack;
    }
    return null;
  }
 @Override
 public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
   ItemStack result = null;
   Slot slot = getSlot(slotIndex);
   if (slot != null && slot.getHasStack()) {
     ItemStack stack = slot.getStack();
     result = stack.copy();
     if (slotIndex == 1) {
       if (!mergeItemStack(stack, 2, 38, true)) return null;
       slot.onSlotChange(stack, result);
     } else if (slotIndex != 0) {
       if (FurnaceRecipes.smelting().getSmeltingResult(stack) != null) {
         if (!this.mergeItemStack(stack, 0, 1, false)) return null;
       } else if (slotIndex >= 2 && slotIndex < 29) {
         if (!this.mergeItemStack(stack, 29, 38, false)) return null;
       } else if (slotIndex >= 29 && slotIndex < 38) {
         if (!this.mergeItemStack(stack, 2, 29, false)) return null;
       }
     } else if (!this.mergeItemStack(stack, 2, 38, false)) return null;
     if (stack.stackSize <= 0) slot.putStack(null);
     else slot.onSlotChanged();
     if (stack.stackSize == result.stackSize) return null;
     slot.onPickupFromSlot(player, stack);
   }
   return result;
 }
  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
    ItemStack stack = null;
    Slot slotObject = (Slot) inventorySlots.get(slot);
    int machInvSize = _ncw.getSizeInventory();

    if (slotObject != null && slotObject.getHasStack()) {
      ItemStack stackInSlot = slotObject.getStack();
      stack = stackInSlot.copy();

      if (slot < machInvSize) {
        if (!mergeItemStack(stackInSlot, machInvSize, inventorySlots.size(), true)) {
          return null;
        }
      } else if (!mergeItemStack(stackInSlot, 0, machInvSize, 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;
  }
 @Override
 public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
   ItemStack stack = null;
   Slot slot = (Slot) inventorySlots.get(slotNumber);
   if (slot != null && slot.getHasStack()) {
     ItemStack slotClicked = slot.getStack();
     stack = slotClicked.copy();
     if (slotNumber <= 36) {
       if (slotNumber == 0 && stack != null && stack.stackSize > 0) {
         tile.decrementCraftingField();
       }
       if (!mergeItemStack(slotClicked, 37, inventorySlots.size(), true)) {
         return null;
       }
     } else {
       stack = null;
     }
     if (slotClicked.stackSize == 0) {
       slot.putStack(null);
     } else {
       slot.onSlotChanged();
     }
   }
   return stack;
 }