block generation event||doc135416

September 20, 2022


  • The class to which the function belongs:Block


Triggers an event when a block is spawned in the map.


  • The generation here does not include the generation of block terrain when the map is initialized, mainly because createBlock will trigger the generation of blocks.
  • And when the block is set to regenerate in the editor, it will trigger when the block is destroyed and regenerated.


The context content of the event

name type Description
pos Vector3 generated coordinates
map Map generated map

Code Samples

on the server sideglobal script, register when the grass block is generatedCallback, print the square to generate coordinates

local cfg = Block.GetNameCfg("myplugin/grass")                --Get the grass block config
Trigger.RegisterHandler(cfg, "BLOCK_SPAWN", function(context)
    local map =
    local pos =  context.pos
    print(" block  spawn!",pos)
local map = World.CurWorld:getMap("map001")
map:createBlock({ x = 1, y = 1, z = 1 }, "myplugin/grass")