roguehippo Posted January 21, 2017 Posted January 21, 2017 Hello, i just wanted to know if it was possible for something to return all the spots in the inventory that contain an item with a certain name in list form. ex:if i had 10 vials in my inventory and i asked for the list for "vial", it would return the 10 corresponding inventory spots.
gamedemented Posted January 21, 2017 Posted January 21, 2017 https://gyazo.com/4d00722177c5dc658d42d42c70b60eda 1
FrostBug Posted January 21, 2017 Posted January 21, 2017 as in the item indices? could do something like int[] slots = IntStream.range(0, getInventory().getCapacity()).filter(i -> getInventory().getItemInSlot(i) != null && "ItemName".equals(getInventory().getItemInSlot(i).getName())).toArray(); 1 1
roguehippo Posted January 21, 2017 Author Posted January 21, 2017 https://gyazo.com/4d00722177c5dc658d42d42c70b60eda thanks, sorry i guess i looked over the fact that i can just check if they are the item i want if i have a list of all items. as in the item indices? could do something like int[] slots = IntStream.range(0, getInventory().getCapacity()).filter(i -> getInventory().getItemInSlot(i) != null && "ItemName".equals(getInventory().getItemInSlot(i).getName())).toArray(); i feel like this would be exactly what i need but since i am still a bit unfamiliar with streams and how they work i would probably not be able to utilize it correctly. thank you for the constant help with almost all of my posts frostbug you are awesome