Change Zombie Drop

Discussion in 'Plugin Development' started by badboysteee98, May 27, 2014.

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

    badboysteee98

    Hello Bukkit,

    I would like to know how to change the Zombie drop rate so that they still drop Zombie Flesh with like a 70% chance and also drop and Diamond with a 2% Chance and then the reset just nothing?

    I have this code so far but it's not doing much expect clearing there Exp dropped and the Zombie flesh

    Code:

    Code:java
    1. public void onZombieDeath(EntityDeathEvent e) {
    2. final Entity zombie = e.getEntity();
    3.  
    4.  
    5. Random drop = new Random();
    6.  
    7. if(drop.nextDouble() <= chance)
    8.  
    9. if(zombie instanceof Zombie) {
    10. e.getDrops().clear();
    11. }
    12. }
     
  2. Offline

    TopTobster5

    You need to get a random number generator, just Google random number Java. Then depending on the result of the number, create an item stack for all results. Then I think you can use e.getDrops().set(youritemstack); badboysteee98
     
  3. badboysteee98 Look into Java's Random class - use it to generate a random number and then from that you can add the items you want to drop.
     
  4. Offline

    badboysteee98

    I have the Random gen and that in I added the old code because I had it copied sorry.
    On the other hand I would I do it depending on the Number?
    Code:java
    1. if(drop < 3) {
    2. e.getDrops().set(new ItemStack(ItemStack.DIAMONDS, 1));
    3. }


    AdamQpzm Just updated my code so it has a Random gen but what do I do after that?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  5. badboysteee98 4 points to consider:

    1. Any particular reason you're getting a double rather than an int?
    2. You'll want to add 1 to the random number since it starts with 0
    3. You'll want to put this bit of code after checking that it's a zombie and clearing the drops
    4. Have you defined chance? It will probably be better to replace with 70 anyway, no real need for a variable.
    5. getDrops() returns a List<ItemStack> - List has a method to add, check relevant JavaDocs
    Edit: 6. Consider the fact I apparently can't count - 4 != 5
     
  6. Offline

    badboysteee98

    AdamQpzm
    1) Okay get an Int because full Number
    2) Add 1 to the Number using what?
    3) I have the code to check if it is an instanceof Zombie and if so clear the drops
    4) What do you mean by define chance?
     
  7. badboysteee98
    2. An additive operator?
    3. Yes, but you do the random stuff before the instanceof check. You want to do it inside that if statement, not before it.
    4. You use 'chance' on line 7 of your code in the OP - what is chance? Where do you make that a thing?
     
Thread Status:
Not open for further replies.

Share This Page