Reputation: 98
I am recently facing a problem that I can't get throught: how do I get the slot of an item?
let's say my code looks like that
ItemStack[] items = inv.getContents();
for (ItemStack item : items) {
if (item != null) {
if (position < 27 && position > -1) {
SOMETHING HERE LIKE ---> item.getRawSlot()
}
} else {
}
}
But the method getRawSlot() is not valid for item class, what can I do?
Upvotes: 2
Views: 2841
Reputation: 4592
You can't know the index of your current array item when using a for-each
loop. You'll have to use a regular for
loop with an explicit index:
for (int = 0 ; i < items.length; ++i) {
Item item = items[i];
if (i < 27 && i > -1) {
// do something here like item.getRawSlot();
}
// another example of something you could now do that you
// couldn't do using for-each
items[i] = new Item(...);
}
Upvotes: 2