Getting Item Taken from a Slot?
vhorvath2010 opened this issue · comments
Is there a way to get what item was removed from a slot? I'm currently trying:
https://paste.md-5.net/ofogaqoqah.coffeescript
and I'm getting an error that the itemstack in that slot is null.
Update, I tried this and it also gives a null pointer: https://paste.md-5.net/weyosicude.coffeescript
I've also tried the deprecated getItem()
with no player reference and it errors as follows: Caused by: java.lang.UnsupportedOperationException: Cannot get item from template
Also, I tried looking at how getItemAmount() works to find a workaround, but looks like getItemAmount() is also broken for inventory removals. For reference I'm using Spigot 1.20.1 so perhaps there were some changes.
I'll need to test out a few cases, but it could be worth trying getClickedSlot().getRawItem()
.
Thanks for the suggestion. I'll try when I'm home and if it works I'll make a PR to make getItemAmount()
more robust and add a corresponding getTakingItem()
to the ClickInformation class
I'll need to test out a few cases, but it could be worth trying
getClickedSlot().getRawItem()
.
This works, I'll make a PR with the suggested changes above
Hey, will try to carve out some time this weekend to take a look. My main concern is backwards-compat so will need to test out how the changes impact the API.
Hey @vhorvath2010, sorry for the 2 month delay. I liked your idea for the taken item API but discovered that canvas had some issues with the SWAP_WITH_CURSOR
InventoryAction (and a few others) that I wanted to address with the new APIs so I've implemented in one of the newer commits.
I've gone ahead and expanded ClickInformation
with the following methods:
getAddingItemAmount
to get the quantity of item added to the clicked slotgetTakingItem
to get the item being removedgetTakingItemAmount
to get the quantity of item being removed
Additionally, ClickInformation#getAddingItem
now properly handles hotbar swapping.
I also didn't want to break functionality for existing users that might be using getItemAmount
so I simply deprecated the method for now.
Hope this helps!