Storage Drawers: Forestry Pack

Storage Drawers: Forestry Pack

6M Downloads

When simulating inserting items, the remaining space is counted twice

lcy0x1 opened this issue ยท 0 comments

commented

When I call ItemHandlerHelper.insertItemStacked(handler, stack, true); with a stack of 35 into a drawer with 10 remaining space, this function is expected to return a stack of 25 for items that cannot be inserted. However, it's actually returing a stack of 15, because the space is double counted.

This is because ItemHandlerHelper.insertItemStacked will iterate through all the slots in the target ItemHandler, it will be attempted to insert into both the virtual slot and the non-virtual slot.

The consequence is that:
When I try to transfer items, I would first call src.extractItem(index, max, true) to see the amount I can extract from source. Then I would call ItemHandlerHelper.insertItemStacked(dst, stack, true); to see the amount I can insert into destination. Then I would call src.extractItem(index, amount, false) to actually extract the item, and ItemHandlerHelper.insertItemStacked(dst, stack, false); to actually insert the item. In this process, the simulated amount would be different from the actual amount, causing a mismatch. For source block that only allow extraction, I can't put the leftover items back in, and thus having a loss of items.