Iterating over the different sections of a player's inventory

Title says more or less my problem. I need to iterate over the different parts of the player’s inventory separately, including hotbar, main inventory, armor, and item in hand. I know how to iterate over the entire inventory, and how to get the item in hand, but I don’t know how to:

  1. Iterate over armor, hotbar, and main inventory seperatley
  2. Distinguish selected item in hotbar so as not to process it twice

Right now all I’m doing is checking the ItemStack in hand, and I really need to be able to distinguish between the different inventory sections. Any help would be greatly appreciated!

EDIT: just find the get\armor/() methods on player! half way there…

EDIT 2: Figured most of it out using GridInventory and Hotbar, just one question, how do I get the SlotIndex of a slot in the hotbar? Currently I’m using:

//Doesn't feel right...
SlotIndex index = hotbar.getProperty(slot, SlotIndex.class, SlotIndex.class.getSimpleName()).get();

This doesn’t work for me. Returns absent. Any progress?

Try

SlotIndex index = slot.getProperty(SlotIndex.class, null).get();

I honestly don’t remember what I did. I know I figured most of this out, and that I found some workaround for what I was specifically doing… Not sure what I did.

Still no. Maybe running this against the wrong item. Here’s what I have

for(Inventory slot : player.getInventory().query(Hotbar.class).slots()){
    SlotIndex index = slot.getProperty(SlotIndex.class, null).get();
}
for(Inventory i : player.getInventory().query(Hotbar.class)){
    Slot s = (Slot)i; 
    s.peek ..... 
}

in a case you want to access slot thru its index

hotbar.getSlot(new SlotIndex(slot));

And also you might find useful hotbar method getSelectedSlotIndex

Still having the same problem unfortunately. What I’m trying to do is save hotbar to a Map including the SlotIndex of each slot so to preserve the location of the ItemStack for later.

for(Inventory i : player.getInventory().query(Hotbar.class)){
    Slot slot = (Slot) i;

    Optional<ItemStack> peek = slot.peek();

    if(peek.isPresent()){
	    hotbar.put(slot.getProperty(SlotIndex.class, null).get(), peek.get());
    }
}

i dont think getProperty is fully implemented.

I see. That explains every inventory type returning no properties. Well I have a work around for the hotbar, but GridInventory I really need the SlotPos.