Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Command context: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Remove broken links to missing pages
SyncBot (talk | contribs)
Fix template calls: add MC/ prefix
Line 16: Line 16:
When commands are executed or raw JSON texts are resolved in different scenarios, corresponding contexts are provided, to allow them to work in different scenarios.
When commands are executed or raw JSON texts are resolved in different scenarios, corresponding contexts are provided, to allow them to work in different scenarios.


When running a function with the {{cmd|function}} command, the context for commands inside the function inherits the Executor Parameters, Execution Environment Parameters, and Execution Permission Level from the context of {{cmd|function}} command, while the Execution Output Callback is not inherited. {{IN|java}}, the Execution Permission Level of commands in a function is limited to 2 or below, so, if the {{cmd|function}} command is executed with 2 or higher Execution Permission Level, the command inside the function is executed with Execution Permission Level being 2.
When running a function with the {{MC/Cmd|function}} command, the context for commands inside the function inherits the Executor Parameters, Execution Environment Parameters, and Execution Permission Level from the context of {{MC/Cmd|function}} command, while the Execution Output Callback is not inherited. {{MC/In|java}}, the Execution Permission Level of commands in a function is limited to 2 or below, so, if the {{MC/Cmd|function}} command is executed with 2 or higher Execution Permission Level, the command inside the function is executed with Execution Permission Level being 2.


{{IN|bedrock}}, the context for commands in functions scheduled by {{cmd|schedule}} command also inherits the Executor Parameters, Execution Environment Parameters, and Execution Permission Level from the context of {{cmd|schedule}} command.
{{MC/In|bedrock}}, the context for commands in functions scheduled by {{MC/Cmd|schedule}} command also inherits the Executor Parameters, Execution Environment Parameters, and Execution Permission Level from the context of {{MC/Cmd|schedule}} command.


=== Static values and Dynamic values ===
=== Static values and Dynamic values ===
{{IN|java}}, the Executor Name and each Execution Environment Parameters in a context are '''static''', and each of them exists independently. In other words, if these parameters are not modified with {{cmd|execute}}, they do not change during the command execution, or during the execution of each command in a function. For example, even if the name of the Executor Entity is modified in a function, it does not change the Executor Name in the context of subsequent commands in the function; For another example, for {{cmd|1=execute at @n[type=sheep] run function test}}, even if a {{cmd|tp}} command in a function {{cd|test}} changes the position, rotation, or dimension of the sheep entity, it does not affect the Execution Position, Execution Rotation, and Execution Dimension in the context of subsequent commands in the function, since the values of all these parameters are static after being modified by the {{cd|at}} subcommand and they are no longer related to the sheep entity itself.
{{MC/In|java}}, the Executor Name and each Execution Environment Parameters in a context are '''static''', and each of them exists independently. In other words, if these parameters are not modified with {{MC/Cmd|execute}}, they do not change during the command execution, or during the execution of each command in a function. For example, even if the name of the Executor Entity is modified in a function, it does not change the Executor Name in the context of subsequent commands in the function; For another example, for {{MC/Cmd|1=execute at @n[type=sheep] run function test}}, even if a {{MC/Cmd|tp}} command in a function {{MC/Cd|test}} changes the position, rotation, or dimension of the sheep entity, it does not affect the Execution Position, Execution Rotation, and Execution Dimension in the context of subsequent commands in the function, since the values of all these parameters are static after being modified by the {{MC/Cd|at}} subcommand and they are no longer related to the sheep entity itself.


{{IN|bedrock}} parameter values are static in some cases but '''dynamic''' in other cases. When dynamic, the value of a parameter does not exist independently, but rather it is a reference to an entity and fetches values from the entity in real time. For example, when an Execution Position is dynamic, it depends on an entity and obtains its position in real time, i.e., if the entity is moved in a function, the Execution Position in the context of subsequent commands in the function is the position of the entity after the move.<ref>{{bug|MCPE-179363}}</ref>
{{MC/In|bedrock}} parameter values are static in some cases but '''dynamic''' in other cases. When dynamic, the value of a parameter does not exist independently, but rather it is a reference to an entity and fetches values from the entity in real time. For example, when an Execution Position is dynamic, it depends on an entity and obtains its position in real time, i.e., if the entity is moved in a function, the Execution Position in the context of subsequent commands in the function is the position of the entity after the move.<ref>{{bug|MCPE-179363}}</ref>


Specifically, dynamic values exist in the following cases:
Specifically, dynamic values exist in the following cases:
Line 29: Line 29:
* When a command block minecart executes the command in it, the Execution Position and Execution Rotation are dynamic, referring to this minecart entity.
* When a command block minecart executes the command in it, the Execution Position and Execution Rotation are dynamic, referring to this minecart entity.
* When an entity event response defined in a behavior pack executes a command, or a script executes a command with entity class, or an animation controller in a behavior pack executes a command, or an NPC executes a command, the Executor Name, Execution Position, Execution Rotation, and Execution Dimension are dynamic and referring to the entity.
* When an entity event response defined in a behavior pack executes a command, or a script executes a command with entity class, or an animation controller in a behavior pack executes a command, or an NPC executes a command, the Executor Name, Execution Position, Execution Rotation, and Execution Dimension are dynamic and referring to the entity.
* {{cmd|execute}} command converts the Executor Name to a dynamic value referring to the Executor Entity. That is, when a command is executed in a {{cmd|execute}} command, the Executor Name of it is always dynamic, fetched from the Executor Entity in real time, regardless of whether there is a static Executor Name in the context of the {{cmd|execute}}.
* {{MC/Cmd|execute}} command converts the Executor Name to a dynamic value referring to the Executor Entity. That is, when a command is executed in a {{MC/Cmd|execute}} command, the Executor Name of it is always dynamic, fetched from the Executor Entity in real time, regardless of whether there is a static Executor Name in the context of the {{MC/Cmd|execute}}.
* {{cd|at ...}} and {{cd|positioned as ...}} subcommands in {{cmd|execute}} set the Execution Position to a dynamic value, referring to the specified entity.
* {{MC/Cd|at ...}} and {{MC/Cd|positioned as ...}} subcommands in {{MC/Cmd|execute}} set the Execution Position to a dynamic value, referring to the specified entity.
* {{cd|at ...}} and {{cd|rotated as ...}}  subcommands in {{cmd|execute}} set the Execution Rotation to a dynamic value, referring to the specified entity.
* {{MC/Cd|at ...}} and {{MC/Cd|rotated as ...}}  subcommands in {{MC/Cmd|execute}} set the Execution Rotation to a dynamic value, referring to the specified entity.


If the Execution Position is dynamic, it fetches the position from an entity in real time. But, if this entity is riding on another entity, there is a special treatment:
If the Execution Position is dynamic, it fetches the position from an entity in real time. But, if this entity is riding on another entity, there is a special treatment:
Line 42: Line 42:
* Execution Position defaults to <code>(0, 0, 0)</code>
* Execution Position defaults to <code>(0, 0, 0)</code>
* Execution Rotation defaults to <code>(0, 0)</code>
* Execution Rotation defaults to <code>(0, 0)</code>
For example, when {{cmd|execute run say hi}} is executed in the command block, as mentioned above, the Executor Name converts to a dynamic value by the {{cmd|execute}} command, referring to the Executor Entity. Since there is no Executor Entity in the context, the Executor Name of {{cmd|say hi}} is an empty string.
For example, when {{MC/Cmd|execute run say hi}} is executed in the command block, as mentioned above, the Executor Name converts to a dynamic value by the {{MC/Cmd|execute}} command, referring to the Executor Entity. Since there is no Executor Entity in the context, the Executor Name of {{MC/Cmd|say hi}} is an empty string.


For another example, if the Executor Entity is removed before a function schedule (scheduled by {{cmd|schedule}}) is executed, the schedule cannot be executed because the Execution Dimension is missing in the context.
For another example, if the Executor Entity is removed before a function schedule (scheduled by {{MC/Cmd|schedule}}) is executed, the schedule cannot be executed because the Execution Dimension is missing in the context.


A dynamic value is converted to a static value in the following cases:
A dynamic value is converted to a static value in the following cases:
* {{cmd|execute}} command converts the Execution Dimension to a static value.
* {{MC/Cmd|execute}} command converts the Execution Dimension to a static value.
* {{cmd|execute}} command converts the Execution Rotation to a static value.
* {{MC/Cmd|execute}} command converts the Execution Rotation to a static value.
* {{cd|align ...}} subcommand in {{cmd|execute}} converts the Execution Position to a static value.
* {{MC/Cd|align ...}} subcommand in {{MC/Cmd|execute}} converts the Execution Position to a static value.
* {{cd|in ...}} subcommand in {{cmd|execute}} converts the Execution Position to a static value.
* {{MC/Cd|in ...}} subcommand in {{MC/Cmd|execute}} converts the Execution Position to a static value.
* {{cd|positioned <''coordinates''>}} subcommand in {{cmd|execute}} converts the Execution Position to a static value.
* {{MC/Cd|positioned <''coordinates''>}} subcommand in {{MC/Cmd|execute}} converts the Execution Position to a static value.
* {{cd|facing ...}} subcommand in {{cmd|execute}} converts the Execution Rotation to a static value.
* {{MC/Cd|facing ...}} subcommand in {{MC/Cmd|execute}} converts the Execution Rotation to a static value.
* {{cd|rotated <''angles''>}} subcommand in {{cmd|execute}} converts the Execution Rotation to a static value.
* {{MC/Cd|rotated <''angles''>}} subcommand in {{MC/Cmd|execute}} converts the Execution Rotation to a static value.
* If the Execution Position is a dynamic value, then {{cd|anchored ...}} subcommand in {{cmd|execute}} converts the Execution Position to a static value, being the position at the referred entity's feet or eyes; If the Execution Position is a static value, {{cd|anchored ...}} subcommand does not take any effect.<ref>{{bug|MCPE-162681}} and {{bug|MCPE-165051}}</ref>
* If the Execution Position is a dynamic value, then {{MC/Cd|anchored ...}} subcommand in {{MC/Cmd|execute}} converts the Execution Position to a static value, being the position at the referred entity's feet or eyes; If the Execution Position is a static value, {{MC/Cd|anchored ...}} subcommand does not take any effect.<ref>{{bug|MCPE-162681}} and {{bug|MCPE-165051}}</ref>


For example:
For example:
* When a player executes {{cmd|function ...}} in the chat bar, the Execution Position, Execution Rotation and Execution Dimension of commands in the function are dynamic, referring to the player.
* When a player executes {{MC/Cmd|function ...}} in the chat bar, the Execution Position, Execution Rotation and Execution Dimension of commands in the function are dynamic, referring to the player.
* When a player executes {{cmd|execute run <''command''>}} in the chat bar, the Execution Position of the {{cd|<''command''>}} is dynamic, while the Execution Rotation and Execution Dimension are static.
* When a player executes {{MC/Cmd|execute run <''command''>}} in the chat bar, the Execution Position of the {{MC/Cd|<''command''>}} is dynamic, while the Execution Rotation and Execution Dimension are static.
* When a player executes {{cmd|execute at @s run <''command''>}} in the chat bar, the Execution Position and Execution Rotation of the {{cd|<''command''>}}} are dynamic, while the Execution Dimension is static.
* When a player executes {{MC/Cmd|execute at @s run <''command''>}} in the chat bar, the Execution Position and Execution Rotation of the {{MC/Cd|<''command''>}}} are dynamic, while the Execution Dimension is static.
* When a player executes {{cmd|execute at @s rotated ~ ~ run <''command''>}} in the chat bar, the Execution Position of the {{cd|<''command''>}} is dynamic, while the Execution Rotation and Execution Dimension are static.
* When a player executes {{MC/Cmd|execute at @s rotated ~ ~ run <''command''>}} in the chat bar, the Execution Position of the {{MC/Cd|<''command''>}} is dynamic, while the Execution Rotation and Execution Dimension are static.
* When a player executes {{cmd|execute at @s rotated ~ ~ positioned ~ ~ ~ run <''command''>}} in the chat bar, the Execution Position, Execution Rotation and Execution Dimension of the {{cd|<''command''>}} are all static.
* When a player executes {{MC/Cmd|execute at @s rotated ~ ~ positioned ~ ~ ~ run <''command''>}} in the chat bar, the Execution Position, Execution Rotation and Execution Dimension of the {{MC/Cd|<''command''>}} are all static.
* When a player executes {{cmd|execute positioned ~ ~ ~ run <''command''>}} in the chat bar, the Execution Position, Execution Rotation and Execution Dimension of the {{cd|<''command''>}} are all static.
* When a player executes {{MC/Cmd|execute positioned ~ ~ ~ run <''command''>}} in the chat bar, the Execution Position, Execution Rotation and Execution Dimension of the {{MC/Cd|<''command''>}} are all static.
* If there are at least three entities in a dimension, and a player in the dimension executes {{cmd|1=execute rotated as @e[c=3] run tp @s ~ ~1 ~}} in the chat bar, the player is teleported to 3 blocks above its original position.
* If there are at least three entities in a dimension, and a player in the dimension executes {{MC/Cmd|1=execute rotated as @e[c=3] run tp @s ~ ~1 ~}} in the chat bar, the player is teleported to 3 blocks above its original position.


== Parameters ==
== Parameters ==
=== Execution Permission Level ===
=== Execution Permission Level ===
{{main|Permission level}}
{{MC/Main|Permission level}}
The Execution Permission Level cannot be modified by {{cmd|execute}} command.
The Execution Permission Level cannot be modified by {{MC/Cmd|execute}} command.


{{IN|java}}, in the context of commands in a function called by a {{cmd|function}} command, the Execution Permission Level is limited to 2 or less. If the Execution Permission Level of the {{cmd|function}} command is greater than 2, the commands in the function is executed with Execution Permission Level of 2.
{{MC/In|java}}, in the context of commands in a function called by a {{MC/Cmd|function}} command, the Execution Permission Level is limited to 2 or less. If the Execution Permission Level of the {{MC/Cmd|function}} command is greater than 2, the commands in the function is executed with Execution Permission Level of 2.


