Is it possible to have a block, when damaged to throw out an item? I can't figure out how to make it work, i'm such a noob
Try onBlockDamage to trigger the trowing item. See: http://javadoc.lukegb.com/Bukkit/de...stener.html#a064b3ca4d623af225849bc2ccb4d90f9
Hi David, i'm a n00b too Did you find out how to put an item into the minecraft world? If yes, would you explain it? I searched in the javadocs and tryed some things but nothing worked for me... Thanks in advance
I just found this: http://javadoc.lukegb.com/Bukkit/dd...1World.html#ab487861a8a67dd9ebac68dd08de6050e Maybe "dropItem" and "dropItemNaturally" is what we are searching for, but i don't know what path has to be includet to use it?! Is there a pro in this forum who knows and likes to share his wisdom? Reward would be a bukkit full of win
Basically yes, but a sandstone block is already dropped if you break sandstone? So if i wanted two sandstone blocks to be dropped, that would be it. What i really want is i.e. a dropped snowball if i break snow or something like that.
okay. well, Sandstone is nonreclaimable when placed, so hence why i used it as an example also, shovelling snow drops snowballs but i can see why you want it to be done with your hands etc, so give me a moment and ill see if i can get it working for you.
Like MadMichi said, dropItemNaturally() is probably the way to go, something like this: Code: event.getPlayer().getWorld().dropItemNaturally(event.getPlayer().getLocation(), new ItemStack(Material.SNOW_BALL, 1)); to use it you should only need to import Code: import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; Along with whatever imports you need for the event you are using.
I'll admit that i have no idea how to check if a block is being damaged. this: Code: public void onBlockDamaged(BlockDamageEvent event) { System.out.println("A block is being damaged!"); System.out.println(event.getBlock().toString()); if (event.getBlock().toString().equalsIgnoreCase("snow")) { event.getPlayer().getWorld().dropItemNaturally(event.getPlayer().getLocation(), new ItemStack(Material.SNOW_BALL)); } } does not output anything in the console, Code: pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this); is the code registered.
Its onBlockDamage() now, i dont think they've updated the hook names though so BLOCK_DAMAGED should still work. EDIT: I'm not sure that Code: event.getBlock().toString().equalsIgnoreCase("snow") will work, might be better to use Code: event.getBlock().getType() == Material.SNOW
Welp, i've got it. break a snow sheet and it gives you 2 snowballs. Doesn't check "in hand" for any tools or anything. oh, and it also randomly spawns a big tree... Code: public void onBlockDamage(BlockDamageEvent event) { if (event.getBlock().getType() == Material.SNOW ) { if (event.getDamageLevel() == BlockDamageLevel.BROKEN) { event.getPlayer().getWorld().dropItemNaturally(event.getPlayer().getLocation(), new ItemStack(Material.SNOW_BALL, 2)); } } }
My version also, if you break a snow sheet at your feet, it grows a tree but i didnt give you that bit.
Wow, works great! I have one problem though, fails epically What's wrong with it? Tried doing compiled fine, but insta-errored me AND corrupted my player.dat file in the world file, making me unable to log in 0.0
Code: Material blockzor = event.getBlock().getType(); Player player = event.getPlayer(); dropItemNaturally(event.getPlayer().getLocation(), new ItemStack(blockzor, 1)); I think works.