Fix incorrect InventoryClickEvent slots when clicking your own inventory during invsee#14060
Open
gunjanjaswal wants to merge 1 commit into
Open
Conversation
Opening another player's inventory renders their inventory as a generic 9x4 chest (36 slots), but a player inventory reports a size of 41 since it also counts the armour and off-hand slots. The view's slot math used that reported size, so clicks in the bottom (viewer's own) inventory were mapped five slots off, making InventoryClickEvent report an unrelated slot and item. Route the top-slot count through an overridable helper and, for a player inventory shown in a container, use the number of slots actually laid out so the raw-to-inventory slot mapping lines up again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #11245
When you open another player's inventory (invsee-style, via
player.openInventory(target.getInventory())) and then click an item in your own inventory at the bottom,InventoryClickEventreports a completely unrelated slot and item. It has been broken since around 1.14.The top inventory in that case is drawn as a generic 9x4 chest, so it only shows 36 slots. A player inventory, though, reports a size of 41 because it also counts the four armour slots and the off-hand. The slot conversion in
CraftAbstractInventoryViewkeyed off that reported size, so every raw slot in the bottom inventory ended up five out. The first few slots of your own inventory were even treated as part of the top.This adds a small
getTopSlots()hook (it defaults to the current behaviour, so nothing else changes) and, for a player inventory opened in a container, returns the slot count that is actually laid out. With that,convertSlot,getSlotType, andcountSlotsline up with the real container again.I worked the mapping through by hand (raw slot 36 maps to main inventory slot 9, raw 71 to hotbar 8, and so on) and it checks out, but I have not been able to run it against a live server build yet, so a second look there would be welcome.