Macros
Macros recently added support for macros inside functions in Minecraft 1.20.2.
Using Macros
To define a macro, use the macro()
function:
Inside a Minecraft function:
When called, this will substitute the actual text of the macro.
You can also evaluate a list of macros and have fully dynamic commands:
Calling functions with macros
You can call a function with macros by using the new arguments
argument.
That can also be a DataArgument (block position/entity selector/storage).
Defining Macro Classes
For more complex macro usage, you can create a Macros
subclass to define your macros:
Then pass an instance to your function:
Now you can access the macros on the macros
property.
This also allows validating macros that are required when calling the function with an NBT Compound.
Best Practice
When using macros, you can create a function with arguments that calls the function with the macros:
Then you can call this function with your argument as a macro: