public ItemStack getItems(Inventory inv, ItemStack itemStack) {
        ItemStack itemStackC;
        int amount = itemStack.getAmount();
        for (int x = 0; x < inv.getSize(); x++) {
            if (amount == 0) {
                break;
            }
            itemStackC = inv.getItem(x);
            if (itemStackC == null) {
                continue;
            }
            if ((itemStackC.getTypeId() == itemStack.getTypeId() && itemStackC.getDurability() == itemStack.getDurability()) || (itemStackC.getTypeId() == itemStack.getTypeId())) {
                if (itemStackC.getAmount() <= amount) {
                    amount -= itemStackC.getAmount();
                    inv.setItem(x, null);
                } else {
                    ItemStack clone = itemStackC.clone();
                    clone.setAmount(amount);
                    itemStackC.setAmount(itemStackC.getAmount() - amount);
                    amount = 0;
                }
                if (amount == 0) {
                    break;
                }
            }
        }

        itemStack.setAmount(itemStack.getAmount() - amount);

        return itemStack;
    }