How to get index of clicked inventory slot on ClickInventoryEvent?

SlotPos slotPos = e.getTransactions().get(0).getSlot().getProperty(SlotPos.class, “slotpos”).orElse(null);

I’ve tried this code and several others, and It seems none of them will do anything useful.

I need to get index of clicked item’s position

Some threads saying that it’s not implemented yet like one year ago; is it still not implemented?

Any idea?

Thank you

It is in fact implemented correctly.
Your explanation is unclear. What do you mean it won’t do anything useful? What else have you tried?
And SlotPos retrieves the x and y coordinates of the slot on the 2D plane of slots. If you want to get the one-dimensional index, you’d use SlotIndex for that.

1 Like

Thank you for reply!

slotPos is always null somehow

I’m pretty new to Sponge API, so is there like foolproof method to get index of clicked slot?

From ClickInventoryEvent :slight_smile:

Bump Bump


As mentioned above SlotPos is only for grid inventories and does not always exists.
slot.getInventoryProperty(SlotIndex.class) is the way to get a SlotIndex.

1 Like

Thank you!

getInventoryProperty() worked like a boss!

I was using getProperty maybe that’s why it didn’t work

getInventoryProperty just calls getProperty with the default key (lower cased classname)

1 Like