click block event||doc135413

September 20, 2022

Format

 BLOCK_CLICK
  • The class to which the function belongs:Block

Description

The event is triggered when the block is clicked. You need to set the block to be clickable in the editor to trigger the click event.


Precautions

  • When a block is set to be clickable, it will not be possible to place a block by clicking on such block.

Context

The context content of the event

name type Description
obj1 Object clicked object
pos Vector3 block coordinates
map Map Example of a map where a block is located


Code Samples

Set grass block properties

on the server sideglobal script, when the registered grass block is clicked by the playerCallbackbroadcast tipsClicked on the grass block

local cfg = Block.GetNameCfg("myplugin/grass")                   --Get the grass block config
Trigger.RegisterHandler(cfg, "BLOCK_CLICK", function(context)
    local clicker = context.obj1
    World.CurWorld.SystemNotice(1, "click grass block !", 40)    --Broadcast
end)