Skip to content

Fix incorrect InventoryClickEvent slots when clicking your own inventory during invsee#14060

Open
gunjanjaswal wants to merge 1 commit into
PaperMC:mainfrom
gunjanjaswal:fix/11245-invsee-bottom-inventory-slots
Open

Fix incorrect InventoryClickEvent slots when clicking your own inventory during invsee#14060
gunjanjaswal wants to merge 1 commit into
PaperMC:mainfrom
gunjanjaswal:fix/11245-invsee-bottom-inventory-slots

Conversation

@gunjanjaswal

Copy link
Copy Markdown
Contributor

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, InventoryClickEvent reports 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 CraftAbstractInventoryView keyed 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, and countSlots line 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.

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.
@gunjanjaswal gunjanjaswal requested a review from a team as a code owner July 13, 2026 02:06
@github-project-automation github-project-automation Bot moved this to Awaiting review in Paper PR Queue Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

Clicking bottom inventory items while another player's inventory is opened up at the top fires InventoryClickEvent with incorrect items and slots

1 participant