Creating random itemstacks.

Discussion in 'Plugin Development' started by Minibros, Apr 23, 2016.

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


    I'm trying to create random itemstacks with Material.Something

    static ArrayList<ItemStack> goodies = new ArrayList<ItemStack>();
    Random selection system:
                  for (int i = (3 + 1); i > 0; i--) {
                        Random random = new Random();
                        int index = random.nextInt(goodies.size());
                        ItemStack dropItem = goodies.get(index);
    Unfinished method that i need:
            for (int i = (100 + 1); i > 0; i--) {
                // Create random itemstacks.
  2. Offline


    First of all, what is the problem?
    And then, some notes:
    Is static nessesary here?

    No need to create 3+1 Random objects, create one outside the loop or even as a class variable and use it instead.

    I thought 100+1 = 101 :O hehe :p <Laugh now, it was supose to be a joke>
  3. Code:
    Material[] m = Material.values();
    int mlength = m.length;
    Random random = new Random();
    int index = random.nextInt(mlength);
    Material randMaterial = m[index];
    ItemStack item = new ItemStack(randMaterial);
    Here's something you can use. (untested).
  4. Offline


    @ZanctarianDevelopment As i said in another thread as well, don't spoonfeed.
    Read the post from @Zombie_Striker found here for a brief explanation of the reasons and feel free to argue or ask any questions you have there. This code as it is there can be abused to an inefficient solution.
  5. Offline


    They all are the same here.... :(
  6. Offline


    Use item id's with java's built in random class, you can use new ItemStacks with the original ID's for different items.

    Why do I even bother helping?
  7. Offline


    Ok as long as you are not abusing it and you remain within the boundaries of Object Oriented Programming.

    Thanks ill remember that. I would apriciate some sort of politeness, and i remind you part of the rules you read and accepted when you registered to this comunity:
    (Mentioned under rule #2)

    But anyways, we have a reason why we don't spoonfeed and that is because experience shows it does more harm than good. You can read more here and feel free to ask any questions you have and argue with us about it there.
Thread Status:
Not open for further replies.

Share This Page