Hi, I’d like to listening an open-inventory-event when a player open his backpack by press “E”, but it seems like
InteractInventoryEvent.Open
could only called when a player open a chest container, is there any way to listening open player backpack?
Unfortunately, no. Minecraft no longer lets the server know when the player opens their inventory.
OK, but is there any other way could achieve this function? something dirt but effectively?
If the client doesn’t let the server know, there is literally no way to know.
It’s actually possible (at least on 1.10) to listen for the achievement when a player opens their inventory.
See this old discussion:
SpongePowered:master
← SpongePowered:feature/inventory
Players and inventories are kind of weird, especially in the case of Players and… their own inventory. With most inventories, the Player interacts with a Block and then the server sends them the open window packets. With a Player's own inventory, however, they don't ask for server side validation before opening the Inventory. The client stores the contents of its own inventory and is therefore able to open the inventory without needing any additional information from the server. Around the time achievements came out(Taking Inventory!) the ability to tell when the client opened its own inventory appeared.
We experimented around a bit with this in Bukkit, but ultimately it didn't directly get anywhere(the functionality can be achieved via the achievements API) The best that you can get is closing the Player's inventory right after they open it, which stands in stark contrast to all other inventories where it can simply be prevented.
Also, I should mention that my knowledge base extends only to Minecraft 1.7. I know nothing about 1.8, and it could be entirely different(Wasn't Dinnerbone rewriting part of inventories?).
Around the time achievements came out(Taking Inventory!) the ability to tell when the client opened its own inventory appeared.
I don’t know if this trick is still possible on 1.12/1.13
If I remember correctly, it was removed in 1.12 when achievements were replaced with advancements.
Not to mention that they wholeheartedly removed the advancement for opening the inventory…