Working with the players inventory

Dear all,

I coulnd’t find any good help inside the documentation and inside the forum. Because of that I decided to create this topic to ask the following questions I am struggeling with.

1.) How do I add an item to a specific slot into the players inventory?
All topics I found were outdated with depricated examples that doesn’t work for me
Example: How to Place Item in an Inventory
Solution: Get the players main Inventory to access the grid Inventory. Inside the grid Inventory you can use the set method to specify the slot number or slot position.

2.) How can I get the clicked slot index inside the ClickInventoryEvent event?
Found a topic for this aswell, but based on the topic it wasn’t implemented years ago. I also tested it with the 7.1.0 API but the results are still empty.
Source: Howto get clicked slot position in the inventory

3.) How do I get the clicked item and the item on the cursor?

I would appreciate any help.

Regards
Sascha

So a lot of the inventory api has changed over the years. For part 2, what event are you using?

As for part 1, your solution is correct. You can use Query as shown in your solutions post. To gain the slot, from there use Slot.set(item) to set the item in that slot

I am currently using the ClickInventoryEvent.Primary event, but I don’t know how to get the related/clicked slot number. As mentioned above the slot index and slot position properties are empty.

How are you getting the slotIndex property? Because the way explained in the link you gave is out of date

You can get the “primary” clicked slot if availiable via:

InteractInventoryEvents provide the cursor item in a transaction:

1 Like

Thanks for the feedback. Seems the GetSlot() Method isn’t included in the 7.1.0 API.
With the latest build it works.