Skip to content

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

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

gunjanjaswal wants to merge 2 commits 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
@gunjanjaswal

Copy link
Copy Markdown
Contributor Author

Small nudge on this. It corrects the InventoryClickEvent slot values for the reported case and carries a test; still mergeable against current. If it's fallen behind I can rebase. Just flagging it's ready for a review pass when someone has time.

@gunjanjaswal

Copy link
Copy Markdown
Contributor Author

Closing this one out — it's sat a while without a review, so cleaning up rather than leaving it stale. The fix still holds if there's interest later (correcting the InventoryClickEvent raw/converted slots when clicking your own inventory while viewing another), and I'm glad to reopen or freshen it up. Thanks!

@gunjanjaswal
gunjanjaswal deleted the fix/11245-invsee-bottom-inventory-slots branch October 1, 2026 12:36
@YnsanitY16

Copy link
Copy Markdown

Just rebase it for main if needed and when the team will have time, they will review it.

@gunjanjaswal
gunjanjaswal restored the fix/11245-invsee-bottom-inventory-slots branch October 1, 2026 15:59
@gunjanjaswal gunjanjaswal reopened this Oct 1, 2026
@gunjanjaswal

Copy link
Copy Markdown
Contributor Author

Good call, @YnsanitY16 — reopened, and thanks for the nudge. You're right that it's worth keeping around; the fix still applies cleanly. Bringing the branch up to date with main now so it's fresh for whenever the team has a window.

@gunjanjaswal

Copy link
Copy Markdown
Contributor Author

Gentle nudge on this one, @YnsanitY16. It's been a few weeks since the reopen and rebase — branch is still current with main, CI's green, and the slot-mapping fix applies cleanly. Whenever someone has a moment for a review pass, I'm around to address anything that comes up.

@gunjanjaswal

Copy link
Copy Markdown
Contributor Author

Following up again — it's been about a month since the last bump and this is still waiting for a review slot. It's a contained fix for the InventoryClickEvent slot indices being reported wrong for the affected menu type. No urgency, just keeping it on the radar whenever someone has the time.

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

2 participants