Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hopper don't transfer if full and wrong destination for TransferInventoryEvent.Pre #3886

Merged

Conversation

AlexandreArcil
Copy link
Contributor

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 method HopperBlockEntityMixin_Inventory#impl$throwTransferPreIfNotFull to capture the transfer and create a TransferInventoryEvent.Pre event. The problem was that the check performed by HopperBlockEntityAccessor.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 of HopperBlockEntityAccessor.invoker$isFullContainer with the attached container. Its name was var0 but I renamed it to 'attachedContainer' like the method HopperBlockEntity#getAttachedContainer.

For the event, I just replaced the destination container with the attached container.

@Faithcaio Faithcaio merged commit e09c0e0 into SpongePowered:api-10 Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants