1 Triggers
Victor Westerlund edited this page 2026-08-22 10:25:40 +02:00

Triggers

The trigger: namespace lets datapacks register callbacks for player movement near a point and block placement events.

Triggers are backed by marker entities and scheduled scans. Registered trigger markers can survive reloads, and mcfstd's load functions restart the scans.


Area triggers

Area triggers run callbacks when a player enters or leaves a radius around the position where the trigger was created.

function trigger:area/add { k: "spawn_zone", r: 5, ef: "example:entered_spawn", lf: "example:left_spawn" }

Functions

Function Arguments Purpose
trigger:area/add k, r, ef, lf Add an area trigger at the current position
trigger:area/rm k Remove all loaded area triggers with this key
trigger:area/clear none Remove all area triggers
trigger:area/ls none List loaded area triggers to the caller

Arguments

Argument Type Description
k string Trigger key
r int or float Radius from the trigger position
ef string Enter callback function
lf string Leave callback function

The radius is normalized to a non-negative value internally.

Callback context

Enter and leave callbacks run:

  • as the player who entered or left
  • at that player's position

Example callback:

# data/example/function/entered_spawn.mcfunction
title @s actionbar { text: "Entered spawn", color: "green" }

Enter and leave behavior

mcfstd creates an internal presence marker for each player and area pair. The enter callback fires when no presence marker exists yet. The leave callback fires when that presence marker is not refreshed during a scan.

Removing area triggers

function trigger:area/rm { k: "spawn_zone" }
function trigger:area/clear

trigger:area/rm removes every loaded area marker whose stored key equals k.


Block triggers

Block triggers run callbacks when players place or mine matching blocks.

function trigger:block/add { k: "stone_counter", t: "minecraft.stone", pf: "example:placed_stone", bf: "example:broken_stone" }

Functions

Function Arguments Purpose
trigger:block/add k, t, pf, bf Add a block trigger
trigger:block/rm k Remove all loaded block triggers with this key
trigger:block/clear none Remove all block triggers and dynamic objectives
trigger:block/ls none List loaded block triggers to the caller

Arguments

Argument Type Description
k string Trigger key
t string Block or item statistic target, or "null" for any placed block
pf string Place callback function
bf string Break callback function

For typed triggers, t uses scoreboard statistic syntax such as minecraft.stone.

Typed block triggers

For a typed trigger, mcfstd creates dynamic scoreboard objectives:

Objective pattern Criterion
_tbp_<k> minecraft.used:<t>
_tbb_<k> minecraft.mined:<t>

The scheduled block scan dispatches callbacks as players whose statistic scores changed, then resets those scores.

Any-block placement triggers

Use string literal "null" for t to run a place callback for any block placement:

function trigger:block/add { k: "any_place", t: "null", pf: "example:any_place", bf: "stdout:void" }

Any-block placement is powered by the z_std:block/place advancement, which triggers on minecraft:placed_block.

Placement context

When a placement callback runs, mcfstd temporarily tags a placement context marker as block.

Callbacks can read or execute at that marker:

# Run at the detected placed-block position
execute as @e[type=marker,tag=block,limit=1] at @s run particle minecraft:happy_villager ~ ~ ~ 0 0 0 0 1

The marker is centered on the detected block and inherits the placing player's rotation. The position is found with a short raycast from the player's eyes, so unusual placements, replaceable blocks, or fluids can make it an approximation.

Break callback status

The block trigger API accepts bf, and typed triggers create a minecraft.mined:<t> objective. Minecraft's block-break event support is still limited compared with placement; check behavior in your target game version before relying on break callbacks.

Removing block triggers

function trigger:block/rm { k: "stone_counter" }
function trigger:block/clear

trigger:block/clear removes registry markers, placement context markers, and dynamic block trigger objectives.


Listing triggers

Both trigger systems have list commands:

function trigger:area/ls
function trigger:block/ls

They print loaded triggers to the calling player. The list commands scan the three vanilla dimensions:

  • minecraft:overworld
  • minecraft:the_nether
  • minecraft:the_end