Hey there!
I was wondering how I would get an item from an inventory that has a certain ItemType and then check the lore for it.
How would I get the item from the inventory?
Thanks in advance!
Take a look at QueryOperationType. Its a god sent.
However if want untested code (so you still learn fixing the mistakes i make from the top of my head) then here you go
Inventory inv; //inventory to query
Inventory filteredInv = inv.query(QueryOperationTypes.ITEM_TYPE.of(ItemTypes.EXAMPLE); //returns a custom inventory with only the slots that have a item with the item type specificed
for(Slot slot : filteredInv.slots()){
ItemStack stack = slot.peek().get(); //gets the item in the slot - as we have already filtered, the optional will always be a value
List<Text> lore = stack.get(Keys.ITEM_LORE).get();
1 Like
Thanks a lot! This really helped me out.
1 Like