Getting a random block/item

Discussion in 'Plugin Development' started by Phishy, Apr 18, 2015.

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

    Phishy

    Hi, I was wonder how I would go about getting a random block, and then it be placed in the players inventory?

    Thanks.
     
  2. Loop through Material.values()
    Check if it is a block
    Add the material to a list

    And then get the random material of the list, build an ItemStack and place it in the players inventory
     
  3. Offline

    Phishy

    Could you explain a little how I would go about doing this, not spoon feeding though.
     
  4. Offline

    ShadowLAX

    @Phishy Use a for loop to iterate through all the values of he material enum. Then, check if it is a block by using the isBlock() method. Then, if it is so, create an ItemStack using that material and add it to the player's inventory.
     
  5. Offline

    Phishy

    That's the exact same thing that Fishy said.
     
  6. Learn java if you don't know how to use:
    • for-loop
    • List
    • Random
     
    DoppelRR and ShadowLAX like this.
Thread Status:
Not open for further replies.

Share This Page