Wizards of Lua

The Art of Spell Crafting


BlockBreakEvent - When a Player Breaks a Block

The BlockBreakEvent is fired when an Block is about to be broken by a player.

Canceling this event will prevent the Block from being broken.

The BlockBreakEvent class is a subtype of the BlockEvent class and inherits all its properties and functions.

Here is an overview of the BlockBreakEvent properties:

Property Type read / write
experience number (int) r/w
player Player r

Properties

Below you find short descriptions about each of the properties and some examples about how to use them in your spells.


experience : number (int)

This is the amount of experience to drop by the block, if the event won’t be canceled.

Example

Drop a number of diamonds equal to the amount of experience a player gains through mining coal ore, redstone ore, etc. Note that you don’t get experience from breaking blocks in creative mode.

local queue = Events.collect("BlockBreakEvent")
while true do
  local event = queue:next()
  spell.pos = event.pos
  if event.experience > 0 then
    spell:dropItem(Items.get('diamond', event.experience))
  end
end

Example

Drop 20 experience points when a players breaks a grass block.

Events.on("BlockBreakEvent"):call(function(event)
  if event.block.name == "grass" then
    event.experience = 20
  end
end)

player : Player

This is the player who broke the block.