=== Executor Parameters ===
=== Executor Parameters ===
There are two Executor Parameters, Executor Name and Executor Entity, where the Executor Entity parameter may be empty (e.g. when a command is executed by a command block). Executor parameters are used in the following scenarios:
There are two Executor Parameters, Executor Name and Executor Entity, where the Executor Entity parameter may be empty (e.g. when a command is executed by a command block). Executor parameters are used in the following scenarios:
* When sending a message using commands such as {{cmd|tell}} or {{cmd|say}}, the Executor Name is used as the sender name of the message.
* When sending a message using commands such as {{MC/Cmd|tell}} or {{MC/Cmd|say}}, the Executor Name is used as the sender name of the message.
* <code>@s</code> target selector directly selects the Executor Entity.
* <code>@s</code> target selector directly selects the Executor Entity.
* By default, the target of commands such as {{cmd|tp}} and {{cmd|kill}} is the Executor Entity.
* By default, the target of commands such as {{MC/Cmd|tp}} and {{MC/Cmd|kill}} is the Executor Entity.
* By default, the target player of commands such as {{cmd|clear}}, {{cmd|gamemode}}, and {{cmd|playsound}} is the Executor Entity, if it is a player entity.
* By default, the target player of commands such as {{MC/Cmd|clear}}, {{MC/Cmd|gamemode}}, and {{MC/Cmd|playsound}} is the Executor Entity, if it is a player entity.
* {{IN|je}}, commands such as {{cmd|trigger}} and {{cmd|teammsg}} take effect on the Executor Entity, if the Executor Entity is a player.
* {{MC/In|je}}, commands such as {{MC/Cmd|trigger}} and {{MC/Cmd|teammsg}} take effect on the Executor Entity, if the Executor Entity is a player.
* {{IN|je}}, [[#Execution Anchor|Execution Anchor]] modifies the Y coordinate based on the eye height of the Executor Entity.
* {{MC/In|je}}, [[#Execution Anchor|Execution Anchor]] modifies the Y coordinate based on the eye height of the Executor Entity.


They can be modified using {{cd|as}}, {{cd|on}}, and {{cd|summon}} subcommands in {{cmd|execute}} command. {{IN|je}}, the Executor Name and Executor Entity are always modified at the same time. {{IN|be}}, only the Executor Entity is modified, and as mentioned above, the Executor Name remains a dynamic value referring to the Executor Entity.
They can be modified using {{MC/Cd|as}}, {{MC/Cd|on}}, and {{MC/Cd|summon}} subcommands in {{MC/Cmd|execute}} command. {{MC/In|je}}, the Executor Name and Executor Entity are always modified at the same time. {{MC/In|be}}, only the Executor Entity is modified, and as mentioned above, the Executor Name remains a dynamic value referring to the Executor Entity.


=== Execution Dimension ===
=== Execution Dimension ===
Line 87: Line 87:
* Whenever [[Minecraft:coordinates]] are specified, the coordinates are specified within the Execution Dimension.
* Whenever [[Minecraft:coordinates]] are specified, the coordinates are specified within the Execution Dimension.
* Target selectors with <code>distance</code>{{only|je|short=1}}, <code>r</code>{{only|be|short=1}}, <code>rm</code>{{only|be|short=1}}, <code>dx</code>, <code>dy</code>, or <code>dz</code> being specified, only entities in the Execution Dimension are selected.
* Target selectors with <code>distance</code>{{only|je|short=1}}, <code>r</code>{{only|be|short=1}}, <code>rm</code>{{only|be|short=1}}, <code>dx</code>, <code>dy</code>, or <code>dz</code> being specified, only entities in the Execution Dimension are selected.
* {{IN|java}}, target selectors with <code>x</code>, <code>y</code>, or <code>z</code> being specified, only entities in the Execution Dimension are selected, too.
* {{MC/In|java}}, target selectors with <code>x</code>, <code>y</code>, or <code>z</code> being specified, only entities in the Execution Dimension are selected, too.
* Commands such as {{cmd|locate}} works within the Execution Dimension.
* Commands such as {{MC/Cmd|locate}} works within the Execution Dimension.


Execution Dimension can be modified using {{cd|at}} and {{cd|in}} subcommands in the {{cmd|execute}} command. {{IN|bedrock}}, the {{cmd|execute}} command itself converts the Execution Dimension to a static value.
Execution Dimension can be modified using {{MC/Cd|at}} and {{MC/Cd|in}} subcommands in the {{MC/Cmd|execute}} command. {{MC/In|bedrock}}, the {{MC/Cmd|execute}} command itself converts the Execution Dimension to a static value.


=== Execution Position ===
=== Execution Position ===
Execution Position is the [[Minecraft:coordinates]] that the command takes effect from. Execution Position is used in the following scenarios:
Execution Position is the [[Minecraft:coordinates]] that the command takes effect from. Execution Position is used in the following scenarios:
* [[Minecraft:Coordinates#Commands|Relative coordinates]] are relative to the Execution Position.
* [[Minecraft:Coordinates#Commands|Relative coordinates]] are relative to the Execution Position.
* {{IN|java}}, the origin of [[Minecraft:Coordinates#Commands|local coordinates]] is based on the Execution Position and affected by the Executor Anchor.
* {{MC/In|java}}, the origin of [[Minecraft:Coordinates#Commands|local coordinates]] is based on the Execution Position and affected by the Executor Anchor.
* {{IN|bedrock}}, the origin of [[Minecraft:Coordinates#Commands|local coordinates]] is the Execution Position.
* {{MC/In|bedrock}}, the origin of [[Minecraft:Coordinates#Commands|local coordinates]] is the Execution Position.
* {{IN|java}}, the start point of {{cmd|execute facing ...}} and {{cmd|tp ... facing ...}} is based on the Execution Position and affected by the Executor Anchor.
* {{MC/In|java}}, the start point of {{MC/Cmd|execute facing ...}} and {{MC/Cmd|tp ... facing ...}} is based on the Execution Position and affected by the Executor Anchor.
* {{IN|bedrock}}, the start point of {{cmd|execute facing ...}} and {{cmd|tp ... facing ...}} is the Execution Position.
* {{MC/In|bedrock}}, the start point of {{MC/Cmd|execute facing ...}} and {{MC/Cmd|tp ... facing ...}} is the Execution Position.
* Commands such as {{cmd|locate}} use the Execution Position as its start point.
* Commands such as {{MC/Cmd|locate}} use the Execution Position as its start point.
* By default, the target position of commands such as {{cmd|locate}} is the Execution Position.
* By default, the target position of commands such as {{MC/Cmd|locate}} is the Execution Position.


Execution Position can be modified using {{cd|align}}, {{cd|at}}, {{cd|positioned}} subcommands in {{cmd|execute}} command, and {{cd|in}} subcommand also affects the Execution Position. {{IN|be}}, {{cd|at}} and {{cd|positioned as}} subcommands set the Execution Position to a dynamic value referring to the specified entity. {{IN|bedrock}}, {{cd|align}}, {{cd|anchored}}, {{cd|in}}, and {{cd|positioned <''coordinates''>}} subcommands convert the Execution Position to a static value.
Execution Position can be modified using {{MC/Cd|align}}, {{MC/Cd|at}}, {{MC/Cd|positioned}} subcommands in {{MC/Cmd|execute}} command, and {{MC/Cd|in}} subcommand also affects the Execution Position. {{MC/In|be}}, {{MC/Cd|at}} and {{MC/Cd|positioned as}} subcommands set the Execution Position to a dynamic value referring to the specified entity. {{MC/In|bedrock}}, {{MC/Cd|align}}, {{MC/Cd|anchored}}, {{MC/Cd|in}}, and {{MC/Cd|positioned <''coordinates''>}} subcommands convert the Execution Position to a static value.


=== Execution Rotation ===
=== Execution Rotation ===
Execution Rotation is the rotation that the command is executed with. Execution Rotation is used in the following scenarios:
Execution Rotation is the rotation that the command is executed with. Execution Rotation is used in the following scenarios:
* The coordinate system of [[Minecraft:Coordinates#Commands|local Coordinates]] is based on the Execution Rotation.
* The coordinate system of [[Minecraft:Coordinates#Commands|local Coordinates]] is based on the Execution Rotation.
* Relative rotation specified with a tilde ({{cd|~}}) in commands such as {{cmd|tp}} and {{cmd|spawnpoint}} is relative to the Execution Rotation.
* Relative rotation specified with a tilde ({{MC/Cd|~}}) in commands such as {{MC/Cmd|tp}} and {{MC/Cmd|spawnpoint}} is relative to the Execution Rotation.


Execution Rotation can be modified using {{cd|at}}, {{cd|facing}}, and {{cd|rotated}} subcommands in the {{cmd|execute}} command. {{IN|be}}, {{cd|as}} and {{cd|rotated as}} subcommands set the Execution Rotation to a dynamic value referring to the specified entity. {{IN|bedrock}}, {{cmd|execute}} command itself and its {{cd|facing}}, {{cd|rotated <''angle''>}} subcommands converts the Execution Rotation to a static value.
Execution Rotation can be modified using {{MC/Cd|at}}, {{MC/Cd|facing}}, and {{MC/Cd|rotated}} subcommands in the {{MC/Cmd|execute}} command. {{MC/In|be}}, {{MC/Cd|as}} and {{MC/Cd|rotated as}} subcommands set the Execution Rotation to a dynamic value referring to the specified entity. {{MC/In|bedrock}}, {{MC/Cmd|execute}} command itself and its {{MC/Cd|facing}}, {{MC/Cd|rotated <''angle''>}} subcommands converts the Execution Rotation to a static value.


=== Execute Anchor ===
=== Execute Anchor ===
{{exclusive|java|section=1}}
{{MC/Exclusive|java|section=1}}
Execute Anchor determines whether the position of eyes or feet of the Executor Entity is used as the origin of local coordinates, and the start point of {{cd|facing}} in {{cmd|teleport}} and of {{cd|facing}} subcommand in {{cmd|execute}}.
Execute Anchor determines whether the position of eyes or feet of the Executor Entity is used as the origin of local coordinates, and the start point of {{MC/Cd|facing}} in {{MC/Cmd|teleport}} and of {{MC/Cd|facing}} subcommand in {{MC/Cmd|execute}}.
* If it is foot, uses the Execution Position directly.
* If it is foot, uses the Execution Position directly.
* If it is eyes, based on the Execution Position, the eye height of the Executor Entity is added into the Y coordinate.
* If it is eyes, based on the Execution Position, the eye height of the Executor Entity is added into the Y coordinate.
Line 119: Line 119:
Execution Anchor are used only in the following scenarios:
Execution Anchor are used only in the following scenarios:
* Local coordinates.
* Local coordinates.
* The start point of {{cd|facing ...}} subcommand in {{cmd|execute}}.
* The start point of {{MC/Cd|facing ...}} subcommand in {{MC/Cmd|execute}}.
* The start point of {{cmd|tp ... facing ...}}.
* The start point of {{MC/Cmd|tp ... facing ...}}.


Execute Anchor can be modified using {{cd|anchored}} subcommand in {{cmd|execute}} command.
Execute Anchor can be modified using {{MC/Cd|anchored}} subcommand in {{MC/Cmd|execute}} command.


Executor Anchor parameter does not exist {{in|be}}. Instead, {{in|be}}, the {{cd|anchored}} subcommand in {{cmd|execute}} directly modifies the Execution Position. If the Execution Position is originally dynamic, the {{cd|anchored}} subcommand converts it to a static value, being the position of feet or eyes of the entity being referred by the dynamic value; If the Execution Position is static, {{cd|anchored}} subcommand does not have any effect at all.
Executor Anchor parameter does not exist {{MC/In|be}}. Instead, {{MC/In|be}}, the {{MC/Cd|anchored}} subcommand in {{MC/Cmd|execute}} directly modifies the Execution Position. If the Execution Position is originally dynamic, the {{MC/Cd|anchored}} subcommand converts it to a static value, being the position of feet or eyes of the entity being referred by the dynamic value; If the Execution Position is static, {{MC/Cd|anchored}} subcommand does not have any effect at all.


=== Execution Output Callback ===
=== Execution Output Callback ===
Line 131: Line 131:
A command executed in a command block, a minecart with command block, or a script{{only|be}} has a callback that sends the success count to the command block or minecart.
A command executed in a command block, a minecart with command block, or a script{{only|be}} has a callback that sends the success count to the command block or minecart.


{{IN|java}}, {{cd|store}} subcommand in {{cmd|execute}} command can be used to add a new callback while the existing callbacks are retained. Existing callbacks cannot be cleared by {{cmd|execute}} command.
{{MC/In|java}}, {{MC/Cd|store}} subcommand in {{MC/Cmd|execute}} command can be used to add a new callback while the existing callbacks are retained. Existing callbacks cannot be cleared by {{MC/Cmd|execute}} command.


The context of commands in a function called by a {{cmd|function}} or {{cmd|schedule}} does not inherit the Execution Output Callbacks of the {{cmd|function}} or {{cmd|schedule}} command.
The context of commands in a function called by a {{MC/Cmd|function}} or {{MC/Cmd|schedule}} does not inherit the Execution Output Callbacks of the {{MC/Cmd|function}} or {{MC/Cmd|schedule}} command.


== Contexts in various scenarios ==
== Contexts in various scenarios ==
Line 150: Line 150:
==== Functions executed by the server-side ====
==== Functions executed by the server-side ====
A function is executed by the server-side when:
A function is executed by the server-side when:
* {{IN|je}}, the function is called via <code>load</code> or <code>tick</code> tags.
* {{MC/In|je}}, the function is called via <code>load</code> or <code>tick</code> tags.
* {{IN|be}}, the function is called via <code>load.json</code> or <code>tick.json</code>.
* {{MC/In|be}}, the function is called via <code>load.json</code> or <code>tick.json</code>.
* {{IN|je}}, the function is scheduled by {{cmd|schedule}} command.
* {{MC/In|je}}, the function is scheduled by {{MC/Cmd|schedule}} command.


The context of commands in a function executed by the server-side is:
The context of commands in a function executed by the server-side is:
Line 165: Line 165:


==== Player ====
==== Player ====
The context of commands that are entered in the chat bar, or requested via a WebSocket server connected with the client {{in|be}}, is:
The context of commands that are entered in the chat bar, or requested via a WebSocket server connected with the client {{MC/In|be}}, is:
* Execution Permission Level: The permission level of the player
* Execution Permission Level: The permission level of the player
* Executor Name: The name of the player; or <code>External</code> for commands requested by a WebSocket {{in|be}}
* Executor Name: The name of the player; or <code>External</code> for commands requested by a WebSocket {{MC/In|be}}
* Executor Entity: The player
* Executor Entity: The player
* Execution Dimension: The dimension the player is in (Dynamic value {{in|bedrock}})
* Execution Dimension: The dimension the player is in (Dynamic value {{MC/In|bedrock}})
* Execution Position: The position of the player (Dynamic value {{in|bedrock}})
* Execution Position: The position of the player (Dynamic value {{MC/In|bedrock}})
* Execution Rotation: The rotation of the player (Dynamic value {{in|bedrock}})
* Execution Rotation: The rotation of the player (Dynamic value {{MC/In|bedrock}})
* Execution Anchor{{only|je|short=1}}: Feet
* Execution Anchor{{only|je|short=1}}: Feet
* Execution Output Callback: None
* Execution Output Callback: None
Line 192: Line 192:
* Executor Entity: The minecart with command block
* Executor Entity: The minecart with command block
* Execution Dimension: The dimension the minecart is in
* Execution Dimension: The dimension the minecart is in
* Execution Position: The position of the minecart (Dynamic value {{in|bedrock}})
* Execution Position: The position of the minecart (Dynamic value {{MC/In|bedrock}})
* Execution Rotation: The rotation of the minecart (Dynamic value {{in|bedrock}})
* Execution Rotation: The rotation of the minecart (Dynamic value {{MC/In|bedrock}})
* Execution Anchor{{only|je|short=1}}: Feet
* Execution Anchor{{only|je|short=1}}: Feet
* Execution Output Callback: Sends the success count to the command block
* Execution Output Callback: Sends the success count to the command block


==== Sign ====
==== Sign ====
{{exclusive|java|section=1}}
{{MC/Exclusive|java|section=1}}
The context of commands executed when a player clicks a [[Minecraft:sign]] block is:
The context of commands executed when a player clicks a [[Minecraft:sign]] block is:
* Execution Permission Level: 2
* Execution Permission Level: 2
Line 210: Line 210:


==== Advancement reward ====
==== Advancement reward ====
{{exclusive|java|section=1}}
{{MC/Exclusive|java|section=1}}
The context of commands in the function called by a {{nbt|string|function}} reward in a custom advancement is:  
The context of commands in the function called by a {{MC/Nbt|string|function}} reward in a custom advancement is:  
* Execution Permission Level: 2
* Execution Permission Level: 2
* Executor Name: The name of the player that gets the advancement
* Executor Name: The name of the player that gets the advancement
Line 222: Line 222:


==== Enchantment effect ====
==== Enchantment effect ====
{{exclusive|java|section=1}}
{{MC/Exclusive|java|section=1}}
The context of commands in the function called by a <code>run_function</code> enchantment effect is:
The context of commands in the function called by a <code>run_function</code> enchantment effect is:
* Execution Permission Level: 2
* Execution Permission Level: 2
Line 234: Line 234:


==== Entity in behavior packs ====
==== Entity in behavior packs ====
{{exclusive|bedrock|section=1}}
{{MC/Exclusive|bedrock|section=1}}


The context of commands executed via an entity event response defined in a behavior pack, or via entity class in a script, or an animation controller in a behavior pack, or a dialogue of an [[Minecraft:NPC]] entity is:
The context of commands executed via an entity event response defined in a behavior pack, or via entity class in a script, or an animation controller in a behavior pack, or a dialogue of an [[Minecraft:NPC]] entity is:
* Execution Permission Level: 1
* Execution Permission Level: 1
* Executor Name: The name of the entity (Dynamic value {{in|bedrock}})
* Executor Name: The name of the entity (Dynamic value {{MC/In|bedrock}})
* Executor Entity: The entity
* Executor Entity: The entity
* Execution Dimension: The dimension the entity is in (Dynamic value {{in|bedrock}})
* Execution Dimension: The dimension the entity is in (Dynamic value {{MC/In|bedrock}})
* Execution Position: The position of the entity (Dynamic value {{in|bedrock}})
* Execution Position: The position of the entity (Dynamic value {{MC/In|bedrock}})
* Execution Rotation: The rotation of the rotation (Dynamic value {{in|bedrock}})
* Execution Rotation: The rotation of the rotation (Dynamic value {{MC/In|bedrock}})
* Execution Output Callback: If via entity class in a script, returns the success count
* Execution Output Callback: If via entity class in a script, returns the success count


==== Dimension in scripts ====
==== Dimension in scripts ====
{{exclusive|bedrock|section=1}}
{{MC/Exclusive|bedrock|section=1}}
The context of commands executed via Dimension class in a script:  
The context of commands executed via Dimension class in a script:  
* Execution Permission Level: 1
* Execution Permission Level: 1
Line 259: Line 259:
When resolving a raw JSON text, relative coordinates, local coordinates, and target selectors in it are resolved based on a command context. The Execution Output Callback parameter in the command context is not used by raw JSON text.
When resolving a raw JSON text, relative coordinates, local coordinates, and target selectors in it are resolved based on a command context. The Execution Output Callback parameter in the command context is not used by raw JSON text.


Note that if the {{nbt|string|name}} field is <code>*</code> in a <code>score</code> type text, the reader's own score is displayed. In addition to the command context, the readers of the raw JSON text are also listed below.
Note that if the {{MC/Nbt|string|name}} field is <code>*</code> in a <code>score</code> type text, the reader's own score is displayed. In addition to the command context, the readers of the raw JSON text are also listed below.


==== Called by a command ====
==== Called by a command ====
A raw JSON text called by a command inherits the context of the command. Including:
A raw JSON text called by a command inherits the context of the command. Including:
* {{cmd|bossbar}}{{only|je}}
* {{MC/Cmd|bossbar}}{{only|je}}
** Reader: None
** Reader: None
* {{cmd|tellraw}}
* {{MC/Cmd|tellraw}}
** Reader: Each player that receives the message
** Reader: Each player that receives the message
* {{cmd|title}}
* {{MC/Cmd|title}}
** Reader: Each player that receives the title
** Reader: Each player that receives the title


==== Written book being opened by a player ====
==== Written book being opened by a player ====
{{exclusive|java|section=1}}
{{MC/Exclusive|java|section=1}}
The context when a written book is being opened by a player is:
The context when a written book is being opened by a player is:
* Execution Permission Level: The permission level of the player
* Execution Permission Level: The permission level of the player
Line 283: Line 283:


==== Written book being placed on a lectern ====
==== Written book being placed on a lectern ====
{{exclusive|java|section=1}}
{{MC/Exclusive|java|section=1}}
The context when a written book is being placed on a [[Minecraft:lectern]] is:
The context when a written book is being placed on a [[Minecraft:lectern]] is:
* Execution Permission Level: 2
* Execution Permission Level: 2
Line 295: Line 295:


==== Sign ====
==== Sign ====
{{exclusive|java|section=1}}
{{MC/Exclusive|java|section=1}}
The context when the text in a [[Minecraft:sign]] block is being changed via NBT is:
The context when the text in a [[Minecraft:sign]] block is being changed via NBT is:
* Execution Permission Level: 2
* Execution Permission Level: 2
Line 307: Line 307:


==== Text display entity ====
==== Text display entity ====
{{exclusive|java|section=1}}
{{MC/Exclusive|java|section=1}}
The context when the text in a text display entity is being changed  
The context when the text in a text display entity is being changed  
* Execution Permission Level: 2
* Execution Permission Level: 2
Line 319: Line 319:


==== Item modifier ====
==== Item modifier ====
{{exclusive|java|section=1}}
{{MC/Exclusive|java|section=1}}
In item modifier, <code>set_name</code> and <code>set_lore</code> functions resolve the raw JSON text only if the entity specified with {{nbt|string|entity}} does exist, with the following context:
In item modifier, <code>set_name</code> and <code>set_lore</code> functions resolve the raw JSON text only if the entity specified with {{MC/Nbt|string|entity}} does exist, with the following context:
* Execution Permission Level: 2
* Execution Permission Level: 2
* Executor Name: The name of the entity specified with {{nbt|string|entity}}
* Executor Name: The name of the entity specified with {{MC/Nbt|string|entity}}
* Executor Entity: The entity specified with {{nbt|string|entity}}
* Executor Entity: The entity specified with {{MC/Nbt|string|entity}}
* Execution Dimension: The dimension that the entity specified with {{nbt|string|entity}} is in
* Execution Dimension: The dimension that the entity specified with {{MC/Nbt|string|entity}} is in
* Execution Position: The position of the entity specified with {{nbt|string|entity}}
* Execution Position: The position of the entity specified with {{MC/Nbt|string|entity}}
* Execution Rotation: The rotation of the entity specified with {{nbt|string|entity}}
* Execution Rotation: The rotation of the entity specified with {{MC/Nbt|string|entity}}
* Execution Anchor: Feet
* Execution Anchor: Feet
* Reader: The entity specified with {{nbt|string|entity}}
* Reader: The entity specified with {{MC/Nbt|string|entity}}


== History ==
== History ==
{{HistoryTable
{{HistoryTable
|{{HistoryLine|java}}
|{{MC/HistoryLine|java}}
|{{HistoryLine||1.13|dev=17w45a|Reworked {{cmd|execute}} command. Now can modify each context parameter independently.
|{{HistoryLine||1.13|dev=17w45a|Reworked {{MC/Cmd|execute}} command. Now can modify each context parameter independently.
|Removed the [[Minecraft:Commands/stats|command stat]] callback in command context.
|Removed the [[Minecraft:Commands/stats|command stat]] callback in command context.
|Added {{cmd|execute store ...}}, allowing to add custom output callbacks into the command context.}}
|Added {{MC/Cmd|execute store ...}}, allowing to add custom output callbacks into the command context.}}
|{{HistoryLine|||dev=18w02a|Added Execution Anchor parameter.
|{{HistoryLine|||dev=18w02a|Added Execution Anchor parameter.
|Added {{cmd|execute anchored ...}}, which can modify the execution anchor.}}
|Added {{MC/Cmd|execute anchored ...}}, which can modify the execution anchor.}}
|{{HistoryLine||1.20|dev=23w16a|Now {{cmd|return}} command sets the return values of a function via command context.}}
|{{HistoryLine||1.20|dev=23w16a|Now {{MC/Cmd|return}} command sets the return values of a function via command context.}}
|{{HistoryLine||1.20.3|dev=23w41a|Now functions called by a {{cmd|function}} command no longer inherit its output callbacks.}}
|{{HistoryLine||1.20.3|dev=23w41a|Now functions called by a {{MC/Cmd|function}} command no longer inherit its output callbacks.}}
|{{HistoryLine|||dev=23w44a|Now {{cmd|return}} command sets the return values of a function via new function system, instead of via command context.}}
|{{HistoryLine|||dev=23w44a|Now {{MC/Cmd|return}} command sets the return values of a function via new function system, instead of via command context.}}


|{{HistoryLine|bedrock}}
|{{MC/HistoryLine|bedrock}}
|{{HistoryLine||1.9.0|dev=beta 1.9.0.2|Commands from command blocks no longer extend to other dimensions.<ref>{{bug|MCPE-33892|||fixed}}</ref>}}
|{{HistoryLine||1.9.0|dev=beta 1.9.0.2|Commands from command blocks no longer extend to other dimensions.<ref>{{bug|MCPE-33892|||fixed}}</ref>}}
|{{HistoryLine||1.13.0|dev=beta 1.13.0.1|Now {{cd|detect}} option in {{cd|/execute}} uses the position and rotation of the executor entity.<ref>{{bug|MCPE-29942|||fixed}}</ref>}}
|{{HistoryLine||1.13.0|dev=beta 1.13.0.1|Now {{MC/Cd|detect}} option in {{MC/Cd|/execute}} uses the position and rotation of the executor entity.<ref>{{bug|MCPE-29942|||fixed}}</ref>}}
|{{HistoryLine||1.16.220|dev=beta 1.16.220.50|Using {{cmd|teleport}} with {{cd|/execute}} command now uses the dimension of the executor entity<ref>{{bug|MCPE-44104|||fixed}}</ref>}}
|{{HistoryLine||1.16.220|dev=beta 1.16.220.50|Using {{MC/Cmd|teleport}} with {{MC/Cd|/execute}} command now uses the dimension of the executor entity<ref>{{bug|MCPE-44104|||fixed}}</ref>}}
|{{HistoryLine||1.19.10|exp=Upcoming Creator Features|dev=Preview 1.19.10.20|Added new {{cmd|execute|link=None}} syntax, which can modify each context parameter independently.}}
|{{HistoryLine||1.19.10|exp=Upcoming Creator Features|dev=Preview 1.19.10.20|Added new {{MC/Cmd|execute|link=None}} syntax, which can modify each context parameter independently.}}
|{{HistoryLine||1.19.50|dev=Preview 1.19.50.23|The new {{cmd|execute|link=none}} syntax is no longer behind the "Upcoming Creator Features" experimental toggle.
|{{HistoryLine||1.19.50|dev=Preview 1.19.50.23|The new {{MC/Cmd|execute|link=none}} syntax is no longer behind the "Upcoming Creator Features" experimental toggle.
|Running {{cmd|execute as}} from Command Blocks no longer inherits rotation from the entity.<ref>{{bug|MCPE-162680|||fixed}}</ref>}}
|Running {{MC/Cmd|execute as}} from Command Blocks no longer inherits rotation from the entity.<ref>{{bug|MCPE-162680|||fixed}}</ref>}}
|{{HistoryLine||1.19.70|dev=beta 1.19.70.20|
|{{HistoryLine||1.19.70|dev=beta 1.19.70.20|
Rotation in the {{cmd|teleport}} command is now relative to the execution rotation instead of the rotation of the target entity.}}
Rotation in the {{MC/Cmd|teleport}} command is now relative to the execution rotation instead of the rotation of the target entity.}}
}}
}}


Line 357: Line 357:


== Navigation ==
== Navigation ==
{{Navbox Java Edition}}
{{MC/Navbox Java Edition}}
{{Navbox Bedrock Edition}}
{{MC/Navbox Bedrock Edition}}


ja:コマンド文脈
ja:コマンド文脈
zh:命令上下文
zh:命令上下文

Revision as of 20:07, 9 April 2026

Command context (also know as execution context, command origin, command source stack) is a set of parameters like the executor and execution environment. It is used to provide context for command execution or raw JSON text resolution.

Behaviors

There are mainly 8Template:Only/7Template:Only parameters in command context:

When commands are executed or raw JSON texts are resolved in different scenarios, corresponding contexts are provided, to allow them to work in different scenarios.

When running a function with the

  1. REDIRECT Template:Command

Template:Redr command, the context for commands inside the function inherits the Executor Parameters, Execution Environment Parameters, and Execution Permission Level from the context of

  1. REDIRECT Template:Command

Template:Redr command, while the Execution Output Callback is not inherited. in Template:Editions, the Execution Permission Level of commands in a function is limited to 2 or below, so, if the

  1. REDIRECT Template:Command

Template:Redr command is executed with 2 or higher Execution Permission Level, the command inside the function is executed with Execution Permission Level being 2.

in Template:Editions, the context for commands in functions scheduled by

  1. REDIRECT Template:Command

Template:Redr command also inherits the Executor Parameters, Execution Environment Parameters, and Execution Permission Level from the context of

  1. REDIRECT Template:Command

Template:Redr command.

Static values and Dynamic values

in Template:Editions, the Executor Name and each Execution Environment Parameters in a context are static, and each of them exists independently. In other words, if these parameters are not modified with

  1. REDIRECT Template:Command

Template:Redr, they do not change during the command execution, or during the execution of each command in a function. For example, even if the name of the Executor Entity is modified in a function, it does not change the Executor Name in the context of subsequent commands in the function; For another example, for

  1. REDIRECT Template:Command

Template:Redr, even if a

  1. REDIRECT Template:Command

Template:Redr command in a function

  1. REDIRECT Template:Code

Template:Redr changes the position, rotation, or dimension of the sheep entity, it does not affect the Execution Position, Execution Rotation, and Execution Dimension in the context of subsequent commands in the function, since the values of all these parameters are static after being modified by the

  1. REDIRECT Template:Code

Template:Redr subcommand and they are no longer related to the sheep entity itself.

in Template:Editions parameter values are static in some cases but dynamic in other cases. When dynamic, the value of a parameter does not exist independently, but rather it is a reference to an entity and fetches values from the entity in real time. For example, when an Execution Position is dynamic, it depends on an entity and obtains its position in real time, i.e., if the entity is moved in a function, the Execution Position in the context of subsequent commands in the function is the position of the entity after the move.<ref>Template:Bug</ref>

Specifically, dynamic values exist in the following cases:

  • When the player executes a command in the chat bar, or a command is requested through a WebSocket server connected with the client, the Execution Position, Execution Rotation, and Execution Dimension are dynamic and referring to the player entity.
  • When a command block minecart executes the command in it, the Execution Position and Execution Rotation are dynamic, referring to this minecart entity.
  • When an entity event response defined in a behavior pack executes a command, or a script executes a command with entity class, or an animation controller in a behavior pack executes a command, or an NPC executes a command, the Executor Name, Execution Position, Execution Rotation, and Execution Dimension are dynamic and referring to the entity.
  1. REDIRECT Template:Command

Template:Redr command converts the Executor Name to a dynamic value referring to the Executor Entity. That is, when a command is executed in a

  1. REDIRECT Template:Command

Template:Redr command, the Executor Name of it is always dynamic, fetched from the Executor Entity in real time, regardless of whether there is a static Executor Name in the context of the

  1. REDIRECT Template:Command

Template:Redr.

  1. REDIRECT Template:Code

Template:Redr and

  1. REDIRECT Template:Code

Template:Redr subcommands in

  1. REDIRECT Template:Command

Template:Redr set the Execution Position to a dynamic value, referring to the specified entity.

  1. REDIRECT Template:Code

Template:Redr and

  1. REDIRECT Template:Code

Template:Redr subcommands in

  1. REDIRECT Template:Command

Template:Redr set the Execution Rotation to a dynamic value, referring to the specified entity.

If the Execution Position is dynamic, it fetches the position from an entity in real time. But, if this entity is riding on another entity, there is a special treatment:

  • If the hitbox bottom of this entity is lower than the hitbox bottom of the mount, the mount's hitbox bottom is used as the Y coordinate of the Execution Position.
    • For example, if a player is riding on a minecart, the player's X and Z coordinates and the minecart's Y coordinate are used as the Execution Position.

If the entity which a dynamic value refers to has been removed from the world (e.g., an armor stand is killed, or a sheep finishes its death animation), the dynamic value cannot be fetched. In this case, default values of parameters are used:

  • Executor Name defaults to an empty string
  • Execution Dimension defaults to empty
  • Execution Position defaults to (0, 0, 0)
  • Execution Rotation defaults to (0, 0)

For example, when

  1. REDIRECT Template:Command

Template:Redr is executed in the command block, as mentioned above, the Executor Name converts to a dynamic value by the

  1. REDIRECT Template:Command

Template:Redr command, referring to the Executor Entity. Since there is no Executor Entity in the context, the Executor Name of

  1. REDIRECT Template:Command

Template:Redr is an empty string.

For another example, if the Executor Entity is removed before a function schedule (scheduled by

  1. REDIRECT Template:Command

Template:Redr) is executed, the schedule cannot be executed because the Execution Dimension is missing in the context.

A dynamic value is converted to a static value in the following cases:

  1. REDIRECT Template:Command

Template:Redr command converts the Execution Dimension to a static value.

  1. REDIRECT Template:Command

Template:Redr command converts the Execution Rotation to a static value.

  1. REDIRECT Template:Code

Template:Redr subcommand in

  1. REDIRECT Template:Command

Template:Redr converts the Execution Position to a static value.

  1. REDIRECT Template:Code

Template:Redr subcommand in

  1. REDIRECT Template:Command

Template:Redr converts the Execution Position to a static value.

  1. REDIRECT Template:Code

Template:Redr subcommand in

  1. REDIRECT Template:Command

Template:Redr converts the Execution Position to a static value.

  1. REDIRECT Template:Code

Template:Redr subcommand in

  1. REDIRECT Template:Command

Template:Redr converts the Execution Rotation to a static value.

  1. REDIRECT Template:Code

Template:Redr subcommand in

  1. REDIRECT Template:Command

Template:Redr converts the Execution Rotation to a static value.

  • If the Execution Position is a dynamic value, then
  1. REDIRECT Template:Code

Template:Redr subcommand in

  1. REDIRECT Template:Command

Template:Redr converts the Execution Position to a static value, being the position at the referred entity's feet or eyes; If the Execution Position is a static value,

  1. REDIRECT Template:Code

Template:Redr subcommand does not take any effect.<ref>Template:Bug and Template:Bug</ref>

For example:

  • When a player executes
  1. REDIRECT Template:Command

Template:Redr in the chat bar, the Execution Position, Execution Rotation and Execution Dimension of commands in the function are dynamic, referring to the player.

  • When a player executes
  1. REDIRECT Template:Command

Template:Redr in the chat bar, the Execution Position of the

  1. REDIRECT Template:Code

Template:Redr is dynamic, while the Execution Rotation and Execution Dimension are static.

  • When a player executes
  1. REDIRECT Template:Command

Template:Redr in the chat bar, the Execution Position and Execution Rotation of the

  1. REDIRECT Template:Code

Template:Redr} are dynamic, while the Execution Dimension is static.

  • When a player executes
  1. REDIRECT Template:Command

Template:Redr in the chat bar, the Execution Position of the

  1. REDIRECT Template:Code

Template:Redr is dynamic, while the Execution Rotation and Execution Dimension are static.

  • When a player executes
  1. REDIRECT Template:Command

Template:Redr in the chat bar, the Execution Position, Execution Rotation and Execution Dimension of the

  1. REDIRECT Template:Code

Template:Redr are all static.

  • When a player executes
  1. REDIRECT Template:Command

Template:Redr in the chat bar, the Execution Position, Execution Rotation and Execution Dimension of the

  1. REDIRECT Template:Code

Template:Redr are all static.

  • If there are at least three entities in a dimension, and a player in the dimension executes
  1. REDIRECT Template:Command

Template:Redr in the chat bar, the player is teleported to 3 blocks above its original position.

Parameters

Execution Permission Level

{{#vardefine:params|0 }}Template:Hatnote The Execution Permission Level cannot be modified by

  1. REDIRECT Template:Command

Template:Redr command.

in Template:Editions, in the context of commands in a function called by a

  1. REDIRECT Template:Command

Template:Redr command, the Execution Permission Level is limited to 2 or less. If the Execution Permission Level of the

  1. REDIRECT Template:Command

Template:Redr command is greater than 2, the commands in the function is executed with Execution Permission Level of 2.

Executor Parameters

There are two Executor Parameters, Executor Name and Executor Entity, where the Executor Entity parameter may be empty (e.g. when a command is executed by a command block). Executor parameters are used in the following scenarios:

  • When sending a message using commands such as
  1. REDIRECT Template:Command

Template:Redr or

  1. REDIRECT Template:Command

Template:Redr, the Executor Name is used as the sender name of the message.

  • @s target selector directly selects the Executor Entity.
  • By default, the target of commands such as
  1. REDIRECT Template:Command

Template:Redr and

  1. REDIRECT Template:Command

Template:Redr is the Executor Entity.

  • By default, the target player of commands such as
  1. REDIRECT Template:Command

Template:Redr,

  1. REDIRECT Template:Command

Template:Redr, and

  1. REDIRECT Template:Command

Template:Redr is the Executor Entity, if it is a player entity.

  1. REDIRECT Template:Command

Template:Redr and

  1. REDIRECT Template:Command

Template:Redr take effect on the Executor Entity, if the Executor Entity is a player.

They can be modified using

  1. REDIRECT Template:Code

Template:Redr,

  1. REDIRECT Template:Code

Template:Redr, and

  1. REDIRECT Template:Code

Template:Redr subcommands in

  1. REDIRECT Template:Command

Template:Redr command. in Template:Editions, the Executor Name and Executor Entity are always modified at the same time. in Template:Editions, only the Executor Entity is modified, and as mentioned above, the Executor Name remains a dynamic value referring to the Executor Entity.

Execution Dimension

Execution Dimension is the Minecraft:dimension in which the command takes effect. Execution Dimension is used in the following scenarios:

  • Whenever Minecraft:coordinates are specified, the coordinates are specified within the Execution Dimension.
  • Target selectors with distanceTemplate:Only, rTemplate:Only, rmTemplate:Only, dx, dy, or dz being specified, only entities in the Execution Dimension are selected.
  • in Template:Editions, target selectors with x, y, or z being specified, only entities in the Execution Dimension are selected, too.
  • Commands such as
  1. REDIRECT Template:Command

Template:Redr works within the Execution Dimension.

Execution Dimension can be modified using

  1. REDIRECT Template:Code

Template:Redr and

  1. REDIRECT Template:Code

Template:Redr subcommands in the

  1. REDIRECT Template:Command

Template:Redr command. in Template:Editions, the

  1. REDIRECT Template:Command

Template:Redr command itself converts the Execution Dimension to a static value.

Execution Position

Execution Position is the Minecraft:coordinates that the command takes effect from. Execution Position is used in the following scenarios:

  1. REDIRECT Template:Command

Template:Redr and

  1. REDIRECT Template:Command

Template:Redr is based on the Execution Position and affected by the Executor Anchor.

  1. REDIRECT Template:Command

Template:Redr and

  1. REDIRECT Template:Command

Template:Redr is the Execution Position.

  • Commands such as
  1. REDIRECT Template:Command

Template:Redr use the Execution Position as its start point.

  • By default, the target position of commands such as
  1. REDIRECT Template:Command

Template:Redr is the Execution Position.

Execution Position can be modified using

  1. REDIRECT Template:Code

Template:Redr,

  1. REDIRECT Template:Code

Template:Redr,

  1. REDIRECT Template:Code

Template:Redr subcommands in

  1. REDIRECT Template:Command

Template:Redr command, and

  1. REDIRECT Template:Code

Template:Redr subcommand also affects the Execution Position. in Template:Editions,

  1. REDIRECT Template:Code

Template:Redr and

  1. REDIRECT Template:Code

Template:Redr subcommands set the Execution Position to a dynamic value referring to the specified entity. in Template:Editions,

  1. REDIRECT Template:Code

Template:Redr,

  1. REDIRECT Template:Code

Template:Redr,

  1. REDIRECT Template:Code

Template:Redr, and

  1. REDIRECT Template:Code

Template:Redr subcommands convert the Execution Position to a static value.

Execution Rotation

Execution Rotation is the rotation that the command is executed with. Execution Rotation is used in the following scenarios:

  • The coordinate system of local Coordinates is based on the Execution Rotation.
  • Relative rotation specified with a tilde (
  1. REDIRECT Template:Code

Template:Redr) in commands such as

  1. REDIRECT Template:Command

Template:Redr and

  1. REDIRECT Template:Command

Template:Redr is relative to the Execution Rotation.

Execution Rotation can be modified using

  1. REDIRECT Template:Code

Template:Redr,

  1. REDIRECT Template:Code

Template:Redr, and

  1. REDIRECT Template:Code

Template:Redr subcommands in the

  1. REDIRECT Template:Command

Template:Redr command. in Template:Editions,

  1. REDIRECT Template:Code

Template:Redr and

  1. REDIRECT Template:Code

Template:Redr subcommands set the Execution Rotation to a dynamic value referring to the specified entity. in Template:Editions,

  1. REDIRECT Template:Command

Template:Redr command itself and its

  1. REDIRECT Template:Code

Template:Redr,

  1. REDIRECT Template:Code

Template:Redr subcommands converts the Execution Rotation to a static value.

Execute Anchor

Script error: No such module "Exclusive". Execute Anchor determines whether the position of eyes or feet of the Executor Entity is used as the origin of local coordinates, and the start point of

  1. REDIRECT Template:Code

Template:Redr in

  1. REDIRECT Template:Command

Template:Redr and of

  1. REDIRECT Template:Code

Template:Redr subcommand in

  1. REDIRECT Template:Command

Template:Redr.

  • If it is foot, uses the Execution Position directly.
  • If it is eyes, based on the Execution Position, the eye height of the Executor Entity is added into the Y coordinate.

Execution Anchor are used only in the following scenarios:

  • Local coordinates.
  • The start point of
  1. REDIRECT Template:Code

Template:Redr subcommand in

  1. REDIRECT Template:Command

Template:Redr.

  • The start point of
  1. REDIRECT Template:Command

Template:Redr.

Execute Anchor can be modified using

  1. REDIRECT Template:Code

Template:Redr subcommand in

  1. REDIRECT Template:Command

Template:Redr command.

Executor Anchor parameter does not exist in Template:Editions. Instead, in Template:Editions, the

  1. REDIRECT Template:Code

Template:Redr subcommand in

  1. REDIRECT Template:Command

Template:Redr directly modifies the Execution Position. If the Execution Position is originally dynamic, the

  1. REDIRECT Template:Code

Template:Redr subcommand converts it to a static value, being the position of feet or eyes of the entity being referred by the dynamic value; If the Execution Position is static,

  1. REDIRECT Template:Code

Template:Redr subcommand does not have any effect at all.

Execution Output Callback

Execution Output Callbacks are used to receive output values of a command.

A command executed in a command block, a minecart with command block, or a scriptTemplate:Only has a callback that sends the success count to the command block or minecart.

in Template:Editions,

  1. REDIRECT Template:Code

Template:Redr subcommand in

  1. REDIRECT Template:Command

Template:Redr command can be used to add a new callback while the existing callbacks are retained. Existing callbacks cannot be cleared by

  1. REDIRECT Template:Command

Template:Redr command.

The context of commands in a function called by a

  1. REDIRECT Template:Command

Template:Redr or

  1. REDIRECT Template:Command

Template:Redr does not inherit the Execution Output Callbacks of the

  1. REDIRECT Template:Command

Template:Redr or

  1. REDIRECT Template:Command

Template:Redr command.

Contexts in various scenarios

Command execution

Server console

The context of commands entered in the server console is:

  • Execution Permission Level: 4
  • Executor Name: Server
  • Executor Entity: None
  • Execution Dimension: Overworld
  • Execution Position: Bottom northwest corner of the block at the Minecraft:world spawnTemplate:Only/(0, 0, 0)Template:Only
  • Execution Rotation: (0, 0)
  • Execution AnchorTemplate:Only: Feet
  • Execution Output Callback: None

Functions executed by the server-side

A function is executed by the server-side when:

  1. REDIRECT Template:Command

Template:Redr command.

The context of commands in a function executed by the server-side is:

Player

The context of commands that are entered in the chat bar, or requested via a WebSocket server connected with the client in Template:Editions, is:

  • Execution Permission Level: The permission level of the player
  • Executor Name: The name of the player; or External for commands requested by a WebSocket in Template:Editions
  • Executor Entity: The player
  • Execution Dimension: The dimension the player is in (Dynamic value in Template:Editions)
  • Execution Position: The position of the player (Dynamic value in Template:Editions)
  • Execution Rotation: The rotation of the player (Dynamic value in Template:Editions)
  • Execution AnchorTemplate:Only: Feet
  • Execution Output Callback: None

Command block

The context of commands that are executed in a command block is:

  • Execution Permission Level: 2Template:Only/1Template:Only
  • Executor Name: The custom name of the command block. If it has no custom name, defaults to @Template:Only/!Template:Only.
  • Executor Entity: None
  • Execution Dimension: The dimension the command block is in
  • Execution Position: The center of the command block
  • Execution Rotation: The rotation of the command blockTemplate:Only/(0, 0)Template:Only
  • Execution AnchorTemplate:Only: Feet
  • Execution Output Callback: Sends the success count to the command block

Minecart with command block

The context of commands that are executed in a minecart with command block is:

  • Execution Permission Level: 2Template:Only/1Template:Only
  • Executor Name: The custom name of the minecart. If it has no custom name, defaults to @Template:Only/!Template:Only.
  • Executor Entity: The minecart with command block
  • Execution Dimension: The dimension the minecart is in
  • Execution Position: The position of the minecart (Dynamic value in Template:Editions)
  • Execution Rotation: The rotation of the minecart (Dynamic value in Template:Editions)
  • Execution AnchorTemplate:Only: Feet
  • Execution Output Callback: Sends the success count to the command block

Sign

Script error: No such module "Exclusive". The context of commands executed when a player clicks a Minecraft:sign block is:

  • Execution Permission Level: 2
  • Executor Name: The name of the player
  • Executor Entity: The player
  • Execution Dimension: The dimension the sign block is in
  • Execution Position: The center of the block the sign is in
  • Execution Rotation: (0, 0)
  • Execution Anchor: Feet
  • Execution Output Callback: None

Advancement reward

Script error: No such module "Exclusive". The context of commands in the function called by a Template:Nbt/sprite function reward in a custom advancement is:

  • Execution Permission Level: 2
  • Executor Name: The name of the player that gets the advancement
  • Executor Entity: The player that gets the advancement
  • Execution Dimension: The dimension the player is in
  • Execution Position: The position of the player
  • Execution Rotation: The rotation of the player
  • Execution Anchor: Feet
  • Execution Output Callback: None

Enchantment effect

Script error: No such module "Exclusive". The context of commands in the function called by a run_function enchantment effect is:

  • Execution Permission Level: 2
  • Executor Name: The name of the affected entity of the enchantment effect
  • Executor Entity: The affected entity of the enchantment effect
  • Execution Dimension: The dimension the enchantment takes effects in
  • Execution Position: The position the enchantment takes effects at
  • Execution Rotation: The rotation of the affected entity of the enchantment effect
  • Execution Anchor: Feet
  • Execution Output Callback: None

Entity in behavior packs

Script error: No such module "Exclusive".

The context of commands executed via an entity event response defined in a behavior pack, or via entity class in a script, or an animation controller in a behavior pack, or a dialogue of an Minecraft:NPC entity is:

  • Execution Permission Level: 1
  • Executor Name: The name of the entity (Dynamic value in Template:Editions)
  • Executor Entity: The entity
  • Execution Dimension: The dimension the entity is in (Dynamic value in Template:Editions)
  • Execution Position: The position of the entity (Dynamic value in Template:Editions)
  • Execution Rotation: The rotation of the rotation (Dynamic value in Template:Editions)
  • Execution Output Callback: If via entity class in a script, returns the success count

Dimension in scripts

Script error: No such module "Exclusive". The context of commands executed via Dimension class in a script:

  • Execution Permission Level: 1
  • Executor Name: Script Engine
  • Executor Entity: None
  • Execution Dimension: The dimension
  • Execution Position: (0, 0, 0)
  • Execution Rotation: (0, 0)
  • Execution Output Callback: Returns the success count

Raw JSON text resolution

When resolving a raw JSON text, relative coordinates, local coordinates, and target selectors in it are resolved based on a command context. The Execution Output Callback parameter in the command context is not used by raw JSON text.

Note that if the Template:Nbt/sprite name field is * in a score type text, the reader's own score is displayed. In addition to the command context, the readers of the raw JSON text are also listed below.

Called by a command

A raw JSON text called by a command inherits the context of the command. Including:

  1. REDIRECT Template:Command

Template:RedrTemplate:Only

    • Reader: None
  1. REDIRECT Template:Command

Template:Redr

    • Reader: Each player that receives the message
  1. REDIRECT Template:Command

Template:Redr

    • Reader: Each player that receives the title

Written book being opened by a player

Script error: No such module "Exclusive". The context when a written book is being opened by a player is:

  • Execution Permission Level: The permission level of the player
  • Executor Name: The name of the player
  • Executor Entity: The player
  • Execution Dimension: The dimension the player is in
  • Execution Position: The position of the player
  • Execution Rotation: The rotation of the player
  • Execution Anchor: Feet
  • Reader: The player

Written book being placed on a lectern

Script error: No such module "Exclusive". The context when a written book is being placed on a Minecraft:lectern is:

  • Execution Permission Level: 2
  • Executor Name: Lectern
  • Executor Entity: None
  • Execution Dimension: The dimension the lectern is in
  • Execution Position: The center of the block the lectern is in
  • Execution Rotation: (0, 0)
  • Execution Anchor: Feet
  • Reader: None

Sign

Script error: No such module "Exclusive". The context when the text in a Minecraft:sign block is being changed via NBT is:

  • Execution Permission Level: 2
  • Executor Name: Sign
  • Executor Entity: None
  • Execution Dimension: The dimension the sign is in
  • Execution Position: The center of the block the sign is in
  • Execution Rotation: (0, 0)
  • Execution Anchor: Feet
  • Reader: None

Text display entity

Script error: No such module "Exclusive". The context when the text in a text display entity is being changed

  • Execution Permission Level: 2
  • Executor Name: The name of the text display entity
  • Executor Entity: The text display entity
  • Execution Dimension: The dimension the text display entity is in
  • Execution Position: The position of the text display entity
  • Execution Rotation: The rotation of the text display entity
  • Execution Anchor: Feet
  • Reader: The text display entity

Item modifier

Script error: No such module "Exclusive". In item modifier, set_name and set_lore functions resolve the raw JSON text only if the entity specified with Template:Nbt/sprite entity does exist, with the following context:

History

Template:HistoryTable

References

<references/>

Navigation

Versions
Development
Version history
Technical

See here for more information

Game customization
Editions
Merged
Ports to consoles
Discontinued
Development
Version history
Technical
Creator
Add-ons
Multiplayer
Exclusive features
Blocks
Mobs
Effects
Unused
Removed

ja:コマンド文脈 zh:命令上下文