Hopper don't transfer if full and wrong destination for TransferInventoryEvent.Pre #3886
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Versions
SpongeAPI: 10.0.0-SNAPSHOT
Sponge: 1.19.4-10.0.0-SNAPSHOT
SpongeVanilla: 1.19.4-10.0.0-RC0
The bug
A hopper didn't transfer its items if its 5 slots were filled with a full stack of items (example: 64 oak woods per slot).
Furthermore, the event TransferInventoryEvent.Pre had the same source and destination inventory.
This bug was reported by the issue #3883.
Description
Before transferring its items to the container in its direction, it checks that the container is not full. The check method
HopperBlockEntity#isFullContainer
was redirected to the mixin methodHopperBlockEntityMixin_Inventory#impl$throwTransferPreIfNotFull
to capture the transfer and create aTransferInventoryEvent.Pre
event. The problem was that the check performed byHopperBlockEntityAccessor.invoker$isFullContainer
was called with the hopper container and not the 'attached container' (the container in the hopper direction, such as a chest). In addition, the event TransferInventoryEvent.Pre was created with the same source and destination container (the hopper).The fix
HopperBlockEntityMixin_Inventory#impl$throwTransferPreIfNotFull
had two containers as arguments: the attached container and the hopper container. I just replaced the container argument ofHopperBlockEntityAccessor.invoker$isFullContainer
with the attached container. Its name was var0 but I renamed it to 'attachedContainer' like the methodHopperBlockEntity#getAttachedContainer
.For the event, I just replaced the destination container with the attached container.