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.
Exemple:
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:
Limitations
- Macros can only be used in functions.
- Macros aren't variables, they are just text substitutions, you can't do operations on them.
- Macros are not type-checked.
- It would be very difficult and long for Kore to allow macros as any argument of commands because of the wide variety of argument types and contexts in Minecraft commands.
