inv.getContents(), get rawslot of each item

Discussion in 'Plugin Development' started by Maxpnl, May 14, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Maxpnl

    Hello guys, I'm trying to get the raw slot from each item inside and inventory, I tried something like this

    ItemStack[] items = inv.getContents();
    for (ItemStack item : items) {
    if (item != null) {
    if (position < 27 && position > -1) {
    item.getRawSlot()
    }
    } else {
    }
    }

    But item class has no getRawSlot(), then my question is, how do I get the slot of the item I'm checking? thanks in advance

    EDIT: I'm new to the forum and I don't know how to make a code formatted line, please be patient :)

    I tried using

    inv.getLocation(item)

    but ItemStack and Inventory don't seem to get along ("The method getLocation() in the type Inventory is not applicable for the arguments (ItemStack)")
     
  2. Online

    timtower Administrator Administrator Moderator

    @Maxpnl Use an int counter instead of the enhanced for loop.
     
  3. Offline

    Maxpnl

    I don't get the point of using it sorry (not saying it's wrong), how do I use the current int to get the position? Thanks for the fast reply btw :)

    EDIT: Holy Jesus you are genius, I'm still pretty tired and I didn't get it immediatly, thansk :D
     
    Last edited: May 14, 2017
  4. Online

    timtower Administrator Administrator Moderator

    @Maxpnl You can't with your method.
    That is why you should use the int loop, you are looping over the slot numbers.
     
Thread Status:
Not open for further replies.

Share This Page