Get Item with the slot in Inventory

Hello ! I search how can I get the Item with the slot in Inventory. I want to do the same that Bukkit in Sponge

public void saveInventory(){

    for(int slot = 0; slot < 36; slot++){
        ItemStack item = player.getInventory().getItem(slot) //That here 
        if(item != null){
            items[slot] = item;
    items[36] = ItemStack.of((ItemType) items[36], 1);
    items[37] = ItemStack.of((ItemType) items[37], 1);
    items[38] = ItemStack.of((ItemType) items[38], 1);
    items[39] = ItemStack.of((ItemType) items[39], 1);


Thank’s !

Use slotIndex inventory propery to get the number of the slot pos.

This may help. I know there is a way of specifying which slot you want using getProperty() but can not for the life of me remeber it.

I don’t find how can I use the #getProperty() to get the slot Item.
Should I do this ?

        for (Inventory i : player.getInventory().slots()) {
    	//get the slot item
    	ItemStack item = ItemStack.of(i.getProperty(property, key), 1);
        if (i.size() != 0) {
        	items[slot] = item;

Thank you

Map<Integer, Slot> map = new HashMap<>();
for (Slot slot : player.getInventory().slots()) {
    if (slot.size() == 0) {
    Optional<SlotIndex> opIndex = slot.getInventoryProperty(SlotIndex.class);
       map.put(opIndex.getValue(), i);

ItemStack stack = map.get(35).peek().get();

That is how I would do it, like i said there is a way to use inventory property from the main inventory but can not remember it. Please note that map.get(35) if slot 35 wasnt set in then it would return null. Also note i wrote this from memory and not in a IDE such as Eclipse, so some expect typos and for it not to work without minor changes.

@MoseMister .getValue() is not defined. Can I get the slot of player inventory with an int, and get the ItemStack ?

Sorry it was supposed to be


And yes. The last line does that

@MoseMister Ok thanks, there is an error in Slot slot : player.getInventory().slots(), we can’t do this.

In map.put(opIndex.getValue(), i);, what is the variable/type of i please ?

Thank’s you!

What is the error? As for what I is.

Map<Integer, Slot> map

Therefore the first value in put is a int/Integer value. As for the second value, it is slot