MinecraftForge/MinecraftForge — pull request #810 by OniBait (2013-10-03 06:55:53+00:00)
Title: Add block break events based on @bloodmc's initial 1.5.2 Pull Request

This is an updated PR for Blood's initial 1.5.2 pull request https://github.com/MinecraftForge/MinecraftForge/pull/623 adding block break events.
I've also cleaned it up a bit.

I've updated the comment from his PR:

This new event will be fired in ItemWorldManager.tryHarvestBlock. Any mod that does not use breakBlock should always fire this event for protection reasons. If the event is cancelled, the mod is responsible for preventing the block from
breaking. If there is no player available, the FakePlayer class can be used. To grab a fake entityplayer, you will need to call FakePlayer.get(world, "playername"). It is expected to pass a real player name in this method so protection mods can handle the event correctly.

Included with the BlockEvent.BreakEvent. is the BlockEvent.ExperienceDropsEvent which is responsible for handling experience gained by breaking blocks. In order for a modded block to assign experinece gained for breaking it, you will need to override Block.getExpDrop method and return the experience you want.

~~I have also added a new BlockSnapshot class which is based on CraftBukkit's BlockState but doesn't allow for modification after the snapshot is taken. This class provides a way to restore any location back to a previous
snapshot. By default, a BlockSnapshot is taken before all vanilla breaks/placements and sent via the event.~~

Note: The BlockSnapshot doesn't apply for this scenario and wasn't in Blood's latest commits on his fork. This is because we don't need to simulate block placement for block break scenarios (it would apply for Block Place events, but that would be a separate PR)

This implementation was based off the following commits by CraftBukkit :
Bukkit/CraftBukkit@0c14373
Bukkit/CraftBukkit@f47bc22
Bukkit/CraftBukkit@c542c64
Bukkit/CraftBukkit@d05957d
Bukkit/CraftBukkit@69d634a
Bukkit/CraftBukkit@ea5efcf
Bukkit/CraftBukkit@ad697c0