Pokkit icon indicating copy to clipboard operation
Pokkit copied to clipboard

Nukkit and the inexistent InventoryClickEvent

Open MrPowerGamerBR opened this issue 8 years ago • 8 comments

Nukkit doesn't have a event to get if a player clicked on a item (InventoryClickEvent), however...

ContainerSetSlotPacket is sent from the client everytime he clicks on a item, at least Nukkit has a DataPacketReceiveEvent so we can intercept the click event.

However, there are issues with this:

  • We need to cache the last open inventory, since Nukkit doesn't have a API to get the current open inventory.
  • We need a way to convert Inventory (Nukkit) to InventoryView (Bukkit) because Bukkit needs a InventoryView.

But now I'm stuck, I tried doing this but I couldn't convert a Inventory (Nukkit) to a InventoryView (Bukkit).

MrPowerGamerBR avatar Oct 07 '16 17:10 MrPowerGamerBR

I will take a look at this tomorrow.

Inventories will be difficult to translate. In Pocket Edition, you can send an ItemStack from one inventory to the other in one go. We can maybe simulate this as two clicks (item pickup and item place).

Storing the open inventory can be done by creating another field in PokkitPlayer. If we know the open inventory and the player inventory, that should be enough information to create an InventoryView.

rutgerkok avatar Oct 07 '16 18:10 rutgerkok

I found InventoryTransactionEvent, which notifies when a transaction is completed.

In the Windows 10 edition, if you move an item (let's say: stone) to another slot, you get an InventoryTransactionEvent after the move is done. The event consists of two transactions: one that sets the old slot from stone to air, and one transaction that sets the new slot from air to stone.

In the Windows 10 edition, the hotbar occupies inventory slot 0 to 8. In Pocket Edition, the hotbar can occupy any inventory slot: place 3 in the hotbar can represent the item on slot 12 in the inventory. It is likely that a lot of Bukkit plugins expect the hotbar to always be in inventory slot 0 to 8.

rutgerkok avatar Oct 08 '16 13:10 rutgerkok

@rutgerkok at first we shouldn't care about the hotbar slots, not a lot of plugins care if a item is at a specific slot in a hotbar (on inventories? yes, but hotbars? probably not)

MrPowerGamerBR avatar Oct 08 '16 13:10 MrPowerGamerBR

@MrPowerGamerBR Tell to magicdroid for implement to nukkit

ghost avatar Oct 08 '16 20:10 ghost

so we can handle when windows 10 client click on item?

Creeperface01 avatar Oct 18 '16 21:10 Creeperface01

@Creeperface01 I tested a little bit with the Minecraft Windows 10 client and yes, the ContainerSetSlotPacket is sent when the client clicks on a item.

MrPowerGamerBR avatar Oct 18 '16 21:10 MrPowerGamerBR

Here is InventoryClickEvent https://github.com/yescallop/Nukkit/blob/ed643e70cddb1a83a32c5b0a8a29a2477982ce34/src/main/java/cn/nukkit/event/inventory/InventoryClickEvent.java

ghost avatar Jun 13 '17 18:06 ghost

Nukkit have implemented an event for inventory clicking. Works in classical UI or default UI in Windows 10. Looking forward to your work guys :)

Snake1999 avatar Jul 09 '17 02:07 Snake1999