-
Notifications
You must be signed in to change notification settings - Fork 1
Variables
Macro variables let a command use information from the game when it runs.
For example:
/say I am looking at %targetEntity.getName().getString()%
Variables must be surrounded by % symbols.
The entity you are currently looking directly at.
%targetEntity.getUUID()%
This will not resolve when you are not looking at an entity.
The nearest living, non-spectator entity within 10 blocks.
%nearestEntity.getName().getString()%
The current Minecraft client.
%minecraft.player.getUUID()%
This is intended for more advanced variables.
Variables access Minecraft's actual mapped fields and methods.
A field does not use parentheses:
%minecraft.player%
A method uses parentheses:
%targetEntity.getUUID()%
Methods can be chained together:
%targetEntity.getName().getString()%
Names must match exactly and are case-sensitive. The resolver will not correct spelling or search for a similar name.
getUUID()
is different from:
getUuid()
These variables do not use a custom list of simplified names. They directly use the mapped names from Minecraft's game code.
This means basic variables can be copied from examples in this wiki, while advanced users can access other mapped Minecraft fields and methods.
For example:
%minecraft.player.getUUID()%
accesses the Minecraft client's player field and then calls the player's getUUID() method.
Because these names come from Minecraft itself, some advanced variables may change or stop working after updating to a different Minecraft version.
Methods can accept the following values:
null
5
2.5
"some text"
true
false
Example:
%targetEntity.someMethod(5, 2.5, "Hello", true, null)%
Strings must use double quotes.
A variable can be passed into another method:
%targetEntity.distanceToSqr(%nearestEntity%)%
The nested variable must include its own % symbols.
A command may contain multiple variables:
/tp %nearestEntity.getUUID()% %targetEntity.getUUID()%
Each variable is resolved separately.
If a variable cannot be resolved, it is left unchanged.
For example, when no entity is being targeted:
/say %targetEntity.getUUID()%
will remain unchanged.
A variable may fail when:
- The entity or value is unavailable.
- The field or method does not exist.
- The capitalization is incorrect.
- The method parameters do not match.
- The mapped name changed between Minecraft versions.
Targeted entity's name:
%targetEntity.getName().getString()%
Nearest entity's UUID:
%nearestEntity.getUUID()%
Your UUID:
%minecraft.player.getUUID()%
Distance between two entities:
%targetEntity.distanceToSqr(%nearestEntity%)%