IllegalArgumentException: Bound must be positive

The issue is that you are calling Random.nextInt() with a zero and it doesn’t like that. That is happening because the List from getAllItems() is empty. I would prevent this situation by checking that the list has items before performing your logic:

List<ItemStack> items = getAllItems(level);
if(!items.isEmpty()) {
    inv.setItem(i, items.get(r.nextInt(items.size())));
}

Leave a Comment