Fix crafter slot ID conversions #13497
Open
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.
Fixes #12864
The networked raw slot IDs for crafter inventory views are mapped a bit differently compared to any other inventory views. This is how raw slots are laid out in crafting tables compared to crafters:
Paper currently handles the conversion from raw IDs to slot IDs incorrectly for crafters, as described in #12864. There is no handling for
InventoryType.CRAFTERin the logic for converting raw slot IDs. The result is that these calls return incorrectly when a player clicks while viewing a crafter:InventoryClickEvent#getSlot()InventoryClickEvent#getClickedInventory()InventoryClickEvent#getSlotType()I generated a table outlining all of these return values before and after this patch at this gist.
A note on my selection of converted slot IDs: the crafter's use of resolved slot IDs 0-8 in the grid and 9 for the result are inconsistent with workbenches and inventory crafting, which use slot 0 for the result and 1-9/1-4 in the grid. Unfortunately, 0-8 and 9 match the vanilla assignment of crafter slot IDs, and therefore the ID mapping used in
Inventory#setItem(int, ItemStack)and commands like/execute if items block ~ ~1 ~ container.0. An alternative mapping here could make crafters and workbenches number slots consistently, but it would make other behavior inconsistent.