On the slot in the stock

Hello!
I customize the inventory and use inventory.offer (itemstack); add item to the inventory. But how do I add something to the specified slot?I customize the inventory and use inventory.offer (itemstack); add item to the inventory. But how do I add something to the specified slot?
Thank you first!

1234
For example: how to add an apple to the position of diamond sword?
4444
It’s my code.
The code at the red line can not be used. Which way should I use?

Use SlotPos#of instead of new SlotPos()!
It is not the same.

inv.query(QueryOperationTypes.INVENTORY_PROPERTY.of(SlotPos.of(1, 1)))

Thanks very much!!
This code is very useful to me…

So how do I get the location of the slot?
Thanks again!!

SlotPos pos = slot.getProperty(SlotPos.class, SlotPos.getDefaultKey(SlotPos.class)).get();

Unfortunately。 This method looks like it can’t be used in a click event

… why wouldn’t it be able to be used in a click event? Methods are methods are methods.

pos.getX();
pos.getY;
This method does not return to the slot position…

I don’t understand what you are saying. You are passing getTargetInventory() where I’ve written slot, right?

I just want to get the coordinates of a slot simply. For example: (1, 6)

So you get the SlotPos from the slot, and you can get the x and y coordinate from that.