[TUTORIAL|EASY] How to make a custom drop

Discussion in 'Resources' started by hawkfalcon, Jun 4, 2012.

  1. Offline

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Updated to reflect new(er) Bukkit syntax.
    This is how you can set the drop for any block:
    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    2. public void onBlockBreak(BlockBreakEvent event) {
    3. if(event.getBlock().getType() == Material.DIRT) {
    4. Block block = event.getBlock();
    5. block.getDrops().clear();
    6. block.getDrops().add(new ItemStack(Material.EGG));
    7. }
    8. }

    Have fun!

    This post has been edited 6 times. It was last edited by hawkfalcon Mar 17, 2013.
  2. Offline

    McLuke500

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    With this what happens if you break a block under water?
  3. Offline

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Haven't tested, good question;o

    This post has been edited 2 times. It was last edited by hawkfalcon Jun 5, 2012.
  4. Offline

    Iron_Crystal

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Well, looking at the code he posted, he is turning the block to air. So what do you think will happen if you make a block air that is fully enclosed in water?

    PS. It fills in.
  5. Offline

    tips48

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    The same thing as if it wasn't under water?
  6. Offline

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    It does set it to air though ;p
  7. Offline

    Technius

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    They really need to add a drops list for BlockBreakEvent. It should be an ArrayList...
    hawkfalcon likes this.
  8. Offline

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Yeah but this is an alternative in the time being^
  9. Offline

    tips48

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    It will set the block that was broken to air. You can't break water, so it will just change the physics when the item is dropped.

    This post has been edited 1 time. It was last edited by tips48 Jun 6, 2012.
  10. Offline

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  11. Offline

    WarmakerT

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    You set the block to air because you cancelled the block break event (99% sure)
    If you didn't, the block would just respawn.

    This post has been edited 1 time. It was last edited by WarmakerT Jul 3, 2012.
  12. Online

    JOPHESTUS

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    This is awesome! I used it in JOPHSpawner. I've given you credits at the bottom :)

    This post has been edited 1 time. It was last edited by JOPHESTUS Jul 3, 2012.
    hawkfalcon likes this.
  13. Offline

    WarmakerT

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Wrong quote :p
  14. Online

    JOPHESTUS

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Sorry :p
  15. Offline

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Thank you:)
    True.
  16. Offline

    WarmakerT

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    And if you don't cancel the event, then the real drops will drop.
  17. Offline

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  18. Offline

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  19. Offline

    Icyene

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Everyone is copying my TUTORIAL|LEVEL format now >.<

    Nice tutorial :) If the newbies see this it will decrease the amount of questions asking about this.
    hawkfalcon likes this.
  20. Offline

    blackwolf12333

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    It is a good way of telling people what level that tutorial is, so i get why everyone is copying it:p
    hawkfalcon likes this.
  21. Offline

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I made it extremely noob friendly:3
  22. Offline

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    derpNaturally();
  23. Offline

    aviator14

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    If you are ignoring the cancelled state, doesn't that mean you can override any sort of protection on the block?

    Would something more like this work?
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)//must be high priority
     
    public void onBlockBreak(BlockBreakEvent event)//checks for any block break
    {
    if(!event.isCancelled() && event.getBlock().getType() == Material.~INSERT_BLOCK_TO_BREAK_HERE~)//checks for a specific block
    {
    Block block = event.getBlock();//creates variable block with the block broken
    Collection<ItemStack> drops = block.getDrops();//creates variable drops with the current drops of that block
    drops.clear();//remove those drops
    drops.add(new ItemStack(Material.~INSERT_MATERIAL_YOU_WANT_DROPPED_HERE~, 1); //do this for every itemstack you want to be dropped
    }
    }

    This post has been edited 2 times. It was last edited by aviator14 Nov 12, 2012.
  24. Offline

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Possibly. Depends on what you want.
  25. Offline

    aviator14

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I retract my first question, having now learned that ignoreCancelled is the opposite of what it sounds like. (For those like me, if that attribute is true, your code will not run if the event is cancelled. So it actually IS what you'd want here.)
    hawkfalcon likes this.
  26. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Wonder what else you could do... :p
    Code:java
    1. Block block = event.getBlock();
    2. block.getDrops().clear();
    3. block.getDrops().add(new ItemStack(Material.EGG));
    hawkfalcon likes this.
  27. Offline

    realiez

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    What would you do for a mob?
  28. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    On the event that the mob dies, clear the drops and add new ones, like I've done above.
  29. Offline

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  30. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME

Share This Page