Fix locking storage and conversion monitors #8272
Merged
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.
Fix #8179
The bug was probably introduced during the rewrite in 70838d7
I'm still a bit confused how
onUseItemOn
andonUseWithoutItem
should interact. My findings were thatonUseItemOn
is always called first (even with an empty hand) and only if the event was not consumed (by returning true)onUseWithoutItem
would be called. My intuition looking at those function names would have been thatonUseItemOn
would never be called with an empty hand in the first place.The problem was, that the event that would potentially lead to the code for locking and unlocking in the
onUseWithoutItem
function was consumed earlier by theonUseItemOn
function. I chose to check for the!InteractionUtil.isInAlternateUseMode(player)
condition to bypass those event consumptions.Another functionality that was broken due to a similar problem, that could only be observed after fixing the locking, was the insert all items behavior when right-clicking empty-handedly. This was fixed by the additional check for
else if (!heldItem.isEmpty())
and moving the return into that block so that the empty-handed case would not return true and continue to run into theonUseWithoutItem
code.Another point for the review: I changed the
return super.onUseWithoutItem(player, pos);
inonUseWithoutItem
inAbstractMonitorPart
toreturn super.onUseItemOn(heldItem, player, hand, pos);
because it looked like a copy&paste error during the rewrite. If that served a specific purpose feel free to restore it, the fix should work without it.