Updated to reflect new(er) Bukkit syntax. This is how you can set the drop for any block: Code:java @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)public void onBlockBreak(BlockBreakEvent event) {if(event.getBlock().getType() == Material.DIRT) {Block block = event.getBlock();block.getDrops().clear();block.getDrops().add(new ItemStack(Material.EGG));}} Have fun!
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.
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.
You set the block to air because you cancelled the block break event (99% sure) If you didn't, the block would just respawn.
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.
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 } }
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.)
Wonder what else you could do... Code:java Block block = event.getBlock();block.getDrops().clear();block.getDrops().add(new ItemStack(Material.EGG));
This resource is based on an old version of bukkit, there are better methods, such as what @KeybordPiano459 @KeybordPiano459 described above.