Reliquary Reincarnations

Reliquary Reincarnations

51M Downloads

FilteredItemStackHandler causes IndexOutOfBoundsException

Theta-Dev opened this issue ยท 0 comments

commented

A user of my mod (ConstructionWand) reported that my wand's automatic item extraction from containers causes an IndexOutOfBoundsException with the Harvest Rod (and possibly other Reliquary items).

Theta-Dev/ConstructionWand#64

Upon closer inspection, it looks like the harvest rod implements a dynamically sized container which always returns one stack more than what is actually stored (an empty harvest rod reports back 2 slots via getSlots() for example).
When these slots are queried using getStackInSlot(i), the last one does not point to an actual stack and causes a OutOfBounds exception.

This is the code in question:

public ItemStack getStackInSlot(int slot) {
validateSlotIndex(slot);
return filteredItemStacks.get(slot).getStack();
}

Interestingly, the older version of this mod does check if the queried index points to the dynamic slot and returns an empty stack in this case.

public ItemStack getStackInSlot(int slot) {
validateSlotIndex(slot);
int bigStackSlot = getBigStackSlot(slot);
if (bigStackSlot < filteredBigItemStacks.size()) {
FilteredBigItemStack bigStack = filteredBigItemStacks.get(0).getStack();
return isInputSlot(slot) ? bigStack.getInputStack() : bigStack.getOutputStack();
} else {
return ItemStack.EMPTY;
}
}

So I would suggest replacing the function with the 1.16 implementation, that should fix the issue.