Wither chance of dropping problem

Discussion in 'Plugin Development' started by xxPatterson, Jul 8, 2014.

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

    xxPatterson

    Code:java
    1. @EventHandler
    2. public void onEntityDeath(EntityDeathEvent e) {
    3. if (e.getEntity() instanceof Wither) {
    4. Random random = new Random();
    5.  
    6. ItemStack witherbow = new ItemStack(Material.BOW, 1);
    7. witherbow.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 5);
    8. witherbow.addUnsafeEnchantment(Enchantment.ARROW_FIRE, 1);
    9. witherbow.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1);
    10. ItemMeta itemMeta = witherbow.getItemMeta();
    11. itemMeta.setDisplayName("§lWither Bow");
    12. itemMeta.setLore(Arrays.asList("§bRare"));
    13. witherbow.setItemMeta(itemMeta);
    14. int Chance = random.nextInt(3);
    15. if(Chance == 1) {
    16. e.getDrops().clear();
    17. e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), witherbow);
    18. }
    19. if(Chance > 1) {
    20. e.getDrops().clear();
    21. e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), new ItemStack(Material.NETHER_STAR));
    22. }
    23. }
    24. }
    25.  
    26. }
    27.  

    This is the code, whenever I kill a wither it only drops a netherstar, I have tried removing the nether star but it still only drops it. There is no stacktrace but it still doesn't work, any ideas?
     
  2. Offline

    CynutsBR

    Ur code looks nice, r u registering events?
     
  3. Offline

    xxPatterson

    I have all my events registered in the main class
     
  4. Offline

    Gater12

    xxPatterson
    Random of 3 is exclusive of 3. So possible outcomes are: 0,1,2.
     
  5. Offline

    jpjunho

    xxPatterson
    Code:java
    1. random.nextInt(3)

    generates a random number that can be 0, 1 or 2. So, there's a chance that your code doesn't run (when it's 0).
    And you should only create the bow if the chance is equal to 1:
    Code:java
    1. if(Chance == 1) {
    2. ItemStack witherbow = new ItemStack(Material.BOW, 1);
    3. witherbow.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 5);
    4. witherbow.addUnsafeEnchantment(Enchantment.ARROW_FIRE, 1);
    5. witherbow.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1);
    6. ItemMeta itemMeta = witherbow.getItemMeta();
    7. itemMeta.setDisplayName("§lWither Bow");
    8. itemMeta.setLore(Arrays.asList("§bRare"));
    9. witherbow.setItemMeta(itemMeta);
    10. e.getDrops().clear();
    11. e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), witherbow);
    12. }
     
  6. Offline

    xxPatterson


    Code:java
    1. @EventHandler
    2. public void onEntityDeath(EntityDeathEvent e) {
    3. if (e.getEntity() instanceof Wither) {
    4. Random random = new Random();
    5.  
    6. ItemStack witherbow = new ItemStack(Material.BOW, 1);
    7. witherbow.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 5);
    8. witherbow.addUnsafeEnchantment(Enchantment.ARROW_FIRE, 1);
    9. witherbow.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1);
    10. ItemMeta itemMeta = witherbow.getItemMeta();
    11. itemMeta.setDisplayName("§lWither Bow");
    12. itemMeta.setLore(Arrays.asList("§bRare"));
    13. witherbow.setItemMeta(itemMeta);
    14. int Chance = random.nextInt(3) + 1;
    15. if(Chance == 1) {
    16. e.getDrops().clear();
    17. e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), witherbow);
    18. }
    19. if(Chance > 1) {
    20. e.getDrops().clear();
    21. e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), new ItemStack(Material.NETHER_STAR));
    22. }
    23. }
    24. }
    25.  
    26. }
    27.  

    Fixed that and still only receive nether star drop :(
     
  7. Offline

    Gater12

    xxPatterson
    Try adding debug lines to make sure the event actually fires when the wither dies.
    Show Spoiler
    Debug lines are simply messages that print out some message saying that the lock of code they're put in actually fires
     
  8. Offline

    xxPatterson


    Code:java
    1. @EventHandler
    2. public void onEntityDeath(EntityDeathEvent e) {
    3. if (e.getEntity() instanceof Wither) {
    4. Random random = new Random();
    5. Bukkit.broadcastMessage("Plugin Works");
    6. ItemStack witherbow = new ItemStack(Material.BOW, 1);
    7. witherbow.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 5);
    8. witherbow.addUnsafeEnchantment(Enchantment.ARROW_FIRE, 1);
    9. witherbow.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1);
    10. ItemMeta itemMeta = witherbow.getItemMeta();
    11. itemMeta.setDisplayName("§lWither Bow");
    12. itemMeta.setLore(Arrays.asList("§bRare"));
    13. witherbow.setItemMeta(itemMeta);
    14. int Chance = random.nextInt(3) + 1;
    15. if(Chance == 1) {
    16. e.getDrops().clear();
    17. e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), witherbow);
    18. }
    19. if(Chance > 1) {
    20. e.getDrops().clear();
    21. e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), new ItemStack(Material.NETHER_STAR));
    22. }
    23. }
    24. }
    25.  
    26. }
    27.  

    I added a debug line and it turns out it isn't broadcasting anything when the wither is killed :(
     
  9. Offline

    teej107

    xxPatterson Broadcast the message outside of instanceof if statement to see if your event is even firing. If not, then you need to register your events. And if you did, double check to make sure. If you could post code of where you registered your events then we could help.
     
Thread Status:
Not open for further replies.

Share This Page