private int getItemStackIndexBackwards(Item item) {
        int ID = item.getID();
        ItemStack stack;

        for (int i = items.size() - 1; i >= 0; i--) {
            stack = items.get(i);
            if (stack.getItemInStackID() == ID && stack.getAmount() <= stack.getMaxStackSize())
                return i;
        }
        stack = new ItemStack(item);
        items.add(stack);
        return items.size() - 1;
    }