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

Fix #122 by simulating inventory transactions before execution. #127

Open
wants to merge 2 commits into
base: mc-1.19.x/stable
Choose a base branch
from

Conversation

toad-dev
Copy link
Member

@toad-dev toad-dev commented Sep 5, 2022

The problem was that we were extracting up to the limit before we knew how many items the destination inventory could actually accept, and then we would fail to replace the remaining items back into the furnace output slot since it's protected from insertions. My fix is to simulate the transaction first, see how many items were successfully transferred, and only then mutate the inventories by that amount.

I would appreciate any reviews or testing on this because I feel like there are probably edge cases I haven't considered and I don't have a good world to test this on. I added some error logging in case it detects that items were lost.

There was also a similar issue with the turtle suck command that I applied the same sort of fix to, along with the error logging.

This was happening because the output slot of a furnace is protected
from all insertions. We were greedily extracting items at the beginning
of the transfer and couldn't place the remainder back into the protected
slot. Instead, simulate the transaction first, count how many items
successfully transfer, then actually mutate the inventories by that
amount. The ItemStorage wrappers already supported simulating
transactions, so I just exposed the option in InventoryUtil.

Also, because it's likely there's still some edge cases where things
will go wrong (especially in the presence of modded blocks), I added
some detailed logging in the case that we detect that items have been
lost.

Fixes cc-tweaked#122
This fixes a similar issue to the previous commit. It was possible for a
TurtleSuckCommand to lose the remainder or put it back in a different
slot from where it came.
@Merith-TK
Copy link
Collaborator

is this mergable or is it stale?

@Merith-TK
Copy link
Collaborator

I... swear this was fixed?? is this still a problem??

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