block removal event||doc135417

September 20, 2022

Format

 BLOCK_REMOVED
  • The class to which the function belongs:Block

Description

Triggers an event when a block is removed from the map.


Precautions

  • The removal here is only triggered when a single block is removed, and does not include removing blocks from regions.
  • The removal here is mainlyremoveBlockRemoving a block triggers, breaking a block does not.

Context

The context content of the event

name type Description
pos Vector3 the coordinates of the block
map Map block location map


Code Samples

on the server sideglobal script, register when the brush block is removedCallback, which prints the coordinates where the square was removed

local cfg = Block.GetNameCfg("myplugin/grass")                   --Get the grass block config
Trigger.RegisterHandler(cfg, "BLOCK_REMOVED", function(context)
    local map = context.map
    local pos =  context.pos
    print(" block  removed!",pos)
end)
local map = World.CurWorld:getMap("map001")
map:createBlock({ x = 1, y = 1, z = 1 }, "myplugin/grass")        --Generate blocks
map:removeBlock({ x = 1, y = 1, z = 1 })                          --Remove the block and trigger the removal logic