Create ItemStack array with no null items

Discussion in 'Plugin Development' started by Max8801, Mar 15, 2016.

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

    Max8801

    Hey guys,
    I wonder how I can create an ItemStack array containing the items in a players inventory. The problem with the getContents method is that it returns an ItemStack array including the empty slots. My question is: How can I filter the ItemStack array so that I have only the real items in it.
    Regards, Max
     
  2. Offline

    mythbusterma

    @Max8801

    Why do you need to not have those items? Empty spots are just as valid as normal items, and if you don't want to add them to something else, ignore the null entries.
     
  3. Offline

    Max8801

    That's the problem. I want to create an item randomizer and I don't want theese null items to affect the result.
     
  4. Offline

    mythbusterma

    @Max8801

    Randomiser in what sense? Rearranges them?
     
  5. Offline

    blablubbabc

    You could loop over all inventory slots and if the slot isn't empty you add the information you need (ex. the ItemStack, or the slot index or similar) to a list which you have created. That list will then not contain any information about the empty inventory slots.
     
Thread Status:
Not open for further replies.

Share This Page