Commands & .mcfunction
Learn Minecraft command functions, selectors, coordinates, execute, scoreboards, load/tick tags and how DAI dispatches into functions.
A function is a text file full of Minecraft commands.
Instead of typing the same commands manually, save them in .mcfunction. Each non-empty line is executed as a command. Inside a function, do not include the leading slash.
say Hello particle minecraft:happy_villager ~ ~1 ~ 0.2 0.2 0.2 0 6 function my_first_dai:another_function
Function IDs come from paths
File: data/my_first_dai/function/player/heal.mcfunction Function ID: my_first_dai:player/heal Call it: /function my_first_dai:player/heal
Selectors: who does the command affect?
| Selector | Plain meaning |
|---|---|
@s | The current command executor. |
@p | Nearest player. |
@a | All players. |
@e | Entities; normally narrow this with selector arguments. |
Example: effect give @s minecraft:speed 5 0 affects the executor for five seconds.
Coordinates: where?
| Form | Meaning |
|---|---|
10 64 -20 | Absolute world coordinates. |
~ ~ ~ | Relative to current position. |
~ ~1 ~ | One block above current position. |
^ ^ ^1 | Local coordinates relative to facing direction. |
execute: change the context, then run something
execute as @a at @s if block ~ ~-1 ~ minecraft:grass_block run say I am standing on grass
Read it left to right: as every player → at that player's position → if the block below is grass → run the command.
Scoreboards: simple numeric game state
scoreboard objectives add my_score dummy scoreboard players add @s my_score 1 execute if score @s my_score matches 10.. run say Ten or more!
Scoreboards are useful for counters, phases, cooldowns and progression. DAI also has richer state systems; use the simplest authoritative state that fits the feature.
Load functions: run once when data loads
Put the tag at data/minecraft/tags/function/load.json:
{
"values": [
"my_first_dai:load"
]
}Then create data/my_first_dai/function/load.mcfunction:
say My First DAI Project loaded scoreboard objectives add my_first_dai_state dummy
Load is for setup that is safe to repeat after /reload. Avoid granting rewards here unless they are protected against duplication.
Tick functions: run every game tick
Put the tag at data/minecraft/tags/function/tick.json:
{
"values": [
"my_first_dai:tick"
]
}Connect DAI to a function
A DAI logic definition can dispatch a command that calls your function:
{
"type": "sequence",
"sequence": [
{
"type": "run_command",
"action": "function my_first_dai:hello"
}
]
}This is the core bridge: DAI decides when/why → Minecraft function performs authoritative world logic.
Client vs server in beginner terms
Presentation/client
Camera, local input, menus, overlays and visual feedback.
Authority/server
Inventory grants, damage, progression, world edits, costs and persistent state.
If cheating/duplication would matter, the final decision belongs on the authoritative server side.
Checkpoint
You are ready when you can turn a file path into a function ID, call one function from another, and explain the difference between load and tick.