When you kill a Mob, it drops an item, how could u do it?

Discussion in 'Archived: Plugin Requests' started by TheRayMirez, Feb 18, 2014.

  1. Offline

    TheRayMirez

    When you kill a Mob, it drops an item, how could u do it?
     
  2. Offline

    Ethanol2906

    You could get the event, make sure it's a mob killed by a player and get the location of the event then drop the item you wish to drop.
    Code:java
    1. @EventHandler
    2. public void onBlockBreak(BlockBreakEvent event) {
    3. Player player = event.getPlayer();
    4. if (event.getBlock().getType() == Material.DIRT || event.getBlock().getType() == Material.GRASS) {
    5. if (player.getItemInHand() != null) {
    6. if (player.getItemInHand().getType() == privateItem.getType()) {
    7. if (player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(privateItem.getItemMeta().getDisplayName())) {
    8. Random randomGenerator = new Random();
    9. int randomInt = randomGenerator.nextInt(11);
    10. if (randomInt <= 3) {
    11. Block block = event.getBlock();
    12. block.setType(Material.AIR);
    13. block.getWorld().dropItemNaturally(block.getLocation(), privateItem);
    14. block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(Material.DIRT));
    15. event.setCancelled(true);
    16. }
    17. }
    18. }
    19. }
    20. }
    21. }


    Just an example of what I did for block break event in one of my plugins.
     
  3. Offline

    TheRayMirez


    But if for example i want that the mob drops an esmerald, what should i do?
     
  4. Offline

    Mathias Eklund

    TheRayMirez You would change Material.DIRT to Material.EMERALD
     

Share This Page