Wizards of Lua

The Art of Spell Crafting


BlockPlaceEvent - When a Player Places a Block

The BlockPlaceEvent class is fired when a player places a block.

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

Here is an overview of the BlockPlaceEvent properties:

Property Type read / write
hand string r
placedAgainst Block r
player Player r
replacedBlock Block r

Properties

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


hand : string

The hand the player used to place the block. Can be ‘MAIN_HAND’ or ‘OFF_HAND’.


placedAgainst : Block

The block against which the new block was placed. Unfortunately the NBT of the block placedAgainst is unavailable in this event.

Example

Transform all torches that are placed against a redstone block into redstone torches.

local queue = Events.collect("BlockPlaceEvent")
while true do
  local event = queue:next()
  if event.block.name == 'torch' and event.placedAgainst.name == 'redstone_block' then
    spell.pos = event.pos
    spell.block = Blocks.get('redstone_torch'):withData(event.block.data)
  end
end

player : Player

The player that triggered this event.


replacedBlock : Block

The block that is replaced by this event.