public void removeItem(Item item, int amount) {
        if (amount <= 0 || item.getMaxStackSize() == 0) return;
        int totalAmount = getItemAmount(item);
        int amt = (amount <= totalAmount ? amount : totalAmount);

        int stackIndex;
        while (amt > 0) {
            stackIndex = getItemStackIndexBackwards(item);
            ItemStack stack = items.get(stackIndex);
            int removeAmt = amt;

            if (removeAmt > stack.getAmount()) {
                removeAmt = stack.getAmount();
            }
            amt -= removeAmt;

            stack.removeItem(removeAmt);
            if (stack.getAmount() <= 0) {
                removeItemStack(stackIndex);
                amt = 0;
            }
        }
    }