Implement variable sized item recipe transfer handler #3872
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.
This PR makes it possible to properly implement item transfer handler for recipes that have inputs with variable item stack size inputs.
For this I added a default method to IRecipeTransferHandler, where a user can return item stack sizes for transferred items.
This method is then passed to BasicRecipeTransferHandlerServer through PacketRecipeTransfer. If the list is empty, transfer behaves as before, otherwise stack sizes are given to net.minecraft.world.inventory.Slot#safeTake, which handles item extraction.
Also I had to replace 3 hash maps with linked hash maps to preserve stack size to slot mapping.
I exposed IRecipeTransferHandlerHelper in the transfer handler registration method to allow getting IStackHelper for use in transfer handler instantiation.
I tested these changes in my mod I'm developing. I have custom recipe type that can have input items with variable size, so I decided to make this PR.