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 |
Below you find short descriptions about each of the properties and some examples about how to use them in your spells.
The hand the player used to place the block. Can be ‘MAIN_HAND’ or ‘OFF_HAND’.
The block against which the new block was placed. Unfortunately the NBT of the block placedAgainst is unavailable in this event.
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
The player that triggered this event.
The block that is replaced by this event.