/function
op 2Technical/function runs every command in an .mcfunction file. From 1.20.2 a function can contain macro lines using $(name), and passing a compound with the with form fills those placeholders in.
Command1 to fix
9
- Function is required.
Press C to copy
Function is required.
optional
Examples
- Run a function
/function my_pack:setup - With macro arguments
/function my_pack:spawn with {mob:"zombie",count:5}
Common questions about /function
›Where do function files go?
In a data pack under data/<namespace>/function/. Older packs used the folder name functions; 1.21 switched it to the singular function.
›How do macros work?
A line starting with $ can contain $(key) placeholders. Call it with /function pack:name with {key:"value"} and the line is rebuilt before it runs.