Hello ! I have search on the javadocs/bukkit for change a drop of a bloc but I don't know. I want change the drop of Iron_Ore etc. Do you know ? Thank you ^^
Hi maxouland1, You'll need to get the drops list with the getDrops() method, and alter it this way. Alternatively, clear the list from getDrops() and then drop an item manually.
I have make this: Code (Text): public void onBlockBreak(BlockBreakEvent e){ ItemStack iron = new ItemStack(Material.IRON_INGOT, 1); if(e.getBlock().getType() == Material.OBSIDIAN) e.getBlock().getDrops().clear(); e.getBlock().getDrops().add(iron); But it doesn't work. Why ?
There are a few mistakes here: - Did you add an EventHandler annotation, and register events onEnable()? - use .equals() for Materials, not == - Use curly braces on your if statement, as in if statement without them only works on one line.
Code (Text): public class QuickMine extends JavaPlugin implements Listener{ public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this);} @EventHandler public void onBlockBreak(BlockBreakEvent e){ if(e.getBlock().getType().equals(Material.OBSIDIAN));{ ItemStack iron = new ItemStack(Material.IRON_INGOT, 1); e.getBlock().getDrops().clear(); e.getBlock().getDrops().add(iron); }}} It doesn't work :/
No, when you are comparing two enums you have to use == not .equals(). I also think you can't change the drops, you just have to manually drop the item in the world at the block's location.
Code (Text): public class QuickMine extends JavaPlugin implements Listener{ @Override public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this);} @EventHandler public void onBlockBreak(BlockBreakEvent e){ if(e.getBlock().getType().equals(Material.OBSIDIAN));{ ItemStack iron = new ItemStack(Material.IRON_INGOT, 1); e.getBlock().getDrops().clear(); e.getBlock().getDrops().add(iron); It doesn't work :c
This should work. Code (Text): @EventHandler public void onBlockBreak(BlockBreakEvent e) { Block block = e.getBlock() ArrayList<ItemStack> drops = new ArrayList<ItemStack>(); if(block.getType() == Material.OBSIDIAN) { ItemStack iron = new ItemStack(Material.IRON_INGOT, 1); drops.add(iron); e.getBlock().getDrops().clear(); for(int i = 0; i < drops.size(); i++) { ItemStack drop = drops.get(i); block.getWorld().spawn(block.getLocation(), drop); } } }
You could try clearing the drops and just doing e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(Material.IRON_INGOT));