@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;
  }
  public ContainerBag(BagContainerWrapper ncw, InventoryPlayer inv) {
    _ncw = ncw;
    _nsi = inv.currentItem;

    for (int i = 0; i < _ncw.getSizeInventory(); ++i)
      this.addSlotToContainer(new SlotAcceptValid(_ncw, i, 44 + i * 18, 20));

    bindPlayerInventory(inv);
  }