AE x Backpack food duplication
Takinatar opened this issue ยท 2 comments
Describe the bug
Having a food item in both AE System and in your backpack, with an Autofeed upgrade while having the "Restock" option on, in the wireless remote from applied, will cause the food to be duplicated on both sides when autofeed happen.
To Reproduce
Steps to reproduce the behavior:
- Put the food of your choice in AE storage and equip a wireless remote.
- Put the same food in your backpack and equip a feeding upgrade.
- Enable "Restock" in wireless remote and trigger the auto feed.
- The food in both the AE System and in your backpack should have been duplicated.
Expected behavior
When you get fed by the autofeed, it should be duplicated in your backpack and in your AE storage?
Versions
sophisticatedstorage-1.21-0.10.40.886
Extra
This bug also have been reported on AE's repo as suggested by a user, as it is unclear "Who's fault it is".
AppliedEnergistics/Applied-Energistics-2#8211
after stepping through this with a debugger, I believe this is Sophisticated Backpacks fault.
conceptually, ae2wtlibs restock tries to keep the stack in the hand at half its maximum stack size, by either adding or removing items from it.
It does that by listening to LivingEntityUseItemEvent.Finish
, and modifying the resultStack to have the desired count.
you call EventHooks.onItemUseFinish
, however you add the result to the backpack, instead of setting the stack to the result.
https://github.com/P3pp3rF1y/SophisticatedCore/blob/d9965f2af58afa21d3dbbf1de7a38a23f6deef68/src/main/java/net/p3pp3rf1y/sophisticatedcore/upgrades/feeding/FeedingUpgradeWrapper.java#L84-L89
while the EventHooks
method doesn't have javadoc, it calls LivingEntityUseItemEvent.Finish
and returns that events resultStack, which, according to the javadoc of LivingEntityUseItemEvent.Finish
is "The result item stack is the stack that is placed in the player's inventory in replacement of the stack that is currently being used." (https://github.com/neoforged/NeoForge/blob/62eb61a8e0c726faa30eaa3f4998ba1101368ee4/src/main/java/net/neoforged/neoforge/event/entity/living/LivingEntityUseItemEvent.java#L90)
I had a plan to change how feeding works for better support of food containers and putting them back into the backpacks - I changed the logic to only put stack of count 1 in player's hand when eating and the event above now really only receives either empty stack if the food doesn't have any container or the container that should be returned. So the issue described here is fixed in the latest release.