Looping over Monster eggs o.O

Discussion in 'Plugin Development' started by PurePlugins, Sep 21, 2014.

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

    PurePlugins

    Hello, I was wondering if anyone knows how to loop over Monster eggs? I know how to loop over items and check for MONSTER_EGG, but i need the (byte) value. I'm trying to loop over all sopawn eggs then add them to a list
     
  2. Offline

    mythbusterma

    PurePlugins

    I don't understand what the question is. What exactly needs iterated over?
     
  3. Offline

    PurePlugins

    mythbusterma, Alright so what I'm trying to do is loop over all monster eggs in the game. from Creeper to Villager.
    I need a way to get their data values, for example a creepers data value is 383:50. I need to single out the 50. do you know what i mean?

    mythbusterma
    What I'm currently doing

    Code:java
    1. public Inventory petMenu(UUID userID) {
    2. Inventory inventory = Bukkit.createInventory(null, 27, "Choose a pet");
    3.  
    4. List<Integer> data = new ArrayList<Integer>();
    5. data.add(50);
    6. data.add(51);
    7. data.add(52);
    8. data.add(54);
    9. data.add(55);
    10. data.add(56);
    11. data.add(57);
    12. data.add(58);
    13. data.add(59);
    14. data.add(60);
    15. data.add(61);
    16. data.add(62);
    17. data.add(65);
    18. data.add(66);
    19. data.add(90);
    20. data.add(91);
    21. data.add(92);
    22. data.add(93);
    23. data.add(94);
    24. data.add(95);
    25. data.add(96);
    26. data.add(98);
    27. data.add(100);
    28. data.add(120);
    29.  
    30. Iterator<Integer> itr = data.iterator();
    31.  
    32. while (itr.hasNext()) {
    33.  
    34. ItemStack icon = new ItemStack(Material.MONSTER_EGG, 1, (byte) itr.next().intValue());
    35.  
    36. inventory.addItem(icon);
    37. }
    38.  
    39. check.add(userID);
    40. return inventory;
    41. }


    but i dont want to have to add them to a list like that

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  4. Offline

    teej107

    PurePlugins Why not use a for loop?

    EDIT: And get rid of that ArrayList
     
  5. Offline

    PurePlugins

  6. Offline

    teej107


    Code:java
    1. for(int i = 50; i < 121; i++)
    2. {
    3. //Use declared int.
    4. }
     
  7. Offline

    PurePlugins

    teej107, i thought thats what you meant, but, if you look at my code snippet you can see that it skips quite a few numbers
     
  8. Offline

    teej107

    Ah well then
    Code:java
    1. int[] numbers = new int[] { numberHere, numberThere, numberEverywhere};
    2.  
    then loop through the array

    idk why your using an iterator. Looping even through your arraylist would've been fine.
     
  9. Offline

    rrhett

  10. Offline

    PurePlugins

Thread Status:
Not open for further replies.

Share This Page