[SPIGOT-3272] InventoryClickEvent Hotbar's slot aren't in range Created: 25/May/17 Updated: 28/May/17 Resolved: 28/May/17 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Minor |
Reporter: | Rossi Lorenzo | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 0 |
Labels: | bug, entity | ||
Environment: |
Latest spigot version (spigot-1.11.2) And latest craftbukkit (1.11.2) (cannot check with vanilla) All got with BuilTools --rev latest Manjaro + KDE (x64) Only one mod (to find the slot number) |
Description |
When the player clicks in the hotbar inventory, checking the relative slots of InventoryClickEvent (#getSlot()) The slots do not map from 0 to 8 (like they should do) but they are (from right to left) [36, 37, 38, 39, 40, 0, 1, 2, 3] code used to check: @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) protected void onPlayerClick(InventoryClickEvent e) { System.out.println(e.getSlotType().name() + ", raw:" + e.getRawSlot() + "->" + e.getSlot()); }//+ The rest of the listener, the main class for loading it and the plugin.yml file |
Comments |
Comment by pokechu22 [ 28/May/17 ] |
Even if it were implemented that way, by convention the 36-item inventory is the bottom one (and not the top one), since it's the bottom one on all other inventories. However, for whatever reason it was chosen to make just the crafting slots at the top the upper inventory, instead of the crafting slots, the armor slots, and the offhand. (My guess: that's because the raw IDs are not continuous between the crafting slots and the armor slots). Creative still has the 5 crafting slots (per the wiki.vg article I linked), which is what offset the slot IDs. Also: note that the fix is in the 1.12 development builds. |
Comment by Rossi Lorenzo [ 27/May/17 ] |
I'm sorry, I don't know much of spigot/bukkit code, shouldn't getTopInventory return the inventory without the quickbar (that is always (creative and survival) of 36 items)? |
Comment by pokechu22 [ 27/May/17 ] |
I've made a PR to fix this: #385 (CB) and #284 (API). |
Comment by pokechu22 [ 27/May/17 ] |
41 is the correct number (4*9 (main inventory and hotbar) + 4 (armor) + 1 (offhand)). The problem's something else entirely: the creative inventory is both the top and bottom inventory. In both survival and creative, the bottom inventory is the creative inventory (size 41). In survival, the top inventory is the crafting slots (5 items). But in creative, it's also the creative inventory (size 41). Thus, no offsetting happens normally, and then when the ID is greater than 41, 41 is subtracted (to get the slot ID in the "lower" inventory). The raw slots in the creative inventory look like this. OK, fine, I can't get an image of them, but per wiki.vg's info on the creative inventory action packet:
So the 5 crafting slots should be in the upper half (even though they aren't visible). That should fix the offsets. As a bonus bug: the current behavior means that putting an item in the offhand slot still indicates the it as being put into the Relates to (but was not introduced by the fix for) |
Comment by pokechu22 [ 26/May/17 ] |
First introduced in 1.9, as best I can tell. |
Comment by Hex [ 26/May/17 ] |
Re-opening this for further review. |
Comment by pokechu22 [ 26/May/17 ] |
Confirmed for survival inventory tab of creative inventory using your plugin. |
Comment by Rossi Lorenzo [ 26/May/17 ] |
Workaround convertSlot function: https://hastebin.com/owefomubut.java |
Comment by Rossi Lorenzo [ 26/May/17 ] |
I've localized a little bit more the problem: in the creative view #getTopInventory#getSize returns 41 even if it should return 36 (like for the non-creative one) so I think that the error is in net.minecraft.server.v1_11_R1.PlayerInventory#getSize |
Comment by Rossi Lorenzo [ 26/May/17 ] |
I left a (major) detail unsaid: this bug appears only in creative mode (sorry, I didn't check) |
Comment by md_5 [ 26/May/17 ] |
Output of your code: [14:37:55 INFO]: QUICKBAR, raw:36->0 [14:37:57 INFO]: QUICKBAR, raw:36->0 [14:37:58 INFO]: QUICKBAR, raw:36->0 [14:37:58 INFO]: QUICKBAR, raw:37->1 [14:37:59 INFO]: QUICKBAR, raw:37->1 [14:37:59 INFO]: QUICKBAR, raw:38->2 [14:38:00 INFO]: QUICKBAR, raw:38->2 [14:38:01 INFO]: QUICKBAR, raw:39->3 [14:38:01 INFO]: QUICKBAR, raw:39->3 [14:38:02 INFO]: QUICKBAR, raw:40->4 [14:38:02 INFO]: QUICKBAR, raw:40->4 [14:38:03 INFO]: QUICKBAR, raw:41->5 [14:38:03 INFO]: QUICKBAR, raw:41->5 [14:38:04 INFO]: QUICKBAR, raw:42->6 [14:38:05 INFO]: QUICKBAR, raw:42->6 [14:38:06 INFO]: QUICKBAR, raw:43->7 [14:38:07 INFO]: QUICKBAR, raw:44->8 Slots work fine |
Comment by pokechu22 [ 26/May/17 ] |
You can't check in vanilla, but I can (using a script); those numbers are significant. Check wiki.vg's article on Inventories; 36 to 44 are all the normal IDs for hotbar slots. That said, it really shouldn't split in the middle - they should either all start at 36, or all at 0. So, still a bug – that's just the source of the numbers. |