P3pp3rF1y / Reliquary

The source code of Reliquary! That mod, with the magical swag, and a weapon, and stuff.
Other
42 stars 29 forks source link

FilteredItemStackHandler causes IndexOutOfBoundsException #619

Closed Theta-Dev closed 11 months ago

Theta-Dev commented 1 year ago

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).

https://github.com/Theta-Dev/ConstructionWand/issues/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: https://github.com/P3pp3rF1y/Reliquary/blob/80984f60ae16eceb15d3ecbb6ee67f168551ea1f/src/main/java/reliquary/items/util/FilteredItemStackHandler.java#L122-L125

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. https://github.com/P3pp3rF1y/Reliquary/blob/8020e80f94e24a5afc5ae670c90ccd9d0c2b4615/src/main/java/xreliquary/items/util/FilteredItemStackHandler.java#L150-L159

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