touch block event||doc135420

September 20, 2022

Format

 BLOCK_TOUCH
  • The class to which the function belongs:Block

Description

The event is fired when the entity object touches the block.


Context

The context content of the event

name type Description
obj1 Entity entity object
pos Vector3 the coordinates of the block


Code Samples

on the server sideglobal script, register when a grass block is touched by a solid objectCallback, remove the block

local cfg = Block.GetNameCfg("myplugin/grass")         --Get the grass block config
Trigger.RegisterHandler(cfg, "BLOCK_TOUCH", function(context)
    local entity = context.obj1
    local pos =  context.pos
    local map = entity.map                             --Get the current object location map
    map:removeBlock(pos)                               --Remove block
end)