rutgerkok / Pokkit

Nukkit plugin that is able to load Bukkit plugins. Bring your Bukkit plugins to Minecraft PE!
Other
79 stars 27 forks source link

Nukkit and the inexistent InventoryClickEvent #24

Open MrPowerGamerBR opened 8 years ago

MrPowerGamerBR commented 8 years ago

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:

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

rutgerkok commented 8 years ago

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 commented 8 years ago

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.

MrPowerGamerBR commented 8 years ago

@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)

ghost commented 8 years ago

@MrPowerGamerBR Tell to magicdroid for implement to nukkit

Creeperface01 commented 8 years ago

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

MrPowerGamerBR commented 8 years ago

@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.

ghost commented 7 years ago

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

Snake1999 commented 7 years ago

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