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

Minecraft:Commands/execute: 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 7: Line 7:
|others=Cheats only{{only|bedrock|short=1}}
|others=Cheats only{{only|bedrock|short=1}}
}}
}}
{{TOC|right}}
{{MC/Toc|right}}
Executes another command but allows changing the executor, changing the position and angle it is executed at, adding preconditions, and storing its result.
Executes another command but allows changing the executor, changing the position and angle it is executed at, adding preconditions, and storing its result.


Line 24: Line 24:
*All entities are teleported to one block in front of the executor: <code>execute at @s as @e run tp ^ ^ ^1</code>
*All entities are teleported to one block in front of the executor: <code>execute at @s as @e run tp ^ ^ ^1</code>


Some subcommands can '''fork''' the command execution into multiple '''branches''', causing subcommands following it to be executed multiple times. For example, when the {{cd|as}} subcommand selects multiple entities, the subcommands following it execute once per entity.
Some subcommands can '''fork''' the command execution into multiple '''branches''', causing subcommands following it to be executed multiple times. For example, when the {{MC/Cd|as}} subcommand selects multiple entities, the subcommands following it execute once per entity.


If the {{cd|/execute}} command doesn't fork, it has only one branch — '''the main branch'''.
If the {{MC/Cd|/execute}} command doesn't fork, it has only one branch — '''the main branch'''.


A branch may terminate halfway if, for example, the condition in a condition subcommand isn't met, or the {{cd|as}} subcommand selects zero entities. When terminating, a red message is shown.{{only|bedrock|short=1}} If all branches terminate, the <code>/execute</code> command is said to have <em>terminated</em>.
A branch may terminate halfway if, for example, the condition in a condition subcommand isn't met, or the {{MC/Cd|as}} subcommand selects zero entities. When terminating, a red message is shown.{{only|bedrock|short=1}} If all branches terminate, the <code>/execute</code> command is said to have <em>terminated</em>.


Forking is different between {{el|java}} and {{el|bedrock}} (see also {{bug|MC-125067|resolution=Won't Fix}} and {{bug|MCPE-165278|resolution=Unresolved}}):
Forking is different between {{MC/El|java}} and {{MC/El|bedrock}} (see also {{bug|MC-125067|resolution=Won't Fix}} and {{bug|MCPE-165278|resolution=Unresolved}}):
* {{IN|java}}, the game processes subcommands in breadth-first, that is, executes subcommands one by one. So the game processes other subcommands before processing <code>run</code> subcommands, so the <code>run</code> subcommand cannot affect other subcommands.
* {{MC/In|java}}, the game processes subcommands in breadth-first, that is, executes subcommands one by one. So the game processes other subcommands before processing <code>run</code> subcommands, so the <code>run</code> subcommand cannot affect other subcommands.
* {{IN|bedrock}}, the game processes subcommands in depth-first. That is, after forking, all the following subcommands are considered as a whole and are executed once for each branch.
* {{MC/In|bedrock}}, the game processes subcommands in depth-first. That is, after forking, all the following subcommands are considered as a whole and are executed once for each branch.
* For example, when there are two armor stands (A and B) in the world, and a player executes <code>execute as @e[type=armor_stand] as @e[type=armor_stand] run summon armor_stand</code>, the behaviors of {{el|java}} and {{el|bedrock}} are shown in the following pictures:
* For example, when there are two armor stands (A and B) in the world, and a player executes <code>execute as @e[type=armor_stand] as @e[type=armor_stand] run summon armor_stand</code>, the behaviors of {{MC/El|java}} and {{MC/El|bedrock}} are shown in the following pictures:
<gallery>
<gallery>
Execute forking in Java Edition.png|Java Edition
Execute forking in Java Edition.png|Java Edition
Line 43: Line 43:
*<code>execute as @e[type=armor_stand] run execute as @e[type=armor_stand] run execute run execute run summon armor_stand</code>
*<code>execute as @e[type=armor_stand] run execute as @e[type=armor_stand] run execute run execute run summon armor_stand</code>


{{IN|java}}, depth-first can be achieved via {{cmd|function}}, for example:
{{MC/In|java}}, depth-first can be achieved via {{MC/Cmd|function}}, for example:
* When there are two armor stands (A and B) in the world, and a player executes <code>execute as @e[type=armor_stand] run function test</code>, and in the function file is:
* When there are two armor stands (A and B) in the world, and a player executes <code>execute as @e[type=armor_stand] run function test</code>, and in the function file is:
** <code>execute as @e[type=armor_stand] run summon armor_stand</code>
** <code>execute as @e[type=armor_stand] run summon armor_stand</code>
*It behaves like <code>/execute as @e[type=armor_stand] as @e[type=armor_stand] run summon armor_stand</code> in {{el|bedrock}}.
*It behaves like <code>/execute as @e[type=armor_stand] as @e[type=armor_stand] run summon armor_stand</code> in {{MC/El|bedrock}}.
{{IN|bedrock}}, there is no way to achieve breadth-first.
{{MC/In|bedrock}}, there is no way to achieve breadth-first.


=== Output values ===
=== Output values ===
{{main|Commands#Output}}
{{MC/Main|Commands#Output}}
==== Stored values ====
==== Stored values ====
{{exclusive|java|section=1}}
{{MC/Exclusive|java|section=1}}
{{IN|java}}, a branch outputs a <code>success</code> value and a <code>result</code> value (see also [[Minecraft:Commands#Output]]) after it is fully executed (does not terminate halfway). These two output values:
{{MC/In|java}}, a branch outputs a <code>success</code> value and a <code>result</code> value (see also [[Minecraft:Commands#Output]]) after it is fully executed (does not terminate halfway). These two output values:
* Are the outputs of each execution branch, rather than the {{cd|/execute}} command itself;
* Are the outputs of each execution branch, rather than the {{MC/Cd|/execute}} command itself;
* Come from the last subcommand (may be a condition subcommand or a <code>run</code> subcommand).
* Come from the last subcommand (may be a condition subcommand or a <code>run</code> subcommand).
* Both are integers. The <code>success</code> value is always 0 or 1. The <code>result</code> value is rounded down if not an integer.
* Both are integers. The <code>success</code> value is always 0 or 1. The <code>result</code> value is rounded down if not an integer.
Line 60: Line 60:
* The two values can be stored through store subcommands{{only|java}}.
* The two values can be stored through store subcommands{{only|java}}.


Note that these two values are from the conditional subcommand at the end or from the command in the {{cd|run}} subcommand, and are the output values of each branch, rather than of the whole {{cd|/execute}} command.
Note that these two values are from the conditional subcommand at the end or from the command in the {{MC/Cd|run}} subcommand, and are the output values of each branch, rather than of the whole {{MC/Cd|/execute}} command.


If executing {{cmd|function}} command in the {{cd|run}} subcommand, these two output values are not available under certain conditions. See the {{cmd|function}} for details.
If executing {{MC/Cmd|function}} command in the {{MC/Cd|run}} subcommand, these two output values are not available under certain conditions. See the {{MC/Cmd|function}} for details.


If the command execution is forked after a store subcommand, the storage operation is applied on each branch. The output value of each branch is stored after the branch is fully executed. If the store locations are the same between all branches, the output value of a later-executing branch directly overwrites the output value of the earlier-executed branch, rather than being accumulated. So, after the whole {{cd|/execute}} command is executed, the value at this storage location is the output of the last branch executed.
If the command execution is forked after a store subcommand, the storage operation is applied on each branch. The output value of each branch is stored after the branch is fully executed. If the store locations are the same between all branches, the output value of a later-executing branch directly overwrites the output value of the earlier-executed branch, rather than being accumulated. So, after the whole {{MC/Cd|/execute}} command is executed, the value at this storage location is the output of the last branch executed.


==== Success count ====
==== Success count ====
Like most commands, <code>/execute</code> command itself also has a '''[[Minecraft:Commands#Output|success count]]''' (whether or not terminates halfway):
Like most commands, <code>/execute</code> command itself also has a '''[[Minecraft:Commands#Output|success count]]''' (whether or not terminates halfway):
* It is the output value of the {{cd|/execute}} command itself, rather than of each execution branch.
* It is the output value of the {{MC/Cd|/execute}} command itself, rather than of each execution branch.
* It comes from the last subcommand (may be a condition subcommand or a <code>run</code> subcommand).
* It comes from the last subcommand (may be a condition subcommand or a <code>run</code> subcommand).
* The success counts of all branches are summed up.
* The success counts of all branches are summed up.
Line 82: Line 82:
|-
|-
|
|
{{needs update|section=1}}
{{MC/Needs update|section=1}}
[[File:Execute graph.svg]]
[[File:Execute graph.svg]]
|}
|}
Line 159: Line 159:
==== align ====
==== align ====
: Updates the ''execution position'', aligning to its current [[Minecraft:Coordinates#Block position|block position]] (integer coordinates). Applies only along specified axes.
: Updates the ''execution position'', aligning to its current [[Minecraft:Coordinates#Block position|block position]] (integer coordinates). Applies only along specified axes.
: Effectively {{Wikipedia|Floor and ceiling functions|floors|newtab=1}} the coordinates (i.e., {{Wikipedia|rounding|rounds|newtab=1}} the coordinates down)
: Effectively {{MC/Wikipedia|Floor and ceiling functions|floors|newtab=1}} the coordinates (i.e., {{MC/Wikipedia|rounding|rounds|newtab=1}} the coordinates down)
:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>align <axes> -> execute</code>
:: <code>align <axes> -> execute</code>
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code>align <axes: string> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>align <axes: string> <chainedCommand: ExecuteChainedOption_0></code>
:;Arguments
:;Arguments
:: {{Argument|axes|swizzle|axes: string|basic_string}}
:: {{MC/Argument|axes|swizzle|axes: string|basic_string}}
::: {{arg desc|je=swizzle}}
::: {{MC/Arg desc|je=swizzle}}
:;Result
:;Result
:: ''Execution position'' in the given axes are floored, changing by less than 1 block.
:: ''Execution position'' in the given axes are floored, changing by less than 1 block.
Line 178: Line 178:
: Sets the ''execution anchor'' to the eyes or feet. Defaults to feet.
: Sets the ''execution anchor'' to the eyes or feet. Defaults to feet.
: Running <code>positioned <pos> -> execute</code> resets to feet.
: Running <code>positioned <pos> -> execute</code> resets to feet.
: Effectively recenters local coordinates on either the eyes or feet, also changing the angle of the <code>facing</code> subcommand (of {{cmd|execute|link=none}} and {{cmd|teleport}}) works off of.
: Effectively recenters local coordinates on either the eyes or feet, also changing the angle of the <code>facing</code> subcommand (of {{MC/Cmd|execute|link=none}} and {{MC/Cmd|teleport}}) works off of.
: See also {{bug|MCPE-162681}} and {{bug|MCPE-165051}} for issues about {{el|bedrock}}.
: See also {{bug|MCPE-162681}} and {{bug|MCPE-165051}} for issues about {{MC/El|bedrock}}.
:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>anchored <anchor> -> execute</code>
:: <code>anchored <anchor> -> execute</code>
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code>anchored <eyes|feet> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>anchored <eyes|feet> <chainedCommand: ExecuteChainedOption_0></code>
:;Arguments
:;Arguments
Line 193: Line 193:
:: Unparseable if the argument is not specified correctly.
:: Unparseable if the argument is not specified correctly.
:;Example
:;Example
:: The effect of {{Command|tp}} is to move a target by placing its feet at the given position.
:: The effect of {{MC/Command|tp}} is to move a target by placing its feet at the given position.
:: <code>execute anchored eyes run tp ^ ^ ^</code> effectively teleports the executor's feet to where its eyes are.
:: <code>execute anchored eyes run tp ^ ^ ^</code> effectively teleports the executor's feet to where its eyes are.
:: <code>execute anchored eyes run tp ^5 ^ ^</code> means "place the executor's feet 5 blocks left of where its eyes are"
:: <code>execute anchored eyes run tp ^5 ^ ^</code> means "place the executor's feet 5 blocks left of where its eyes are"
Line 200: Line 200:
: Sets the ''executor'' to target entity, without changing ''execution position'', ''rotation'', ''dimension'', and ''anchor''.
: Sets the ''executor'' to target entity, without changing ''execution position'', ''rotation'', ''dimension'', and ''anchor''.
:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>as <targets> -> execute</code>
:: <code>as <targets> -> execute</code>
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code>as <origin: target> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>as <origin: target> <chainedCommand: ExecuteChainedOption_0></code>
:;Arguments
:;Arguments
:: {{Argument|targets|entity|origin: target|CommandSelector<Actor>}}
:: {{MC/Argument|targets|entity|origin: target|CommandSelector<Actor>}}
::: Target entity/entities to become the new executor.
::: Target entity/entities to become the new executor.
::: {{arg desc|je=entity|amount=multiple|type=entities|be=CommandSelector<Actor>}}
::: {{MC/Arg desc|je=entity|amount=multiple|type=entities|be=CommandSelector<Actor>}}
:;Result
:;Result
:: ''Executor'' is updated to target entity (which changes the meaning of <code>@s</code>).
:: ''Executor'' is updated to target entity (which changes the meaning of <code>@s</code>).
Line 220: Line 220:
: Sets the ''execution position'', ''rotation'', and ''dimension'' to match those of an entity; does not change ''executor''.
: Sets the ''execution position'', ''rotation'', and ''dimension'' to match those of an entity; does not change ''executor''.
:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>at <targets> -> execute</code>
:: <code>at <targets> -> execute</code>
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code>at <origin: target> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>at <origin: target> <chainedCommand: ExecuteChainedOption_0></code>
:;Arguments
:;Arguments
:: {{Argument|targets|entity|origin: target|CommandSelector<Actor>}}
:: {{MC/Argument|targets|entity|origin: target|CommandSelector<Actor>}}
::: Target entity/entities to match position, rotation, and dimension with.
::: Target entity/entities to match position, rotation, and dimension with.
::: {{arg desc|je=entity|amount=multiple|type=entities|be=CommandSelector<Actor>}}
::: {{MC/Arg desc|je=entity|amount=multiple|type=entities|be=CommandSelector<Actor>}}
:;Result
:;Result
:: ''Execution position, rotation,'' and ''dimension'' are updated to match target entity.
:: ''Execution position, rotation,'' and ''dimension'' are updated to match target entity.
Line 240: Line 240:
: Sets the ''execution rotation'' to face a given point, as viewed from its anchor (either the eyes or the feet).
: Sets the ''execution rotation'' to face a given point, as viewed from its anchor (either the eyes or the feet).
:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>facing <pos> -> execute</code>
:: <code>facing <pos> -> execute</code>
:: <code>facing entity <targets> <anchor> -> execute</code>
:: <code>facing entity <targets> <anchor> -> execute</code>
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code>facing <position: x y z> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>facing <position: x y z> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>facing entity <origin: target> <eyes|feet> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>facing entity <origin: target> <eyes|feet> <chainedCommand: ExecuteChainedOption_0></code>
:;Arguments
:;Arguments
:: '''Options:''' <code>facing <pos></code> and <code>facing <position: x y z></code>
:: '''Options:''' <code>facing <pos></code> and <code>facing <position: x y z></code>
::: {{Argument|pos|vec3|position: x y z|CommandPositionFloat}}
::: {{MC/Argument|pos|vec3|position: x y z|CommandPositionFloat}}
:::: Coordinates to rotate toward.
:::: Coordinates to rotate toward.
:::: {{arg desc|je=vec3|be=CommandPositionFloat}}
:::: {{MC/Arg desc|je=vec3|be=CommandPositionFloat}}
:: '''Options:''' <code>facing entity <targets> <anchor></code> and <code>facing entity <origin: target> <eyes|feet></code>
:: '''Options:''' <code>facing entity <targets> <anchor></code> and <code>facing entity <origin: target> <eyes|feet></code>
::: {{Argument|targets|entity|origin: target|CommandSelector<Actor>}}
::: {{MC/Argument|targets|entity|origin: target|CommandSelector<Actor>}}
:::: The target(s) to rotate toward.
:::: The target(s) to rotate toward.
:::: {{arg desc|je=entity|amount=multiple|type=entities|be=CommandSelector<Actor>}}
:::: {{MC/Arg desc|je=entity|amount=multiple|type=entities|be=CommandSelector<Actor>}}
::: {{Argument|anchor|entity_anchor|eyes{{!}}feet|enum}}
::: {{Argument|anchor|entity_anchor|eyes{{!}}feet|enum}}
:::: Whether to face the target's ''eyes'' or ''feet''
:::: Whether to face the target's ''eyes'' or ''feet''
Line 273: Line 273:
: It respects dimension scaling for relative and local coordinates: the ''execution position'' (only the X/Z part) is divided by 8 when changing from the Overworld to the Nether, and is multiplied by 8 when vice versa. Applies to custom dimensions as well.
: It respects dimension scaling for relative and local coordinates: the ''execution position'' (only the X/Z part) is divided by 8 when changing from the Overworld to the Nether, and is multiplied by 8 when vice versa. Applies to custom dimensions as well.
:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>in <dimension> -> execute</code>
:: <code>in <dimension> -> execute</code>
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code>in <dimension: Dimension> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>in <dimension: Dimension> <chainedCommand: ExecuteChainedOption_0></code>
:;Arguments
:;Arguments
:: {{Argument|dimension|dimension|dimension: Dimension|enum}}
:: {{MC/Argument|dimension|dimension|dimension: Dimension|enum}}
::: ID of the new execution dimension.
::: ID of the new execution dimension.
::: {{arg desc|je=dimension|be=enum}}
::: {{MC/Arg desc|je=dimension|be=enum}}
:;Result
:;Result
:: ''Execution dimension'' and ''position'' is updated.
:: ''Execution dimension'' and ''position'' is updated.
Line 288: Line 288:
:::* <code>execute '''in minecraft:the_end''' run locate structure minecraft:end_city</code>{{only|java}}
:::* <code>execute '''in minecraft:the_end''' run locate structure minecraft:end_city</code>{{only|java}}
:::* <code>execute '''in the_end''' run locate structure end_city</code>{{only|bedrock}}
:::* <code>execute '''in the_end''' run locate structure end_city</code>{{only|bedrock}}
:: If a player at position {{cd|(16,64,16)}} in Overworld runs the following command, the player is teleported to {{cd|(16,64,16)}} in the Nether:
:: If a player at position {{MC/Cd|(16,64,16)}} in Overworld runs the following command, the player is teleported to {{MC/Cd|(16,64,16)}} in the Nether:
:::* <code>execute '''in minecraft:the_nether''' positioned as @s run tp ~ ~ ~</code>{{only|java}}
:::* <code>execute '''in minecraft:the_nether''' positioned as @s run tp ~ ~ ~</code>{{only|java}}
:::* <code>execute '''in nether''' positioned as @s run tp ~ ~ ~</code>{{only|bedrock}}
:::* <code>execute '''in nether''' positioned as @s run tp ~ ~ ~</code>{{only|bedrock}}
:: If a player at position {{cd|(16,64,16)}} in Overworld runs the following command, the player is teleported to {{cd|(2,64,2)}} in the Nether.
:: If a player at position {{MC/Cd|(16,64,16)}} in Overworld runs the following command, the player is teleported to {{MC/Cd|(2,64,2)}} in the Nether.
:::* <code>execute '''in minecraft:the_nether''' run tp ~ ~ ~</code>{{only|java}}
:::* <code>execute '''in minecraft:the_nether''' run tp ~ ~ ~</code>{{only|java}}
:::* <code>execute '''in nether''' run tp ~ ~ ~</code>{{only|bedrock}}
:::* <code>execute '''in nether''' run tp ~ ~ ~</code>{{only|bedrock}}
:: If a player at position {{cd|(80,64,80)}} in Overworld runs the following command, the player is teleported to {{cd|(10,64,15)}} in the Nether.
:: If a player at position {{MC/Cd|(80,64,80)}} in Overworld runs the following command, the player is teleported to {{MC/Cd|(10,64,15)}} in the Nether.
::* <code>execute '''in minecraft:the_nether''' run tp ~ ~ ~5</code>{{only|java}}
::* <code>execute '''in minecraft:the_nether''' run tp ~ ~ ~5</code>{{only|java}}
::* <code>execute '''in nether''' run tp ~ ~ ~5</code>{{only|bedrock}}
::* <code>execute '''in nether''' run tp ~ ~ ~5</code>{{only|bedrock}}


==== on ====
==== on ====
{{exclusive|section=1|java}}
{{MC/Exclusive|section=1|java}}
: Updates the ''executor'' to entities selected based on relation to the current executor entity. without changing ''execution position'', ''rotation'', ''dimension'', and ''anchor''.
: Updates the ''executor'' to entities selected based on relation to the current executor entity. without changing ''execution position'', ''rotation'', ''dimension'', and ''anchor''.
:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>on <''relation''> -> execute</code>
:: <code>on <''relation''> -> execute</code>
:;Arguments
:;Arguments
:: {{el|je|short=1}}: {{Argument|''relation''|}}
:: {{MC/El|je|short=1}}: {{MC/Argument|''relation''|}}
::: A relation to the current executor entity.
::: A relation to the current executor entity.
:::* <code>attacker</code>: the last entity that damaged the current executor entity in the previous 5 seconds. Note that damage types in <code>minecraft:no_anger</code> tag bypass the record of attacker. Interaction entities do not forget attacker after 5 seconds. Some mobs forget the attacker when ceasing their aggression.
:::* <code>attacker</code>: the last entity that damaged the current executor entity in the previous 5 seconds. Note that damage types in <code>minecraft:no_anger</code> tag bypass the record of attacker. Interaction entities do not forget attacker after 5 seconds. Some mobs forget the attacker when ceasing their aggression.
Line 327: Line 327:
: Sets the ''execution position'', without changing ''execution rotation'' or ''dimension''; can match an entity's position, or at one block above the Y-level stored in the specified heightmap{{only|java|short=1}}.
: Sets the ''execution position'', without changing ''execution rotation'' or ''dimension''; can match an entity's position, or at one block above the Y-level stored in the specified heightmap{{only|java|short=1}}.
:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>positioned <pos> -> execute</code>
:: <code>positioned <pos> -> execute</code>
:: <code>positioned as <targets> -> execute</code>
:: <code>positioned as <targets> -> execute</code>
:: <code>positioned over <heightmap> -> execute</code>
:: <code>positioned over <heightmap> -> execute</code>
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code>positioned <position: x y z> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>positioned <position: x y z> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>positioned as <origin: target> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>positioned as <origin: target> <chainedCommand: ExecuteChainedOption_0></code>
:;Arguments
:;Arguments
:: '''Option:''' <code>positioned <pos></code> or <code>positioned <position: x y z></code>
:: '''Option:''' <code>positioned <pos></code> or <code>positioned <position: x y z></code>
::: {{Argument|pos|vec3|position: x y z|CommandPositionFloat}}
::: {{MC/Argument|pos|vec3|position: x y z|CommandPositionFloat}}
:::: New position.
:::: New position.
:::: {{arg desc|je=vec3|be=CommandPositionFloat}}
:::: {{MC/Arg desc|je=vec3|be=CommandPositionFloat}}
:: '''Option:''' <code>positioned as <targets></code> or <code>positioned as <origin: target></code>
:: '''Option:''' <code>positioned as <targets></code> or <code>positioned as <origin: target></code>
::: {{Argument|targets|entity|origin: target|CommandSelector<Actor>}}
::: {{MC/Argument|targets|entity|origin: target|CommandSelector<Actor>}}
:::: Target entity/entities to match position with.
:::: Target entity/entities to match position with.
:::: {{arg desc|je=entity|amount=multiple|type=entities|be=CommandSelector<Actor>}}
:::: {{MC/Arg desc|je=entity|amount=multiple|type=entities|be=CommandSelector<Actor>}}
:: '''Option:''' <code>positioned over <heightmap></code>
:: '''Option:''' <code>positioned over <heightmap></code>
::: {{el|je|short=1}}: {{Argument|heightmap|heightmap}}
::: {{MC/El|je|short=1}}: {{MC/Argument|heightmap|heightmap}}
:::: Specifies the heightmap.
:::: Specifies the heightmap.
:::: Must be one of <code>world_surface</code>, <code>motion_blocking</code>, <code>motion_blocking_no_leaves</code>, and <code>ocean_floor</code>.
:::: Must be one of <code>world_surface</code>, <code>motion_blocking</code>, <code>motion_blocking_no_leaves</code>, and <code>ocean_floor</code>.
Line 360: Line 360:
: Sets the ''execution rotation''; can match an entity's rotation.
: Sets the ''execution rotation''; can match an entity's rotation.
:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>rotated <rot> -> execute</code>
:: <code>rotated <rot> -> execute</code>
:: <code>rotated as <targets> -> execute</code>
:: <code>rotated as <targets> -> execute</code>
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code>rotated <yaw: value> <pitch: value> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>rotated <yaw: value> <pitch: value> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>rotated as <origin: target> <chainedCommand: ExecuteChainedOption_0></code>
:: <code>rotated as <origin: target> <chainedCommand: ExecuteChainedOption_0></code>
:;Arguments
:;Arguments
:: '''Option:''' <code>rotated <rot></code> or <code>rotated <yaw: value> <pitch: value></code>
:: '''Option:''' <code>rotated <rot></code> or <code>rotated <yaw: value> <pitch: value></code>
::: {{el|je|short=1}}: {{Argument|rot|rotation}} (<code><yaw> <pitch></code>)
::: {{MC/El|je|short=1}}: {{MC/Argument|rot|rotation}} (<code><yaw> <pitch></code>)
::: {{el|be|short=1}}: {{Argument|be=1|yaw: value|RelativeFloat}} and {{Argument|be=1|pitch: value|RelativeFloat}}
::: {{MC/El|be|short=1}}: {{MC/Argument|be=1|yaw: value|RelativeFloat}} and {{MC/Argument|be=1|pitch: value|RelativeFloat}}
:::: Angles of rotation.
:::: Angles of rotation.
:::: {{arg desc|je=rotation|be=RelativeFloat}}
:::: {{MC/Arg desc|je=rotation|be=RelativeFloat}}
:: '''Option:''' <code>rotated as <targets></code> or <code>rotated as <origin: target></code>
:: '''Option:''' <code>rotated as <targets></code> or <code>rotated as <origin: target></code>
::: {{Argument|targets|entity|origin: target|CommandSelector<Actor>}}
::: {{MC/Argument|targets|entity|origin: target|CommandSelector<Actor>}}
:::: Target entity/entities to match rotation with.
:::: Target entity/entities to match rotation with.
:::: {{arg desc|je=entity|amount=multiple|type=entities|be=CommandSelector<Actor>}}
:::: {{MC/Arg desc|je=entity|amount=multiple|type=entities|be=CommandSelector<Actor>}}
:;Result
:;Result
:: ''Execution rotation'' is updated.
:: ''Execution rotation'' is updated.
Line 387: Line 387:


==== summon ====
==== summon ====
{{exclusive|section=1|java}}
{{MC/Exclusive|section=1|java}}
: ''Summons'' a new entity at execution position and changes the ''executor'' to this summoned entity.
: ''Summons'' a new entity at execution position and changes the ''executor'' to this summoned entity.
:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>summon <entity> -> execute</code>
:: <code>summon <entity> -> execute</code>
:;Arguments
:;Arguments
:: {{el|je|short=1}}: {{Argument|entity|resource}}
:: {{MC/El|je|short=1}}: {{MC/Argument|entity|resource}}
::: The entity to be summoned and become the new executor.
::: The entity to be summoned and become the new executor.
::: {{arg desc|je=resource|registry=minecraft:entity_type}}
::: {{MC/Arg desc|je=resource|registry=minecraft:entity_type}}
:;Result
:;Result
:: ''Summons'' the entity and changes the ''executor''.
:: ''Summons'' the entity and changes the ''executor''.
:: Unparseable if the argument is not specified correctly.
:: Unparseable if the argument is not specified correctly.
:: Terminates current branch if execution position's <x> or <z> exceeds the range of [-30000000, 30000000), or <y> exceeds the range of [-20000000, 20000000).
:: Terminates current branch if execution position's <x> or <z> exceeds the range of [-30000000, 30000000), or <y> exceeds the range of [-20000000, 20000000).
:: Terminates the whole {{cmd|execute|link=none}} command if the specified entity is <code>minecraft:player</code> or <code>minecraft:fishing_bobber</code>.
:: Terminates the whole {{MC/Cmd|execute|link=none}} command if the specified entity is <code>minecraft:player</code> or <code>minecraft:fishing_bobber</code>.
:;Example
:;Example
:: Summon a sheep with the tag "Test": <code>execute '''summon sheep''' run tag ''@s'' add Test</code>
:: Summon a sheep with the tag "Test": <code>execute '''summon sheep''' run tag ''@s'' add Test</code>
:: Summon a block display entiy and scale it: <code>execute '''summon block_display''' run data merge entity ''@s'' {transformation:{scale:[4.0,4.0,4.0]},block_state:{Name:"minecraft:dirt"}}</code>
:: Summon a block display entiy and scale it: <code>execute '''summon block_display''' run data merge entity ''@s'' {transformation:{scale:[4.0,4.0,4.0]},block_state:{Name:"minecraft:dirt"}}</code>


{{Anchor|if}}{{Anchor|unless}}
{{MC/Anchor|if}}{{MC/Anchor|unless}}


=== Condition subcommands ===
=== Condition subcommands ===
Line 414: Line 414:
: In some cases, for example, testing a block outside the world, both <code>if</code> and <code>unless</code> terminates or fails.
: In some cases, for example, testing a block outside the world, both <code>if</code> and <code>unless</code> terminates or fails.
: When not at the end of the subcommands chain, only if the condition tests pass does the branch continue; otherwise it terminates.
: When not at the end of the subcommands chain, only if the condition tests pass does the branch continue; otherwise it terminates.
:: {{IN|java}}, if it is executed in multiple branches, it acts as a context filter (only branches with contexts that match the condition continue).
:: {{MC/In|java}}, if it is executed in multiple branches, it acts as a context filter (only branches with contexts that match the condition continue).
: When at the end of the subcommands chain, it checks whether the condition is met and then outputs. {{IN|java}}, it has output values that can be stored by store subcommands.
: When at the end of the subcommands chain, it checks whether the condition is met and then outputs. {{MC/In|java}}, it has output values that can be stored by store subcommands.


There are eleven{{only|java|short=1}} / four{{only|bedrock|short=1}} different types of conditions:
There are eleven{{only|java|short=1}} / four{{only|bedrock|short=1}} different types of conditions:
Line 430: Line 430:
# [[#ifunlessscore|(if|unless) score]] - Tests a target's score
# [[#ifunlessscore|(if|unless) score]] - Tests a target's score


{{anchor|ifunlessbiome}}
{{MC/Anchor|ifunlessbiome}}


==== (if|unless) biome ====
==== (if|unless) biome ====
{{exclusive|section=1|java}}
{{MC/Exclusive|section=1|java}}
: Checks for a specific biome in a given position.  
: Checks for a specific biome in a given position.  
:;Syntax
:;Syntax
Line 439: Line 439:


:;Arguments
:;Arguments
:: {{Argument|pos|block_pos}}
:: {{MC/Argument|pos|block_pos}}
::: Position to test.
::: Position to test.
::: {{arg desc|je=block_pos}}
::: {{MC/Arg desc|je=block_pos}}
:: {{Argument|biome|resource_or_tag}}
:: {{MC/Argument|biome|resource_or_tag}}
::: Biome(s) to test for.
::: Biome(s) to test for.
::: {{arg desc|je=resource_or_tag|registry=minecraft:worldgen/biome}}
::: {{MC/Arg desc|je=resource_or_tag|registry=minecraft:worldgen/biome}}


:;Result
:;Result
Line 453: Line 453:
:: When at the end of the subcommand chain, if the command is successful, both <code>success</code> value and <code>result</code> value are 1.
:: When at the end of the subcommand chain, if the command is successful, both <code>success</code> value and <code>result</code> value are 1.


{{anchor|ifunlessblock}}
{{MC/Anchor|ifunlessblock}}


==== (if|unless) block ====
==== (if|unless) block ====
Line 459: Line 459:


:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>(if|unless) '''block''' <pos> <block> -> [execute]</code>
:: <code>(if|unless) '''block''' <pos> <block> -> [execute]</code>
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code><subcommand: Option_If_Unless> '''block''' <position: x y z> <block: Block> [chainedCommand: ExecuteChainedOption_0]</code>
:: <code><subcommand: Option_If_Unless> '''block''' <position: x y z> <block: Block> [chainedCommand: ExecuteChainedOption_0]</code>
:: <code><subcommand: Option_If_Unless> '''block''' <position: x y z> <block: Block> <blockStates: block states> [chainedCommand: ExecuteChainedOption_0]</code>
:: <code><subcommand: Option_If_Unless> '''block''' <position: x y z> <block: Block> <blockStates: block states> [chainedCommand: ExecuteChainedOption_0]</code>


:;Arguments
:;Arguments
:: {{Argument|pos|block_pos|position: x y z|CommandPosition}}
:: {{MC/Argument|pos|block_pos|position: x y z|CommandPosition}}
::: Position of a target block to test.
::: Position of a target block to test.
::: {{arg desc|je=block_pos|be=CommandPosition}}
::: {{MC/Arg desc|je=block_pos|be=CommandPosition}}
:: {{Argument|block|block_predicate|block: Block|enum}}
:: {{MC/Argument|block|block_predicate|block: Block|enum}}
::: Specifies the block to test for.
::: Specifies the block to test for.
::: {{arg desc|je=block_predicate|be=Block}}
::: {{MC/Arg desc|je=block_predicate|be=Block}}
:: {{el|bedrock|short=1}}: {{Argument|be=1|blockStates: block states|BlockStateCommandParam}}
:: {{MC/El|bedrock|short=1}}: {{MC/Argument|be=1|blockStates: block states|BlockStateCommandParam}}
::: Specifies the block state for the specified block to test for.
::: Specifies the block state for the specified block to test for.
::: {{arg desc|be=BlockStateCommandParam}}
::: {{MC/Arg desc|be=BlockStateCommandParam}}


:;Result
:;Result
Line 481: Line 481:
::* If <code><pos></code> or <code>position: x y z</code> is unloaded or out of the world.
::* If <code><pos></code> or <code>position: x y z</code> is unloaded or out of the world.
::* If test doesn't pass.
::* If test doesn't pass.
:: {{IN|java}}, when at the end of the subcommand chain, if the command is successful, both <code>success</code> value and <code>result</code> value are 1.
:: {{MC/In|java}}, when at the end of the subcommand chain, if the command is successful, both <code>success</code> value and <code>result</code> value are 1.


{{anchor|ifunlessblocks}}
{{MC/Anchor|ifunlessblocks}}


==== (if|unless) blocks ====
==== (if|unless) blocks ====
Line 489: Line 489:


:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>(if|unless) '''blocks''' <start> <end> <destination> (all|masked) -> [execute]</code>
:: <code>(if|unless) '''blocks''' <start> <end> <destination> (all|masked) -> [execute]</code>
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code><subcommand: Option_If_Unless> '''blocks''' <begin: x y z> <end: x y z> <destination: x y z> <scan mode: BlocksScanMode> [chainedCommand: ExecuteChainedOption_0]</code>
:: <code><subcommand: Option_If_Unless> '''blocks''' <begin: x y z> <end: x y z> <destination: x y z> <scan mode: BlocksScanMode> [chainedCommand: ExecuteChainedOption_0]</code>


:;Arguments
:;Arguments
:: {{Argument|start|block_pos|begin: x y z|CommandPosition}}
:: {{MC/Argument|start|block_pos|begin: x y z|CommandPosition}}
:: {{Argument|end|block_pos|end: x y z|CommandPosition}}
:: {{MC/Argument|end|block_pos|end: x y z|CommandPosition}}
::: Positions of any two diagonal corners of the source volume (the volume to compare).
::: Positions of any two diagonal corners of the source volume (the volume to compare).
::: {{arg desc|je=block_pos|be=CommandPosition}}
::: {{MC/Arg desc|je=block_pos|be=CommandPosition}}
:: {{Argument|destination|block_pos|destination: x y z|CommandPosition}}  
:: {{MC/Argument|destination|block_pos|destination: x y z|CommandPosition}}  
::: Position of the lower northwest corner of the destination volume (the volume to compare to).
::: Position of the lower northwest corner of the destination volume (the volume to compare to).
::: Assumed to be of the same size as the source volume
::: Assumed to be of the same size as the source volume
::: {{arg desc|je=block_pos|be=CommandPosition}}
::: {{MC/Arg desc|je=block_pos|be=CommandPosition}}
:: {{el|je|short=1}}: {{code|(all{{!}}masked)}}
:: {{MC/El|je|short=1}}: {{code|(all{{!}}masked)}}
:: {{el|be|short=1}}: {{Argument|be=1|scan mode: BlocksScanMode|enum}}
:: {{MC/El|be|short=1}}: {{MC/Argument|be=1|scan mode: BlocksScanMode|enum}}
::: Specifies whether ''all'' blocks in the source volume should be compared, or if air blocks should be ''masked/ignored''.
::: Specifies whether ''all'' blocks in the source volume should be compared, or if air blocks should be ''masked/ignored''.
::: Must be either <code>all</code> or <code>masked</code>.
::: Must be either <code>all</code> or <code>masked</code>.
Line 514: Line 514:
::* If the volume of the source region is greater than 32768 (the equivalent of 8 chunk sections).
::* If the volume of the source region is greater than 32768 (the equivalent of 8 chunk sections).
::* If test doesn't pass.
::* If test doesn't pass.
:: {{IN|java}}, when at the end of the subcommand chain, if the command is successful:
:: {{MC/In|java}}, when at the end of the subcommand chain, if the command is successful:
::: The <code>success</code> value is 1.
::: The <code>success</code> value is 1.
::: For <code>if</code> mode, <code>result</code> value is the number of matching blocks (the total number of blocks in <code>all</code> mode, or the number of source region non-air blocks in <code>masked</code> mode).
::: For <code>if</code> mode, <code>result</code> value is the number of matching blocks (the total number of blocks in <code>all</code> mode, or the number of source region non-air blocks in <code>masked</code> mode).
::: For <code>unless</code> mode, <code>result</code> value is 1.
::: For <code>unless</code> mode, <code>result</code> value is 1.


{{Anchor|ifunlessdata}}
{{MC/Anchor|ifunlessdata}}


==== (if|unless) data ====
==== (if|unless) data ====
{{exclusive|section=1|java}}
{{MC/Exclusive|section=1|java}}
: Checks whether the targeted block, entity or storage has any data tag for a given path.
: Checks whether the targeted block, entity or storage has any data tag for a given path.


Line 532: Line 532:
:; Arguments
:; Arguments
:: '''Option:''' <code>(if|unless) data '''block <pos> <path>'''</code>
:: '''Option:''' <code>(if|unless) data '''block <pos> <path>'''</code>
::: {{Argument|pos|block_pos}}
::: {{MC/Argument|pos|block_pos}}
:::: Position of the block for data testing.
:::: Position of the block for data testing.
:::: {{arg desc|je=block_pos}}
:::: {{MC/Arg desc|je=block_pos}}
::: {{Argument|path|nbt_path}}
::: {{MC/Argument|path|nbt_path}}
:::: Data path to check whether the block has.
:::: Data path to check whether the block has.
:::: {{arg desc|je=nbt_path}}
:::: {{MC/Arg desc|je=nbt_path}}
:: '''Option:''' <code>(if|unless) data '''entity <target> <path>'''</code>
:: '''Option:''' <code>(if|unless) data '''entity <target> <path>'''</code>
::: {{Argument|target|entity}}
::: {{MC/Argument|target|entity}}
:::: A single entity for data testing.
:::: A single entity for data testing.
:::: {{Arg desc|je=entity|amount=single|type=entities}}
:::: {{MC/Arg desc|je=entity|amount=single|type=entities}}
::: {{Argument|path|nbt_path}}
::: {{MC/Argument|path|nbt_path}}
:::: Data path to check whether the entity has.
:::: Data path to check whether the entity has.
:::: {{arg desc|je=nbt_path}}
:::: {{MC/Arg desc|je=nbt_path}}
:: '''Option:''' <code>(if|unless) data '''storage <source> <path>'''</code>
:: '''Option:''' <code>(if|unless) data '''storage <source> <path>'''</code>
::: {{Argument|source|resource_location}}
::: {{MC/Argument|source|resource_location}}
:::: The resource location of the storage for data testing.
:::: The resource location of the storage for data testing.
:::: {{arg desc|je=resource_location}}
:::: {{MC/Arg desc|je=resource_location}}
::: {{Argument|path|nbt_path}}
::: {{MC/Argument|path|nbt_path}}
:::: Data path to check whether the storage has.
:::: Data path to check whether the storage has.
:::: {{arg desc|je=nbt_path}}
:::: {{MC/Arg desc|je=nbt_path}}


:;Result
:;Result
Line 565: Line 565:
::: For <code>unless</code> mode, <code>result</code> value is 1.
::: For <code>unless</code> mode, <code>result</code> value is 1.


{{anchor|ifunlessdimension}}
{{MC/Anchor|ifunlessdimension}}


==== (if|unless) dimension ====
==== (if|unless) dimension ====
{{exclusive|section=1|java}}
{{MC/Exclusive|section=1|java}}
: Checks if the execution is in a matching dimension.
: Checks if the execution is in a matching dimension.


Line 575: Line 575:


:;Arguments
:;Arguments
:: {{Argument|dimension|dimension}}
:: {{MC/Argument|dimension|dimension}}
::: Dimension to test for.
::: Dimension to test for.
::: {{arg desc|je=dimension}}
::: {{MC/Arg desc|je=dimension}}
:;Result
:;Result
:: Unparseable if the argument is not specified correctly.
:: Unparseable if the argument is not specified correctly.
Line 584: Line 584:
:: When at the end of the subcommand chain, if the command is successful, both <code>success</code> value and <code>result</code> value are 1.
:: When at the end of the subcommand chain, if the command is successful, both <code>success</code> value and <code>result</code> value are 1.


{{anchor|ifunlessentity}}
{{MC/Anchor|ifunlessentity}}


==== (if|unless) entity ====
==== (if|unless) entity ====
Line 590: Line 590:


:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>(if|unless) '''entity''' <entities> -> [execute]</code>
:: <code>(if|unless) '''entity''' <entities> -> [execute]</code>
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code><subcommand: Option_If_Unless> '''entity''' <target: target> [chainedCommand: ExecuteChainedOption_0]</code>
:: <code><subcommand: Option_If_Unless> '''entity''' <target: target> [chainedCommand: ExecuteChainedOption_0]</code>
:;Arguments
:;Arguments
:: {{Argument|entities|entity|target: target|CommandSelector<Actor>}}
:: {{MC/Argument|entities|entity|target: target|CommandSelector<Actor>}}
::: The target entity/ies to test for.
::: The target entity/ies to test for.
::: {{arg desc|je=entity|amount=multiple|type=entities|be=CommandSelector<Actor>}}
::: {{MC/Arg desc|je=entity|amount=multiple|type=entities|be=CommandSelector<Actor>}}
:;Result
:;Result
:: Unparseable if the argument is not specified correctly.
:: Unparseable if the argument is not specified correctly.
:: In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
:: In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
::* If test doesn't pass.
::* If test doesn't pass.
:: {{IN|java}}, when at the end of the subcommand chain, if the command is successful:
:: {{MC/In|java}}, when at the end of the subcommand chain, if the command is successful:
::: The <code>success</code> value is 1.
::: The <code>success</code> value is 1.
::: For <code>if</code> mode, <code>result</code> value is the number of matching entities.
::: For <code>if</code> mode, <code>result</code> value is the number of matching entities.
::: For <code>unless</code> mode, <code>result</code> value is 1.
::: For <code>unless</code> mode, <code>result</code> value is 1.


{{anchor|ifunlessfunction}}
{{MC/Anchor|ifunlessfunction}}
==== (if|unless) function ====
==== (if|unless) function ====
{{exclusive|section=1|java}}
{{MC/Exclusive|section=1|java}}
: Checks if function(s) are non-void and the return value is non-zero. Terminates current branch unless the function's return value is non-zero. Doesn't change any execution context.
: Checks if function(s) are non-void and the return value is non-zero. Terminates current branch unless the function's return value is non-zero. Doesn't change any execution context.
: Unlike other conditional subcommands, this subcommand can modify the world depending on the function(s) that are tested. It also cannot be placed at the end of the subcommand chain.<ref>{{bug|MC-267799|||Invalid}}</ref>
: Unlike other conditional subcommands, this subcommand can modify the world depending on the function(s) that are tested. It also cannot be placed at the end of the subcommand chain.<ref>{{bug|MC-267799|||Invalid}}</ref>
Line 617: Line 617:


:;Arguments
:;Arguments
:: {{Argument|function|function}}
:: {{MC/Argument|function|function}}
::: Function to test for.
::: Function to test for.
::: {{arg desc|je=function}}
::: {{MC/Arg desc|je=function}}


:;Result
:;Result
Line 632: Line 632:
::* If a function returns a success and its return value is not 0: Ends this subcommand execution, and <code>if</code> does nothing and <code>unless</code> terminates current branch.
::* If a function returns a success and its return value is not 0: Ends this subcommand execution, and <code>if</code> does nothing and <code>unless</code> terminates current branch.


{{anchor|ifunlessitems}}
{{MC/Anchor|ifunlessitems}}


==== (if|unless) items ====
==== (if|unless) items ====
{{exclusive|section=1|java}}
{{MC/Exclusive|section=1|java}}
: Checks for a matching item in the provided inventory [[Minecraft:slot]]s.
: Checks for a matching item in the provided inventory [[Minecraft:slot]]s.


Line 643: Line 643:


:; Arguments
:; Arguments
:: {{Argument|sourcePos|block_pos}}
:: {{MC/Argument|sourcePos|block_pos}}
::: Location of a block entity to test.
::: Location of a block entity to test.
::: {{arg desc|je=block_pos}}
::: {{MC/Arg desc|je=block_pos}}
:: {{Argument|source|entity}}
:: {{MC/Argument|source|entity}}
::: Entity to test.
::: Entity to test.
::: {{arg desc|je=entity}}
::: {{MC/Arg desc|je=entity}}
:: {{Argument|slots|item_slots}}
:: {{MC/Argument|slots|item_slots}}
::: Slots to test. A string that consists of a "slot type" and an optional "slot number", in the format of <code><slot_type></code>, <code><slot_type>.<slot_number></code> or <code><slot_type>.*</code>. See [[Minecraft:Slot]] for details.
::: Slots to test. A string that consists of a "slot type" and an optional "slot number", in the format of <code><slot_type></code>, <code><slot_type>.<slot_number></code> or <code><slot_type>.*</code>. See [[Minecraft:Slot]] for details.
:: {{Argument|item_predicate|item_predicate}}
:: {{MC/Argument|item_predicate|item_predicate}}
::: Item or item tag to test for.
::: Item or item tag to test for.
::: {{arg desc|je=item_predicate}}
::: {{MC/Arg desc|je=item_predicate}}


:; Result
:; Result
Line 666: Line 666:
:::For <code>if</code> mode, <code>result</code> value is the number of matching items.
:::For <code>if</code> mode, <code>result</code> value is the number of matching items.
:::For <code>unless</code> mode, <code>result</code> value is 1.
:::For <code>unless</code> mode, <code>result</code> value is 1.
{{anchor|ifunlessloaded}}
{{MC/Anchor|ifunlessloaded}}


==== (if|unless) loaded ====
==== (if|unless) loaded ====
{{exclusive|section=1|java}}
{{MC/Exclusive|section=1|java}}
: Checks if chunks at a given position is fully loaded (Entity Ticking).
: Checks if chunks at a given position is fully loaded (Entity Ticking).


Line 675: Line 675:
:: <code>(if|unless) '''loaded''' <pos> -> [execute]</code>
:: <code>(if|unless) '''loaded''' <pos> -> [execute]</code>
:;Arguments
:;Arguments
:: {{Argument|pos|block_pos}}
:: {{MC/Argument|pos|block_pos}}
::: Position to test
::: Position to test
::: {{arg desc|je=block_pos}}
::: {{MC/Arg desc|je=block_pos}}


:;Result
:;Result
Line 686: Line 686:
:: When at the end of the subcommand chain, if the command is successful, both <code>success</code> value and <code>result</code> value are 1.
:: When at the end of the subcommand chain, if the command is successful, both <code>success</code> value and <code>result</code> value are 1.


{{anchor|ifunlesspredicate}}
{{MC/Anchor|ifunlesspredicate}}


==== (if|unless) predicate ====
==== (if|unless) predicate ====
{{exclusive|section=1|java}}
{{MC/Exclusive|section=1|java}}
: Checks whether the predicate successes. See Predicate for more information.
: Checks whether the predicate successes. See Predicate for more information.


Line 695: Line 695:
:: <code>(if|unless) '''predicate''' <predicate> -> [execute]</code>
:: <code>(if|unless) '''predicate''' <predicate> -> [execute]</code>
:;Arguments
:;Arguments
:: {{Argument|predicate|resource_location}} or inline definition
:: {{MC/Argument|predicate|resource_location}} or inline definition
::: The predicate to be checked whether it evaluates to a positive result.
::: The predicate to be checked whether it evaluates to a positive result.
::: Must either be a resource location or an inline definition, following the same structure as predicates encoded in the SNBT format.  
::: Must either be a resource location or an inline definition, following the same structure as predicates encoded in the SNBT format.  
Line 707: Line 707:
:: When at the end of the subcommand chain, if the command is successful, both <code>success</code> value and <code>result</code> value are 1.
:: When at the end of the subcommand chain, if the command is successful, both <code>success</code> value and <code>result</code> value are 1.


{{anchor|ifunlessscore}}
{{MC/Anchor|ifunlessscore}}
==== (if|unless) score ====
==== (if|unless) score ====
: Check whether a score has the specific relation to another score, or whether it is in a given range.
: Check whether a score has the specific relation to another score, or whether it is in a given range.


:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>(if|unless) '''score''' <target> <targetObjective> (<|<=|=|>=|>) <source> <sourceObjective> -> [execute]</code> – for comparing two scores
:: <code>(if|unless) '''score''' <target> <targetObjective> (<|<=|=|>=|>) <source> <sourceObjective> -> [execute]</code> – for comparing two scores
:: <code>(if|unless) '''score''' <target> <targetObjective> matches <range> -> [execute]</code> – for comparing one score against a range
:: <code>(if|unless) '''score''' <target> <targetObjective> matches <range> -> [execute]</code> – for comparing one score against a range
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code><subcommand: Option_If_Unless> '''score''' <target: target> <objective: string> <operation: compare operator> <source: target> <objective: string> [chainedCommand: ExecuteChainedOption_0]</code> - for comparing two scores
:: <code><subcommand: Option_If_Unless> '''score''' <target: target> <objective: string> <operation: compare operator> <source: target> <objective: string> [chainedCommand: ExecuteChainedOption_0]</code> - for comparing two scores
:: <code><subcommand: Option_If_Unless> '''score''' <target: target> <objective: string> matches <range: integer range> [chainedCommand: ExecuteChainedOption_0]</code> - for comparing one score against a range
:: <code><subcommand: Option_If_Unless> '''score''' <target: target> <objective: string> matches <range: integer range> [chainedCommand: ExecuteChainedOption_0]</code> - for comparing one score against a range


:;Arguments
:;Arguments
:: {{Argument|target|score_holder|target: target|CommandSelector<Actor>}}
:: {{MC/Argument|target|score_holder|target: target|CommandSelector<Actor>}}
::: A single score holder.
::: A single score holder.
::: {{IN|java}}, {{lcfirst:{{arg desc|je=score_holder}}}}
::: {{MC/In|java}}, {{lcfirst:{{MC/Arg desc|je=score_holder}}}}
::: {{IN|bedrock}}, {{lcfirst:{{arg desc|be=CommandSelector<Actor>}}}} It can also be quoted unique id to specified non-player entities in the objective.
::: {{MC/In|bedrock}}, {{lcfirst:{{MC/Arg desc|be=CommandSelector<Actor>}}}} It can also be quoted unique id to specified non-player entities in the objective.
:: {{Argument|targetObjective|objective|objective: string|basic_string}}
:: {{MC/Argument|targetObjective|objective|objective: string|basic_string}}
::: The scoreboard objective to check under. The score of <target> or <target: target> in this objective is checked.
::: The scoreboard objective to check under. The score of <target> or <target: target> in this objective is checked.
::: {{arg desc|je=objective|be=basic_string}}
::: {{MC/Arg desc|je=objective|be=basic_string}}
:: '''Option:''' <code>(if|unless) score ... '''(<|<=|=|>=|>)''' ...</code> or <code><subcommand: Option_If_Unless> score ... '''<operation: compare operator>''' ...</code>
:: '''Option:''' <code>(if|unless) score ... '''(<|<=|=|>=|>)''' ...</code> or <code><subcommand: Option_If_Unless> score ... '''<operation: compare operator>''' ...</code>
::: {{el|java|short=1}}: <code>(<|<=|=|>=|>)</code>
::: {{MC/El|java|short=1}}: <code>(<|<=|=|>=|>)</code>
::: {{el|bedrock|short=1}}: {{Argument|be=1|operation: compare operator|CommandCompareOperator}}
::: {{MC/El|bedrock|short=1}}: {{MC/Argument|be=1|operation: compare operator|CommandCompareOperator}}
:::: Specifies a compare operator.
:::: Specifies a compare operator.
:::: Must be one of <code><</code>, <code><=</code>, <code>=</code>, <code>>=</code>, and <code>></code>.
:::: Must be one of <code><</code>, <code><=</code>, <code>=</code>, <code>>=</code>, and <code>></code>.
::: {{Argument|source|score_holder|source: target|CommandSelector<Actor>}}
::: {{MC/Argument|source|score_holder|source: target|CommandSelector<Actor>}}
:::: A single score holder to compare against.
:::: A single score holder to compare against.
:::: {{IN|java}}, {{lcfirst:{{arg desc|je=score_holder}}}}
:::: {{MC/In|java}}, {{lcfirst:{{MC/Arg desc|je=score_holder}}}}
:::: {{IN|bedrock}}, {{lcfirst:{{arg desc|be=CommandSelector<Actor>}}}} It can also be quoted unique id to specified non-player entities in the objective.
:::: {{MC/In|bedrock}}, {{lcfirst:{{MC/Arg desc|be=CommandSelector<Actor>}}}} It can also be quoted unique id to specified non-player entities in the objective.
::: {{Argument|sourceObjective|objective|objective: string|basic_string}}
::: {{MC/Argument|sourceObjective|objective|objective: string|basic_string}}
:::: A scoreboard objective. The score of <source> or <source: target> in this objective is checked.
:::: A scoreboard objective. The score of <source> or <source: target> in this objective is checked.
:::: {{arg desc|je=objective|be=basic_string}}
:::: {{MC/Arg desc|je=objective|be=basic_string}}
:: '''Option:''' <code>(if|unless) score ... '''matches''' ...</code> or <code><subcommand: Option_If_Unless> score ... '''matches''' ...</code>
:: '''Option:''' <code>(if|unless) score ... '''matches''' ...</code> or <code><subcommand: Option_If_Unless> score ... '''matches''' ...</code>
::: {{Argument|range|int_range|range: integer range|CommandIntegerRange}}
::: {{MC/Argument|range|int_range|range: integer range|CommandIntegerRange}}
:::: Range to compare score against.
:::: Range to compare score against.
:::: {{arg desc|je=int_range|be=CommandIntegerRange}}
:::: {{MC/Arg desc|je=int_range|be=CommandIntegerRange}}


:;Result
:;Result
:: Unparseable if the argument is not specified correctly.
:: Unparseable if the argument is not specified correctly.
:: In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
:: In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
::* {{IN|java}}, if <code><target></code> / <code>target: target</code> or <code><source></code> / <code>source: target</code> is <code>*</code>.
::* {{MC/In|java}}, if <code><target></code> / <code>target: target</code> or <code><source></code> / <code>source: target</code> is <code>*</code>.
::* If test doesn't pass.
::* If test doesn't pass.
:: {{IN|java}}, when at the end of the subcommand chain, if the command is successful, both <code>success</code> value and <code>result</code> value are 1.
:: {{MC/In|java}}, when at the end of the subcommand chain, if the command is successful, both <code>success</code> value and <code>result</code> value are 1.


==== Example ====
==== Example ====
Line 757: Line 757:
: Check whether scores A and B are equal: <code>execute '''if score @s A = @s B'''</code>
: Check whether scores A and B are equal: <code>execute '''if score @s A = @s B'''</code>


{{anchor|store}}
{{MC/Anchor|store}}


=== Store subcommand ===
=== Store subcommand ===
{{Exclusive|Java|section=1}}
{{MC/Exclusive|Java|section=1}}
Stores the final subcommand's <code>result</code> or <code>success</code> value somewhere. It is first processed along with other subcommands in the subcommand chain, recording the location to store in. After the last subcommand (may be a condition subcommand or a <code>run</code> subcommand) is executed, output values are stored in the recorded location. Note that the output values of commands are always an integer. If not, they are rounded down.
Stores the final subcommand's <code>result</code> or <code>success</code> value somewhere. It is first processed along with other subcommands in the subcommand chain, recording the location to store in. After the last subcommand (may be a condition subcommand or a <code>run</code> subcommand) is executed, output values are stored in the recorded location. Note that the output values of commands are always an integer. If not, they are rounded down.


Line 770: Line 770:
# [[#storestorage|store (result|success) storage]] – Stores output value under one of a storage's NBTs
# [[#storestorage|store (result|success) storage]] – Stores output value under one of a storage's NBTs


{{Anchor|storeblock}}
{{MC/Anchor|storeblock}}
==== store (result|success) block ====
==== store (result|success) block ====
: Saves the final command's output value as tag data within a block entity. Store as a byte, short, int, long, float, or double. If the output value is a decimal, it is rounded first and then multiplied by <code><scale></code>.
: Saves the final command's output value as tag data within a block entity. Store as a byte, short, int, long, float, or double. If the output value is a decimal, it is rounded first and then multiplied by <code><scale></code>.
Line 778: Line 778:


:;Arguments
:;Arguments
:: {{Argument|targetPos|block_pos}}
:: {{MC/Argument|targetPos|block_pos}}
::: Position of target block.
::: Position of target block.
::: {{arg desc|je=block_pos}}
::: {{MC/Arg desc|je=block_pos}}
:: {{Argument|path|nbt_path}}
:: {{MC/Argument|path|nbt_path}}
::: Location of the desired tag to hold the value in.
::: Location of the desired tag to hold the value in.
:: {{code|<''type''>}}
:: {{MC/Code|<''type''>}}
::: Desired data size/type.
::: Desired data size/type.
::: Must be one of <code>byte</code>, <code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, and <code>double</code>.
::: Must be one of <code>byte</code>, <code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, and <code>double</code>.
:: {{Argument|scale|double}}
:: {{MC/Argument|scale|double}}
::: Multiplier to apply before storing value, may be negative.
::: Multiplier to apply before storing value, may be negative.
::: {{arg desc|je=double}}
::: {{MC/Arg desc|je=double}}


:;Result
:;Result
:: Unparseable if the argument is not specified correctly.
:: Unparseable if the argument is not specified correctly.


{{Anchor|storebossbar}}
{{MC/Anchor|storebossbar}}
==== store (result|success) bossbar ====
==== store (result|success) bossbar ====
: Saves the final command's output value in either a bossbar's current value or its maximum value
: Saves the final command's output value in either a bossbar's current value or its maximum value
Line 800: Line 800:
:: <code>store (result|success) '''bossbar''' <id> (value|max) -> execute</code>
:: <code>store (result|success) '''bossbar''' <id> (value|max) -> execute</code>
:;Arguments
:;Arguments
:: {{Argument|id|resource_location}}
:: {{MC/Argument|id|resource_location}}
::: ID of the bossbar to target for saving.
::: ID of the bossbar to target for saving.
::: {{arg desc|je=resource_location}}
::: {{MC/Arg desc|je=resource_location}}
:: {{code|value{{!}}max}}
:: {{code|value{{!}}max}}
::: Whether to overwrite the bossbar's ''current value'' or its ''max value''<!--TODO-->
::: Whether to overwrite the bossbar's ''current value'' or its ''max value''<!--TODO-->
Line 808: Line 808:
:: Unparseable if the argument is not specified correctly.
:: Unparseable if the argument is not specified correctly.


{{Anchor|storeentity}}
{{MC/Anchor|storeentity}}
==== store (result|success) entity ====
==== store (result|success) entity ====
: Save the final command's output value in one of an entity's data tags. Store as a byte, short, int, long, float, or double. If the output value is a decimal, it is rounded first and then multiplied by <code><scale></code>. Like the {{cmd|data}} command, "/execute store" cannot modify player NBT.
: Save the final command's output value in one of an entity's data tags. Store as a byte, short, int, long, float, or double. If the output value is a decimal, it is rounded first and then multiplied by <code><scale></code>. Like the {{MC/Cmd|data}} command, "/execute store" cannot modify player NBT.


:;Syntax
:;Syntax
Line 816: Line 816:


:;Arguments
:;Arguments
:: {{Argument|target|entity}}
:: {{MC/Argument|target|entity}}
::: A single entity to store under.
::: A single entity to store under.
::: {{arg desc|je=entity|amount=single|type=entities}}
::: {{MC/Arg desc|je=entity|amount=single|type=entities}}
:: {{Argument|path|nbt_path}}
:: {{MC/Argument|path|nbt_path}}
::: Location of the desired tag to hold the value in.
::: Location of the desired tag to hold the value in.
:: {{code|<''type''>}}
:: {{MC/Code|<''type''>}}
::: Desired data size/type
::: Desired data size/type
::: Must be one of <code>byte</code>, <code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, and <code>double</code>.
::: Must be one of <code>byte</code>, <code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, and <code>double</code>.
:: {{Argument|scale|double}}
:: {{MC/Argument|scale|double}}
::: Multiplier to apply before storing value, may be negative.
::: Multiplier to apply before storing value, may be negative.
::: {{arg desc|je=double}}
::: {{MC/Arg desc|je=double}}
:;Result
:;Result
:: Unparseable if the argument is not specified correctly.
:: Unparseable if the argument is not specified correctly.


{{Anchor|storescore}}
{{MC/Anchor|storescore}}


==== store (result|success) score ====
==== store (result|success) score ====
Line 839: Line 839:


:;Arguments
:;Arguments
:: {{Argument|targets|score_holder}}
:: {{MC/Argument|targets|score_holder}}
::: Specifies score holder(s) whose score is to be overridden.
::: Specifies score holder(s) whose score is to be overridden.
::: {{arg desc|je=score_holder}}
::: {{MC/Arg desc|je=score_holder}}
:: {{Argument|objective|objective}}
:: {{MC/Argument|objective|objective}}
::: A scoreboard objective.
::: A scoreboard objective.
::: {{arg desc|je=objective}}
::: {{MC/Arg desc|je=objective}}
:;Result
:;Result
:: Unparseable if the argument is not specified correctly.
:: Unparseable if the argument is not specified correctly.


{{Anchor|storestorage}}
{{MC/Anchor|storestorage}}


==== store (result|success) storage ====
==== store (result|success) storage ====
: Uses the {{cd|<path>}} within storage {{cd|<target>}} to store the output value in. Store as a byte, short, int, long, float, or double. If the output value is a decimal, it is rounded first and then multiplied by {{cd|<scale>}}. If the storage does not yet exist, it gets created.
: Uses the {{MC/Cd|<path>}} within storage {{MC/Cd|<target>}} to store the output value in. Store as a byte, short, int, long, float, or double. If the output value is a decimal, it is rounded first and then multiplied by {{MC/Cd|<scale>}}. If the storage does not yet exist, it gets created.


:;Syntax
:;Syntax
Line 857: Line 857:


:;Arguments
:;Arguments
:: {{Argument|target|resource_location}}
:: {{MC/Argument|target|resource_location}}
::: Target storage container, as a resource location.
::: Target storage container, as a resource location.
::: {{arg desc|je=resource_location}}
::: {{MC/Arg desc|je=resource_location}}
:: {{Argument|path|nbt_path}}
:: {{MC/Argument|path|nbt_path}}
::: Location of the desired tag to hold the value in.
::: Location of the desired tag to hold the value in.
::: {{arg desc|je=nbt_path}}
::: {{MC/Arg desc|je=nbt_path}}
:: {{code|<''type''>}}
:: {{MC/Code|<''type''>}}
::: Desired data size/type.
::: Desired data size/type.
::: Must be one of <code>byte</code>, <code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, and <code>double</code>.
::: Must be one of <code>byte</code>, <code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, and <code>double</code>.
:: {{Argument|scale|double}}
:: {{MC/Argument|scale|double}}
::: Multiplier to apply before storing value, may be negative.
::: Multiplier to apply before storing value, may be negative.
::: {{arg desc|je=double}}
::: {{MC/Arg desc|je=double}}


:;Result
:;Result
:: Unparseable if the argument is not specified correctly.
:: Unparseable if the argument is not specified correctly.


{{Anchor|run}}
{{MC/Anchor|run}}


=== Run subcommand ===
=== Run subcommand ===
The {{Cd|run}} command's single argument is the command to be executed, the context variables of which may be modified by the subcommands used.
The {{MC/Cd|run}} command's single argument is the command to be executed, the context variables of which may be modified by the subcommands used.


:;Syntax
:;Syntax
: {{el|java}}:
: {{MC/El|java}}:
:: <code>run --><''command''></code>
:: <code>run --><''command''></code>
: {{el|bedrock}}:
: {{MC/El|bedrock}}:
:: <code>run <command: command></code>
:: <code>run <command: command></code>


:;Arguments
:;Arguments
:: {{argument|command||command: command|unique_ptr<Command>}}
:: {{MC/Argument|command||command: command|unique_ptr<Command>}}
::: Can be any [[Minecraft:Commands#List and summary of commands|command]]
::: Can be any [[Minecraft:Commands#List and summary of commands|command]]


Line 919: Line 919:
=== ''Java Edition'' ===
=== ''Java Edition'' ===
{{HistoryTable
{{HistoryTable
|{{HistoryLine|java}}
|{{MC/HistoryLine|java}}
|{{HistoryLine||1.13|dev=17w45a|Reworked {{cmd|execute|link=none}}. The syntax of {{cmd|execute|link=none}} has been split off. See [[Minecraft:Commands/execute (old)]] for old syntax.}}
|{{HistoryLine||1.13|dev=17w45a|Reworked {{MC/Cmd|execute|link=none}}. The syntax of {{MC/Cmd|execute|link=none}} has been split off. See [[Minecraft:Commands/execute (old)]] for old syntax.}}
|{{HistoryLine|||dev=17w45b|Reworked {{cmd|execute store|link=none}}.}}
|{{HistoryLine|||dev=17w45b|Reworked {{MC/Cmd|execute store|link=none}}.}}
|{{HistoryLine|||dev=18w02a|Added new subcommands to {{cmd|execute|link=none}} to allow for more control over commands.}}
|{{HistoryLine|||dev=18w02a|Added new subcommands to {{MC/Cmd|execute|link=none}} to allow for more control over commands.}}
|{{HistoryLine|||dev=18w05a|Added {{cmd|execute store (result{{!}}success) bossbar|link=none}}.}}
|{{HistoryLine|||dev=18w05a|Added {{cmd|execute store (result{{!}}success) bossbar|link=none}}.}}
|{{HistoryLine||1.14|dev=18w43a|Added {{cmd|execute (if&#124;unless) data|link=none}}.}}
|{{HistoryLine||1.14|dev=18w43a|Added {{MC/Cmd|execute (if&#124;unless) data|link=none}}.}}
|{{HistoryLine||1.15|dev=19w38a|Added {{cmd|execute (if{{!}}unless) predicate|link=none}}.
|{{HistoryLine||1.15|dev=19w38a|Added {{cmd|execute (if{{!}}unless) predicate|link=none}}.
|Added {{cmd|execute store (result{{!}}success) storage|link=none}}.}}
|Added {{cmd|execute store (result{{!}}success) storage|link=none}}.}}
|{{HistoryLine||1.19.3|dev=22w46a|Added {{cmd|execute (if&#124;unless) biome|link=none}}.}}
|{{HistoryLine||1.19.3|dev=22w46a|Added {{MC/Cmd|execute (if&#124;unless) biome|link=none}}.}}
|{{HistoryLine||1.19.4|dev=23w03a|Added {{cmd|execute on|link=none}}.|Added {{cmd|execute (if{{!}}unless) dimension|link=none}} and {{cmd|execute (if{{!}}unless) loaded|link=none}}.}}
|{{HistoryLine||1.19.4|dev=23w03a|Added {{MC/Cmd|execute on|link=none}}.|Added {{cmd|execute (if{{!}}unless) dimension|link=none}} and {{cmd|execute (if{{!}}unless) loaded|link=none}}.}}
|{{HistoryLine|||dev=23w04a|Added a new relation <code>origin</code> for {{cmd|execute on|link=none}}.}}
|{{HistoryLine|||dev=23w04a|Added a new relation <code>origin</code> for {{MC/Cmd|execute on|link=none}}.}}
|{{HistoryLine|||dev=23w06a|Added {{cmd|execute summon|link=none}}.|Now {{cmd|execute if loaded|link=none}} is a condition subcommand instead of a modifier-like subcommand.<ref>{{bug|MC-259227|resolution=Fixed}}</ref>}}
|{{HistoryLine|||dev=23w06a|Added {{MC/Cmd|execute summon|link=none}}.|Now {{MC/Cmd|execute if loaded|link=none}} is a condition subcommand instead of a modifier-like subcommand.<ref>{{bug|MC-259227|resolution=Fixed}}</ref>}}
|{{HistoryLine|||dev=Pre-release 1|Added {{cmd|execute positioned over|link=none}}.}}
|{{HistoryLine|||dev=Pre-release 1|Added {{MC/Cmd|execute positioned over|link=none}}.}}
|{{HistoryLine||1.20.2|dev=23w31a|Added {{cmd|execute (if{{!}}unless) function|link=none}}.}}
|{{HistoryLine||1.20.2|dev=23w31a|Added {{cmd|execute (if{{!}}unless) function|link=none}}.}}
|{{HistoryLine|||dev=1.20.2 Pre-release 1|Temporarily removed syntax {{cmd|link=none|execute (if{{!}}unless) function}}.}}
|{{HistoryLine|||dev=1.20.2 Pre-release 1|Temporarily removed syntax {{cmd|link=none|execute (if{{!}}unless) function}}.}}
Line 942: Line 942:
=== ''Bedrock Edition'' ===
=== ''Bedrock Edition'' ===
{{HistoryTable
{{HistoryTable
|{{HistoryLine|bedrock}}
|{{MC/HistoryLine|bedrock}}
|{{HistoryLine||1.19.10|exp=Upcoming Creator Features|dev=Preview 1.19.10.20|Added new {{cmd|execute|link=None}} syntax to closer resemble that of {{el|java}}.}}
|{{HistoryLine||1.19.10|exp=Upcoming Creator Features|dev=Preview 1.19.10.20|Added new {{MC/Cmd|execute|link=None}} syntax to closer resemble that of {{MC/El|java}}.}}
|{{HistoryLine||1.19.40|exp=Upcoming Creator Features|dev=Preview 1.19.40.20|Implemented the {{cmd|execute rotated|link=none}} command.}}
|{{HistoryLine||1.19.40|exp=Upcoming Creator Features|dev=Preview 1.19.40.20|Implemented the {{MC/Cmd|execute rotated|link=none}} command.}}
|{{HistoryLine|||dev=Preview 1.19.40.21|Implemented the {{cmd|execute facing|link=none}} and {{cmd|execute align|link=none}} commands.}}
|{{HistoryLine|||dev=Preview 1.19.40.21|Implemented the {{MC/Cmd|execute facing|link=none}} and {{MC/Cmd|execute align|link=none}} commands.}}
|{{HistoryLine|||dev=Preview 1.19.40.23|Implemented the {{cmd|execute anchored|link=none}} and {{cmd|execute in|link=none}} commands.}}
|{{HistoryLine|||dev=Preview 1.19.40.23|Implemented the {{MC/Cmd|execute anchored|link=none}} and {{MC/Cmd|execute in|link=none}} commands.}}
|{{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.}}
|{{HistoryLine||1.19.70|dev=Preview 1.19.70.21|Removed <code>data: int</code> argument from {{cmd|execute <if{{!}}unless> block|link=none}}.}}
|{{HistoryLine||1.19.70|dev=Preview 1.19.70.21|Removed <code>data: int</code> argument from {{cmd|execute <if{{!}}unless> block|link=none}}.}}
}}
}}
Line 959: Line 959:


== Navigation ==
== Navigation ==
{{Navbox commands}}
{{MC/Navbox commands}}


de:Befehl/execute
de:Befehl/execute

Latest revision as of 20:09, 9 April 2026

Template:Infobox command

  1. redirect Template:TOC

Executes another command but allows changing the executor, changing the position and angle it is executed at, adding preconditions, and storing its result.

Usage

There are fourteenTemplate:Only / elevenTemplate:Only subcommands (aka. instructions) for the /execute command. Multiple subcommands can be chained after /execute. Subcommands are divided into 4Template:Only / 3Template:Only categories: modifier subcommands, condition subcommands, store subcommandsTemplate:Only, and the run subcommand.

  • Modifier subcommands modify execution context variables to change the context the command is executed in. Subcommands following it execute with specific executor(s), execution position(s), execution dimension(s), execution rotation(s) and execution anchor.
  • Condition subcommands are used to test whether certain conditions are met, and either output the result or limit the execution of following subcommands.
  • Store subcommandsTemplate:Only can store the output values of the command in a scoreboard or the data of an entity, Minecraft:block entity, or command storage, and can also change the maximum or current value of a bossbar.
  • run subcommand is used for carrying out another command.

All needed subcommands can be concatenated together. Subcommands other than the run subcommand can be arranged arbitrarily and used multiple times. The run subcommand can be used only once, at the end of the chain. Only a run subcommand or a condition subcommand may finalize the chain; otherwise, the command is unparseable.

Subcommands and forking

The game processes the subcommand chain in order — from left to right. For example, the following commands are different:

  • All entities move one block forward: execute as @e at @s run tp ^ ^ ^1
  • All entities are teleported to one block in front of the executor: execute at @s as @e run tp ^ ^ ^1

Some subcommands can fork the command execution into multiple branches, causing subcommands following it to be executed multiple times. For example, when the

  1. REDIRECT Template:Code

Template:Redr subcommand selects multiple entities, the subcommands following it execute once per entity.

If the

  1. REDIRECT Template:Code

Template:Redr command doesn't fork, it has only one branch — the main branch.

A branch may terminate halfway if, for example, the condition in a condition subcommand isn't met, or the

  1. REDIRECT Template:Code

Template:Redr subcommand selects zero entities. When terminating, a red message is shown.Template:Only If all branches terminate, the /execute command is said to have terminated.

Forking is different between

  1. REDIRECT Template:Edition

Template:Rcat and

  1. REDIRECT Template:Edition

Template:Rcat (see also Template:Bug and Template:Bug):

  • in Template:Editions, the game processes subcommands in breadth-first, that is, executes subcommands one by one. So the game processes other subcommands before processing run subcommands, so the run subcommand cannot affect other subcommands.
  • in Template:Editions, the game processes subcommands in depth-first. That is, after forking, all the following subcommands are considered as a whole and are executed once for each branch.
  • For example, when there are two armor stands (A and B) in the world, and a player executes execute as @e[type=armor_stand] as @e[type=armor_stand] run summon armor_stand, the behaviors of
  1. REDIRECT Template:Edition

Template:Rcat and

  1. REDIRECT Template:Edition

Template:Rcat are shown in the following pictures:

Note that ... run execute ... has no overall effect in both versions. For example, the following commands are identical:

  • execute as @e[type=armor_stand] as @e[type=armor_stand] run summon armor_stand
  • execute as @e[type=armor_stand] run execute as @e[type=armor_stand] run execute run execute run summon armor_stand

in Template:Editions, depth-first can be achieved via

  1. REDIRECT Template:Command

Template:Redr, for example:

  • When there are two armor stands (A and B) in the world, and a player executes execute as @e[type=armor_stand] run function test, and in the function file is:
    • execute as @e[type=armor_stand] run summon armor_stand
  • It behaves like /execute as @e[type=armor_stand] as @e[type=armor_stand] run summon armor_stand in
  1. REDIRECT Template:Edition

Template:Rcat. in Template:Editions, there is no way to achieve breadth-first.

Output values

{{#vardefine:params|0 }}Template:Hatnote

Stored values

Script error: No such module "Exclusive". in Template:Editions, a branch outputs a success value and a result value (see also Minecraft:Commands#Output) after it is fully executed (does not terminate halfway). These two output values:

  • Are the outputs of each execution branch, rather than the
  1. REDIRECT Template:Code

Template:Redr command itself;

  • Come from the last subcommand (may be a condition subcommand or a run subcommand).
  • Both are integers. The success value is always 0 or 1. The result value is rounded down if not an integer.
  • If in a branch the last subcommand fails, both the two values are 0 in the branch.
  • The two values can be stored through store subcommandsTemplate:Only.

Note that these two values are from the conditional subcommand at the end or from the command in the

  1. REDIRECT Template:Code

Template:Redr subcommand, and are the output values of each branch, rather than of the whole

  1. REDIRECT Template:Code

Template:Redr command.

If executing

  1. REDIRECT Template:Command

Template:Redr command in the

  1. REDIRECT Template:Code

Template:Redr subcommand, these two output values are not available under certain conditions. See the

  1. REDIRECT Template:Command

Template:Redr for details.

If the command execution is forked after a store subcommand, the storage operation is applied on each branch. The output value of each branch is stored after the branch is fully executed. If the store locations are the same between all branches, the output value of a later-executing branch directly overwrites the output value of the earlier-executed branch, rather than being accumulated. So, after the whole

  1. REDIRECT Template:Code

Template:Redr command is executed, the value at this storage location is the output of the last branch executed.

Success count

Like most commands, /execute command itself also has a success count (whether or not terminates halfway):

  • It is the output value of the
  1. REDIRECT Template:Code

Template:Redr command itself, rather than of each execution branch.

  • It comes from the last subcommand (may be a condition subcommand or a run subcommand).
  • The success counts of all branches are summed up.
  • It is an integer greater than or equal to 0.
  • When executing it with a command block, the success count is passed into the command block, which can be checked with a chained conditional command block or be read with a redstone comparator.

Syntax

There are fourteenTemplate:Only / elevenTemplate:Only instructions (aka. subcommands) for the /execute command, and each has its own special syntax, so describing syntax takes a large branching tree.

Full syntax tree
  • Java Edition
/execute ...
  • ... align <axes> -> execute
  • ... anchored <anchor> -> execute
  • ... as <targets> -> execute
  • ... at <targets> -> execute
  • ... facing (<pos>|entity <targets> <anchor>) -> execute
  • ... in <dimension> -> execute
  • ... on <relation> -> execute
  • ... positioned (<pos>|as <targets>|over <heightmap>) -> execute
  • ... rotated (<rot>|as <targets>) -> execute
  • ... store (result|success) ...
    • ... block <targetPos> <path> <type> <scale> -> execute
    • ... bossbar <id> (max|value) -> execute
    • ... entity <target> <path> <type> <scale> -> execute
    • ... score <targets> <objective> -> execute
    • ... storage <target> <path> <type> <scale> -> execute
  • ... summon <entity> -> execute
  • ... (if|unless) ...
    • ... biome <pos> <biome> -> [execute]
    • ... block <pos> <block> -> [execute]
    • ... blocks <start> <end> <destination> (all|masked) -> [execute]
    • ... data ...
      • ... block <sourcePos> <path> -> [execute]
      • ... entity <source> <path> -> [execute]
      • ... storage <source> <path> -> [execute]
    • ... dimension <dimension> -> [execute]
    • ... entity <entities> -> [execute]
    • ... function <function> -> execute
    • ... items ...
      • ... block <sourcePos> <slots> <item_predicate> -> [execute]
      • ... entity <source> <slots> <item_predicate> -> [execute]
    • ... loaded <pos> -> [execute]
    • ... predicate <predicate> -> [execute]
    • ... score <target> <targetObjective> ...
      • ... (<|<=|=|>|>=) <source> <sourceObjective> -> [execute]
      • ... matches <range> -> [execute]
  • ... run <command>
where -> execute represents the start of another subcommand that is required; -> [execute] represents the start of another subcommand that is optional.
  • Bedrock Edition
/execute ...
  • ... align <axes: string> <chainedCommand: ExecuteChainedOption_0>
  • ... anchored <eyes|feet> <chainedCommand: ExecuteChainedOption_0>
  • ... as <origin: target> <chainedCommand: ExecuteChainedOption_0>
  • ... at <origin: target> <chainedCommand: ExecuteChainedOption_0>
  • ... facing ...
    • ... <position: x y z> <chainedCommand: ExecuteChainedOption_0>
    • ... entity <origin: target> <eyes|feet> <chainedCommand: ExecuteChainedOption_0>
  • ... in <dimension: Dimension> <chainedCommand: ExecuteChainedOption_0>
  • ... positioned ...
    • ... <position: x y z> <chainedCommand: ExecuteChainedOption_0>
    • ... as <origin: target> <chainedCommand: ExecuteChainedOption_0>
  • ... rotated ...
    • ... <yaw: value> <pitch: value> <chainedCommand: ExecuteChainedOption_0>
    • ... as <origin: target> <chainedCommand: ExecuteChainedOption_0>
  • ... <subcommand: Option_If_Unless> ...
    • ... block <position: x y z> <block: Block> ...
      • ... <blockStates: block states> [chainedCommand: ExecuteChainedOption_0]
      • ... [chainedCommand: ExecuteChainedOption_0]
    • ... blocks <begin: x y z> <end: x y z> <destination: x y z> <scan mode: BlocksScanMode> [chainedCommand: ExecuteChainedOption_0]
    • ... entity <target: target> [chainedCommand: ExecuteChainedOption_0]
    • ... score <target: target> <objective: string> ...
      • ... <operation: compare operator> <source: target> <objective: string> [chainedCommand: ExecuteChainedOption_0]
      • ... matches <range: integer range> [chainedCommand: ExecuteChainedOption_0]
  • ... run <command: command>
where chainedCommand: ExecuteChainedOption_0 represents the start of another subcommand.

Modifier subcommands

align

Updates the execution position, aligning to its current block position (integer coordinates). Applies only along specified axes.
Effectively floors the coordinates (i.e., rounds the coordinates down)
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

align <axes> -> execute
  1. REDIRECT Template:Edition

Template:Rcat:

align <axes: string> <chainedCommand: ExecuteChainedOption_0>
Arguments
Template:El<axes>: swizzle
Template:El: axes: string: basic_string
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|swizzle}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Execution position in the given axes are floored, changing by less than 1 block.
Unparseable if the argument is not specified correctly.
Example
Given (-1.8, 2.3, 5.9), execute align xz changes the position to (-2, 2.3, 5).
Given (2.4, -1.1, 3.8), execute align yxz run spawnpoint @p ~ ~ ~ sets the player's spawnpoint to (2, -2, 3).

anchored

Sets the execution anchor to the eyes or feet. Defaults to feet.
Running positioned <pos> -> execute resets to feet.
Effectively recenters local coordinates on either the eyes or feet, also changing the angle of the facing subcommand (of
  1. REDIRECT Template:Command

Template:Redr and

  1. REDIRECT Template:Command

Template:Redr) works off of.

See also Template:Bug and Template:Bug for issues about
  1. REDIRECT Template:Edition

Template:Rcat.

Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

anchored <anchor> -> execute
  1. REDIRECT Template:Edition

Template:Rcat:

anchored <eyes|feet> <chainedCommand: ExecuteChainedOption_0>
Arguments
Template:Argument
Whether to anchor the executed command to eyes or feet.
Must be either eyes or feet.
Result
Execution anchor is set to either the eyes or the feet.
Unparseable if the argument is not specified correctly.
Example
The effect of Script error: No such module "command". is to move a target by placing its feet at the given position.
execute anchored eyes run tp ^ ^ ^ effectively teleports the executor's feet to where its eyes are.
execute anchored eyes run tp ^5 ^ ^ means "place the executor's feet 5 blocks left of where its eyes are"

as

Sets the executor to target entity, without changing execution position, rotation, dimension, and anchor.
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

as <targets> -> execute
  1. REDIRECT Template:Edition

Template:Rcat:

as <origin: target> <chainedCommand: ExecuteChainedOption_0>
Arguments
Template:El<targets>: entity
Template:El: origin: target: CommandSelector<Actor>
Target entity/entities to become the new executor.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|entity}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Executor is updated to target entity (which changes the meaning of @s).
Unparseable if the argument is not specified correctly.
Forks if <targets> or origin: target selects multiple entities.
Terminates current branch if <targets> or origin: target fails to resolve to one or more entities (named players must be online).
Example
Kill all sheep: execute as @e[type=sheep] run kill @s
Make all villagers in loaded chunks invincible: execute as @e[type=villager] run data merge entity @s {Invulnerable:1}Template:Only

at

Sets the execution position, rotation, and dimension to match those of an entity; does not change executor.
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

at <targets> -> execute
  1. REDIRECT Template:Edition

Template:Rcat:

at <origin: target> <chainedCommand: ExecuteChainedOption_0>
Arguments
Template:El<targets>: entity
Template:El: origin: target: CommandSelector<Actor>
Target entity/entities to match position, rotation, and dimension with.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|entity}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Execution position, rotation, and dimension are updated to match target entity.
Unparseable if the argument is not specified correctly.
Forks if <targets> or origin: target selects multiple entities.
Terminates current branch if <targets> or origin: target fails to resolve to one or more entities (named players must be online).
Example
Move all sheep upward 1 block: execute as @e[type=sheep] at @s run tp ~ ~1 ~
Kill the player running the command, because "at" does not change the executor: execute at @e[type=sheep] run kill @s

facing

Sets the execution rotation to face a given point, as viewed from its anchor (either the eyes or the feet).
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

facing <pos> -> execute
facing entity <targets> <anchor> -> execute
  1. REDIRECT Template:Edition

Template:Rcat:

facing <position: x y z> <chainedCommand: ExecuteChainedOption_0>
facing entity <origin: target> <eyes|feet> <chainedCommand: ExecuteChainedOption_0>
Arguments
Options: facing <pos> and facing <position: x y z>
Template:El<pos>: vec3
Template:El: position: x y z: CommandPositionFloat
Coordinates to rotate toward.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|vec3}}{{#vardefine:be-arg|vec3}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Options: facing entity <targets> <anchor> and facing entity <origin: target> <eyes|feet>
Template:El<targets>: entity
Template:El: origin: target: CommandSelector<Actor>
The target(s) to rotate toward.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|entity}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Template:Argument
Whether to face the target's eyes or feet
Must be either eyes or feet.
Result
Execution rotation is updated to face given position or targets.
Unparseable if the argument is not specified correctly.
Forks if <targets> or origin: target selects multiple entities.
Terminates current branch if <targets> or origin: target fails to resolve to one or more entities (named players must be online).
Example
Executor rotates once to the left: execute facing ^1 ^ ^ run tp @s ~ ~ ~ ~ ~
All entities move one block in the direction of (0, 64, 0) (without changing their rotation): execute as @e at @s facing 0 64 0 run tp @s ^ ^ ^1
All entities move one block in the direction of (0, 64, 0) (with changing their rotation): execute as @e at @s facing 0 64 0 run tp ^ ^ ^1 ~ ~
All non player entities move one space in the direction of their nearest player (without changing their rotation): execute as @e[type=!player] at @s facing entity @p feet run tp @s ^ ^ ^1

in

Sets the execution dimension and execution position.
It respects dimension scaling for relative and local coordinates: the execution position (only the X/Z part) is divided by 8 when changing from the Overworld to the Nether, and is multiplied by 8 when vice versa. Applies to custom dimensions as well.
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

in <dimension> -> execute
  1. REDIRECT Template:Edition

Template:Rcat:

in <dimension: Dimension> <chainedCommand: ExecuteChainedOption_0>
Arguments
Template:El<dimension>: dimension
Template:El: dimension: Dimension: enum
ID of the new execution dimension.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|dimension}}{{#vardefine:be-arg|{{#var:je-arg}}}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Execution dimension and position is updated.
Unparseable if the argument is not specified correctly.
Example
Looking for an end city (from the overworld):
  • execute in minecraft:the_end run locate structure minecraft:end_cityTemplate:Only
  • execute in the_end run locate structure end_cityTemplate:Only
If a player at position
  1. REDIRECT Template:Code

Template:Redr in Overworld runs the following command, the player is teleported to

  1. REDIRECT Template:Code

Template:Redr in the Nether:

  • execute in minecraft:the_nether positioned as @s run tp ~ ~ ~Template:Only
  • execute in nether positioned as @s run tp ~ ~ ~Template:Only
If a player at position
  1. REDIRECT Template:Code

Template:Redr in Overworld runs the following command, the player is teleported to

  1. REDIRECT Template:Code

Template:Redr in the Nether.

If a player at position
  1. REDIRECT Template:Code

Template:Redr in Overworld runs the following command, the player is teleported to

  1. REDIRECT Template:Code

Template:Redr in the Nether.

on

Script error: No such module "Exclusive".

Updates the executor to entities selected based on relation to the current executor entity. without changing execution position, rotation, dimension, and anchor.
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

on <relation> -> execute
Arguments
  1. REDIRECT Template:Edition

Template:Rcat: <relation>

A relation to the current executor entity.
  • attacker: the last entity that damaged the current executor entity in the previous 5 seconds. Note that damage types in minecraft:no_anger tag bypass the record of attacker. Interaction entities do not forget attacker after 5 seconds. Some mobs forget the attacker when ceasing their aggression.
  • controller: the entity that is riding and controlling the current executor entity. See Riding for details.
  • leasher: the entity leading the current executor entity with a leash.
  • origin: the entity that cause the summon of the current executor entity. For example, the shooter of an arrow, the primer of a primed TNT entity.
  • owner: the owner of the current executor entity if it is a tameable animal.
  • passengers: all entities that are directly riding the current executor entity, no sub-passengers.
  • target: the target that the current executor entity intends on attacking. Interaction entities can select the last entity that interacted with them.
  • vehicle: the entity ridden by the current executor entity.
Result
Executor is updated based on the relation with the executor entity (which changes the meaning of @s).
Forks if passengers selects multiple entities. (Other relations can select only at most one entities.)
Terminates current branch if the current executor is not an entity.
Terminates current branch if the relation is not applicable to the current executor entity or there are no entities matching it.
Example
Damage 1 heart the entity that is leashing a cat: execute as @e[type=cat] on leasher run damage @s 2 generic
Give all players riding a boat a fishing rod: execute as @e[type=boat] on passengers run give @s fishing_rod

positioned

Sets the execution position, without changing execution rotation or dimension; can match an entity's position, or at one block above the Y-level stored in the specified heightmapTemplate:Only.
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

positioned <pos> -> execute
positioned as <targets> -> execute
positioned over <heightmap> -> execute
  1. REDIRECT Template:Edition

Template:Rcat:

positioned <position: x y z> <chainedCommand: ExecuteChainedOption_0>
positioned as <origin: target> <chainedCommand: ExecuteChainedOption_0>
Arguments
Option: positioned <pos> or positioned <position: x y z>
Template:El<pos>: vec3
Template:El: position: x y z: CommandPositionFloat
New position.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|vec3}}{{#vardefine:be-arg|vec3}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Option: positioned as <targets> or positioned as <origin: target>
Template:El<targets>: entity
Template:El: origin: target: CommandSelector<Actor>
Target entity/entities to match position with.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|entity}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Option: positioned over <heightmap>
  1. REDIRECT Template:Edition

Template:Rcat: <heightmap>: heightmap

Specifies the heightmap.
Must be one of world_surface, motion_blocking, motion_blocking_no_leaves, and ocean_floor.
Result
Execution position is updated. And positioned <pos> also resets execution anchor to feet.
Unparseable if the argument is not specified correctly.
Forks if <targets> or origin: target selects multiple entities.
Terminates current branch if <targets> or origin: target fails to resolve to one or more entities (named players must be online), or over <heightmap> is specified when current execution position is not loaded.
Example
Look for a village near (0, 64, 0):
  • execute positioned 0 64 0 run locate structure #villageTemplate:Only
  • execute positioned 0 64 0 run locate structure villageTemplate:Only

rotated

Sets the execution rotation; can match an entity's rotation.
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

rotated <rot> -> execute
rotated as <targets> -> execute
  1. REDIRECT Template:Edition

Template:Rcat:

rotated <yaw: value> <pitch: value> <chainedCommand: ExecuteChainedOption_0>
rotated as <origin: target> <chainedCommand: ExecuteChainedOption_0>
Arguments
Option: rotated <rot> or rotated <yaw: value> <pitch: value>
  1. REDIRECT Template:Edition

Template:Rcat: <rot>: rotation (<yaw> <pitch>)

  1. REDIRECT Template:Edition

Template:Rcat: yaw: value: RelativeFloat and pitch: value: RelativeFloat

Angles of rotation.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|rotation}}{{#vardefine:be-arg|relativefloat}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Option: rotated as <targets> or rotated as <origin: target>
Template:El<targets>: entity
Template:El: origin: target: CommandSelector<Actor>
Target entity/entities to match rotation with.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|entity}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Execution rotation is updated.
Unparseable if the argument is not specified correctly.
Forks if <targets> or origin: target selects multiple entities.
Terminates current branch if <targets> or origin: target fails to resolve to one or more valid entities (named players must be online).
Example
Move every sheep 1 block in the direction that the player closest to it is facing:
  • execute as @e[type=sheep] at @s rotated as @p run tp @s ^ ^ ^1
  • execute as @e[type=sheep] positioned as @s rotated as @p run tp @s ^ ^ ^1

summon

Script error: No such module "Exclusive".

Summons a new entity at execution position and changes the executor to this summoned entity.
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

summon <entity> -> execute
Arguments
  1. REDIRECT Template:Edition

Template:Rcat: <entity>: resource

The entity to be summoned and become the new executor.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|resource}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Summons the entity and changes the executor.
Unparseable if the argument is not specified correctly.
Terminates current branch if execution position's <x> or <z> exceeds the range of [-30000000, 30000000), or <y> exceeds the range of [-20000000, 20000000).
Terminates the whole
  1. REDIRECT Template:Command

Template:Redr command if the specified entity is minecraft:player or minecraft:fishing_bobber.

Example
Summon a sheep with the tag "Test": execute summon sheep run tag @s add Test
Summon a block display entiy and scale it: execute summon block_display run data merge entity @s {transformation:{scale:[4.0,4.0,4.0]},block_state:{Name:"minecraft:dirt"}}

Condition subcommands

The particular use of the if and unless subcommands are to restrict command execution to happen only under specified conditions. In most cases, unless is a negation of if, equivalent to "if not...". The two subcommands have identical argument structures.

Result of condition subcommands
Unparseable if the arguments are not specified correctly.
In some cases, for example, testing a block outside the world, both if and unless terminates or fails.
When not at the end of the subcommands chain, only if the condition tests pass does the branch continue; otherwise it terminates.
in Template:Editions, if it is executed in multiple branches, it acts as a context filter (only branches with contexts that match the condition continue).
When at the end of the subcommands chain, it checks whether the condition is met and then outputs. in Template:Editions, it has output values that can be stored by store subcommands.

There are elevenTemplate:Only / fourTemplate:Only different types of conditions:

  1. (if|unless) biome – Tests the biome in a positionTemplate:Only
  2. (if|unless) block – Tests a single block
  3. (if|unless) blocks – Tests blocks in a 3D rectangular volume against another
  4. (if|unless) data – Tests for the data held by a block entity, an entity, or a storageTemplate:Only
  5. (if|unless) dimension - Tests the dimension of the executionTemplate:Only
  6. (if|unless) entity – Tests whether an entity like the one given is real
  7. (if|unless) function – Runs a function or function tag and tests its return valueTemplate:Only
  8. (if|unless) items – Tests an inventory slot for a given itemTemplate:Only
  9. (if|unless) loaded – Tests if a given position is loaded in the worldTemplate:Only
  10. (if|unless) predicate – Tests a predicateTemplate:Only
  11. (if|unless) score - Tests a target's score

(if|unless) biome

Script error: No such module "Exclusive".

Checks for a specific biome in a given position.
Syntax
(if|unless) biome <pos> <biome> -> [execute]
Arguments
<pos>: block_pos
Position to test.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<biome>: resource_or_tag
Biome(s) to test for.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|resource_or_tag}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.
In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
  • If <pos> is unloaded or out of the world.
  • If test doesn't pass.
When at the end of the subcommand chain, if the command is successful, both success value and result value are 1.

(if|unless) block

Compares the block at a given position to a given block ID or a block tagTemplate:Only
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

(if|unless) block <pos> <block> -> [execute]
  1. REDIRECT Template:Edition

Template:Rcat:

<subcommand: Option_If_Unless> block <position: x y z> <block: Block> [chainedCommand: ExecuteChainedOption_0]
<subcommand: Option_If_Unless> block <position: x y z> <block: Block> <blockStates: block states> [chainedCommand: ExecuteChainedOption_0]
Arguments
Template:El<pos>: block_pos
Template:El: position: x y z: CommandPosition
Position of a target block to test.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|block_pos}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Template:El<block>: block_predicate
Template:El: block: Block: enum
Specifies the block to test for.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_predicate}}{{#vardefine:be-arg|block_be}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
  1. REDIRECT Template:Edition

Template:Rcat: blockStates: block states: BlockStateCommandParam

Specifies the block state for the specified block to test for.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|blockstatecommandparam}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.
In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
  • If <pos> or position: x y z is unloaded or out of the world.
  • If test doesn't pass.
in Template:Editions, when at the end of the subcommand chain, if the command is successful, both success value and result value are 1.

(if|unless) blocks

Compares the blocks in two equally sized volumes.
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

(if|unless) blocks <start> <end> <destination> (all|masked) -> [execute]
  1. REDIRECT Template:Edition

Template:Rcat:

<subcommand: Option_If_Unless> blocks <begin: x y z> <end: x y z> <destination: x y z> <scan mode: BlocksScanMode> [chainedCommand: ExecuteChainedOption_0]
Arguments
Template:El<start>: block_pos
Template:El: begin: x y z: CommandPosition
Template:El<end>: block_pos
Template:El: end: x y z: CommandPosition
Positions of any two diagonal corners of the source volume (the volume to compare).
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|block_pos}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Template:El<destination>: block_pos
Template:El: destination: x y z: CommandPosition
Position of the lower northwest corner of the destination volume (the volume to compare to).
Assumed to be of the same size as the source volume
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|block_pos}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
  1. REDIRECT Template:Edition

Template:Rcat: Template:Code

  1. REDIRECT Template:Edition

Template:Rcat: scan mode: BlocksScanMode: enum

Specifies whether all blocks in the source volume should be compared, or if air blocks should be masked/ignored.
Must be either all or masked.
Result
Unparseable if the argument is not specified correctly.
In following conditions, terminates current branch when this subcommand is not at end of the subcommand chain; fails when at the end:
  • If <start> / begin: x y z, <end> / end: x y z, or <destination> / destination: x y z is unloaded or out of the world.
  • If the volume of the source region is greater than 32768 (the equivalent of 8 chunk sections).
  • If test doesn't pass.
in Template:Editions, when at the end of the subcommand chain, if the command is successful:
The success value is 1.
For if mode, result value is the number of matching blocks (the total number of blocks in all mode, or the number of source region non-air blocks in masked mode).
For unless mode, result value is 1.

(if|unless) data

Script error: No such module "Exclusive".

Checks whether the targeted block, entity or storage has any data tag for a given path.
Syntax
(if|unless) data block <pos> <path> -> [execute] – for data checking a block
(if|unless) data entity <target> <path> -> [execute] – for data checking an entity
(if|unless) data storage <source> <path> -> [execute] – for data checking a storage
Arguments
Option: (if|unless) data block <pos> <path>
<pos>: block_pos
Position of the block for data testing.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<path>: nbt_path
Data path to check whether the block has.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_path}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Option: (if|unless) data entity <target> <path>
<target>: entity
A single entity for data testing.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<path>: nbt_path
Data path to check whether the entity has.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_path}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Option: (if|unless) data storage <source> <path>
<source>: resource_location
The resource location of the storage for data testing.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|resource_location}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<path>: nbt_path
Data path to check whether the storage has.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_path}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.
In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
  • If <pos> is unloaded or out of the world.
  • If block at <pos> isn't a block entity.
  • If <target> fails to resolve to one or more valid entities (named players must be online).
  • If test doesn't pass.
When at the end of the subcommand chain, if the command is successful:
The success value is 1.
For if mode, result value is the number of matching data tags.
For unless mode, result value is 1.

(if|unless) dimension

Script error: No such module "Exclusive".

Checks if the execution is in a matching dimension.
Syntax
(if|unless) dimension <dimension> -> [execute]
Arguments
<dimension>: dimension
Dimension to test for.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|dimension}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.
In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
  • If test doesn't pass.
When at the end of the subcommand chain, if the command is successful, both success value and result value are 1.

(if|unless) entity

Checks whether one or more entities exist.
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

(if|unless) entity <entities> -> [execute]
  1. REDIRECT Template:Edition

Template:Rcat:

<subcommand: Option_If_Unless> entity <target: target> [chainedCommand: ExecuteChainedOption_0]
Arguments
Template:El<entities>: entity
Template:El: target: target: CommandSelector<Actor>
The target entity/ies to test for.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|entity}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.
In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
  • If test doesn't pass.
in Template:Editions, when at the end of the subcommand chain, if the command is successful:
The success value is 1.
For if mode, result value is the number of matching entities.
For unless mode, result value is 1.

(if|unless) function

Script error: No such module "Exclusive".

Checks if function(s) are non-void and the return value is non-zero. Terminates current branch unless the function's return value is non-zero. Doesn't change any execution context.
Unlike other conditional subcommands, this subcommand can modify the world depending on the function(s) that are tested. It also cannot be placed at the end of the subcommand chain.<ref>Template:Bug</ref>
Syntax
(if|unless) function <function> -> execute
Arguments
<function>: function
Function to test for.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|function}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.
If the given function or function tag does not exist, or a function tag is given but there's no function in it, terminates the whole /execute command.
When only one function is given, if it is not macro function; and it is not void; and its return value is not 0:
  • if does nothing and unless terminates current branch.
When multiple functions are given, each function is checked and called one by one in the defined order in the tag file:
  • If the function is a macro function: Ends this subcommand execution, and if terminates current branch and unless does nothing.
  • If a function is void: Checks and calls the next function. If there's no next function, if terminates current branch and unless does nothing.
  • If a function returns a failure, or returns a success but its return value is 0: Ends this subcommand execution, and if terminates current branch and unless does nothing.
  • If a function returns a success and its return value is not 0: Ends this subcommand execution, and if does nothing and unless terminates current branch.

(if|unless) items

Script error: No such module "Exclusive".

Checks for a matching item in the provided inventory Minecraft:slots.
Syntax
(if|unless) items block <sourcePos> <slots> <item_predicate>
(if|unless) items entity <source> <slots> <item_predicate>
Arguments
<sourcePos>: block_pos
Location of a block entity to test.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<source>: entity
Entity to test.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<slots>: item_slots
Slots to test. A string that consists of a "slot type" and an optional "slot number", in the format of <slot_type>, <slot_type>.<slot_number> or <slot_type>.*. See Minecraft:Slot for details.
<item_predicate>: item_predicate
Item or item tag to test for.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|item_predicate}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.
In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
  • If <source_pos> is unloaded or out of the world.
  • If block at <source_pos> isn't a block entity.
  • If <source> fails to resolve to one or more valid entities (named players must be online).
  • If test doesn't pass.
When at the end of the subcommand chain, if the command is successful:
The success value is 1.
For if mode, result value is the number of matching items.
For unless mode, result value is 1.

(if|unless) loaded

Script error: No such module "Exclusive".

Checks if chunks at a given position is fully loaded (Entity Ticking).
Syntax
(if|unless) loaded <pos> -> [execute]
Arguments
<pos>: block_pos
Position to test
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.
In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
  • If <pos> is out of the world.
  • If test doesn't pass.
When at the end of the subcommand chain, if the command is successful, both success value and result value are 1.

(if|unless) predicate

Script error: No such module "Exclusive".

Checks whether the predicate successes. See Predicate for more information.
Syntax
(if|unless) predicate <predicate> -> [execute]
Arguments
<predicate>: resource_location or inline definition
The predicate to be checked whether it evaluates to a positive result.
Must either be a resource location or an inline definition, following the same structure as predicates encoded in the SNBT format.
The command is resolved during command execution into unregistered content, or sent to the client to resolve into a client-side content.
Result
Unparseable if the argument is not specified correctly.
In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
  • If the predicate doesn't exist.
  • If test doesn't pass.
When at the end of the subcommand chain, if the command is successful, both success value and result value are 1.

(if|unless) score

Check whether a score has the specific relation to another score, or whether it is in a given range.
Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

(if|unless) score <target> <targetObjective> (<|<=|=|>=|>) <source> <sourceObjective> -> [execute] – for comparing two scores
(if|unless) score <target> <targetObjective> matches <range> -> [execute] – for comparing one score against a range
  1. REDIRECT Template:Edition

Template:Rcat:

<subcommand: Option_If_Unless> score <target: target> <objective: string> <operation: compare operator> <source: target> <objective: string> [chainedCommand: ExecuteChainedOption_0] - for comparing two scores
<subcommand: Option_If_Unless> score <target: target> <objective: string> matches <range: integer range> [chainedCommand: ExecuteChainedOption_0] - for comparing one score against a range
Arguments
Template:El<target>: score_holder
Template:El: target: target: CommandSelector<Actor>
A single score holder.
in Template:Editions, {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|score_holder}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
in Template:Editions, {{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|inapplicability}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}} It can also be quoted unique id to specified non-player entities in the objective.
Template:El<targetObjective>: objective
Template:El: objective: string: basic_string
The scoreboard objective to check under. The score of <target> or <target: target> in this objective is checked.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|objective}}{{#vardefine:be-arg|string}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Option: (if|unless) score ... (<|<=|=|>=|>) ... or <subcommand: Option_If_Unless> score ... <operation: compare operator> ...
  1. REDIRECT Template:Edition

Template:Rcat: (<|<=|=|>=|>)

  1. REDIRECT Template:Edition

Template:Rcat: operation: compare operator: CommandCompareOperator

Specifies a compare operator.
Must be one of <, <=, =, >=, and >.
Template:El<source>: score_holder
Template:El: source: target: CommandSelector<Actor>
A single score holder to compare against.
in Template:Editions, {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|score_holder}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
in Template:Editions, {{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|inapplicability}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}} It can also be quoted unique id to specified non-player entities in the objective.
Template:El<sourceObjective>: objective
Template:El: objective: string: basic_string
A scoreboard objective. The score of <source> or <source: target> in this objective is checked.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|objective}}{{#vardefine:be-arg|string}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Option: (if|unless) score ... matches ... or <subcommand: Option_If_Unless> score ... matches ...
Template:El<range>: int_range
Template:El: range: integer range: CommandIntegerRange
Range to compare score against.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|int_range}}{{#vardefine:be-arg|int_range}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.
In following conditions, terminates current branch when this subcommand is not at the end of the subcommand chain; fails when at the end:
  • in Template:Editions, if <target> / target: target or <source> / source: target is *.
  • If test doesn't pass.
in Template:Editions, when at the end of the subcommand chain, if the command is successful, both success value and result value are 1.

Example

Kill all players standing on a wool:
  • execute as @a at @s if block ~ ~-1 ~ #wool run kill @sTemplate:Only
  • execute as @a at @s if block ~ ~-1 ~ wool run kill @sTemplate:Only
Check whether scores A and B are equal: execute if score @s A = @s B

Store subcommand

Script error: No such module "Exclusive". Stores the final subcommand's result or success value somewhere. It is first processed along with other subcommands in the subcommand chain, recording the location to store in. After the last subcommand (may be a condition subcommand or a run subcommand) is executed, output values are stored in the recorded location. Note that the output values of commands are always an integer. If not, they are rounded down.

There are five different modes of storage:

  1. store (result|success) block – Stores output value under one of a block's NBTs
  2. store (result|success) bossbar – Stores output value as a bossbar data
  3. store (result|success) entity – Stores output value under one of an entity's NBTs
  4. store (result|success) score – Stores output value under a target's score on an objective
  5. store (result|success) storage – Stores output value under one of a storage's NBTs

store (result|success) block

Saves the final command's output value as tag data within a block entity. Store as a byte, short, int, long, float, or double. If the output value is a decimal, it is rounded first and then multiplied by <scale>.
Syntax
store (result|success) block <targetPos> <path> <type> <scale> -> execute
Arguments
<targetPos>: block_pos
Position of target block.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<path>: nbt_path
Location of the desired tag to hold the value in.
<type>
Desired data size/type.
Must be one of byte, short, int, long, float, and double.
<scale>: double
Multiplier to apply before storing value, may be negative.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|double}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.

store (result|success) bossbar

Saves the final command's output value in either a bossbar's current value or its maximum value
Syntax
store (result|success) bossbar <id> (value|max) -> execute
Arguments
<id>: resource_location
ID of the bossbar to target for saving.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|resource_location}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Template:Code
Whether to overwrite the bossbar's current value or its max value
Result
Unparseable if the argument is not specified correctly.

store (result|success) entity

Save the final command's output value in one of an entity's data tags. Store as a byte, short, int, long, float, or double. If the output value is a decimal, it is rounded first and then multiplied by <scale>. Like the
  1. REDIRECT Template:Command

Template:Redr command, "/execute store" cannot modify player NBT.

Syntax
store (result|success) entity <target> <path> <type> <scale> -> execute
Arguments
<target>: entity
A single entity to store under.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<path>: nbt_path
Location of the desired tag to hold the value in.
<type>
Desired data size/type
Must be one of byte, short, int, long, float, and double.
<scale>: double
Multiplier to apply before storing value, may be negative.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|double}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.

store (result|success) score

Overrides the score held by <targets> on the given <objective> with the final command's output value.
Syntax
store (result|success) score <targets> <objective> -> execute
Arguments
<targets>: score_holder
Specifies score holder(s) whose score is to be overridden.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|score_holder}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<objective>: objective
A scoreboard objective.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|objective}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.

store (result|success) storage

Uses the
  1. REDIRECT Template:Code

Template:Redr within storage

  1. REDIRECT Template:Code

Template:Redr to store the output value in. Store as a byte, short, int, long, float, or double. If the output value is a decimal, it is rounded first and then multiplied by

  1. REDIRECT Template:Code

Template:Redr. If the storage does not yet exist, it gets created.

Syntax
store (result|success) storage <target> <path> <type> <scale> -> execute
Arguments
<target>: resource_location
Target storage container, as a resource location.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|resource_location}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<path>: nbt_path
Location of the desired tag to hold the value in.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_path}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<type>
Desired data size/type.
Must be one of byte, short, int, long, float, and double.
<scale>: double
Multiplier to apply before storing value, may be negative.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|double}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Unparseable if the argument is not specified correctly.

Run subcommand

The

  1. REDIRECT Template:Code

Template:Redr command's single argument is the command to be executed, the context variables of which may be modified by the subcommands used.

Syntax
  1. REDIRECT Template:Edition

Template:Rcat:

run --><command>
  1. REDIRECT Template:Edition

Template:Rcat:

run <command: command>
Arguments
Template:El<command>
Template:El: command: command: unique_ptr<Command>
Can be any command
TechnicalTemplate:Only
Resets the command node to the root of the command dispatcher
Information on modelling commands as chat text:
  • The command dispatcher is what starts when the player begins a message with a forward-slash (/).
  • A command node is the specific word/entry the cursor is editing, either a command or an argument.
  • The root node comes before the first word in the current command.
Result
Execute this command. Fails if <command> or command: command is failure.

More examples

  • Teleport all players who have an item enchanted with Efficiency in their first hotbar slot to coordinates (0, 64, 0):
    /execute as @a if data entity @s Inventory[{Slot:0b}].tag.Enchantments[{id:"minecraft:efficiency"}] run tp @s 0 64 0Template:Only
  • Create a smoke particle three blocks in front of all players:
    /execute as @a at @s anchored eyes run particle smoke ^ ^ ^3Template:Only
  • Place a saddle on Minecraft:pigs located within 5 blocks of the executing player, and remove saddles from pigs located over 5 blocks away from the executing player:
    /execute as @e[type=pig] at @s store success entity @s Saddle byte 1 if entity @p[distance=..5]Template:Only
  • Make a player say "My feet are soaked!" in chat if they are located in a block of Minecraft:water:
    /execute as @a at @s if block ~ ~ ~ water run say "My feet are soaked!"
  • Make a player say "Score is reset" in chat if the score test is not set, eg by doing "scoreboard players reset @s test":
    /execute as @a unless score @s test = @s test run say "Score is reset"
  • Hurl all skeletons skyward who are within 3 blocks of the nearest player:
    /execute at @p as @e[type=skeleton,distance=..3] run data merge entity @s {Motion:[0.0,2.0,0.0]}Template:Only
  • Kill all Minecraft:zombies who have no headgear:
    /execute as @e[type=zombie] unless data entity @s ArmorItems[3].id run kill @sTemplate:Only
  • Set every player's nearbyRedSheep scoreboard objective equal to the amount of red sheep within twenty blocks:
    /execute as @a at @s store result score @s nearbyRedSheep if entity @e[type=sheep,nbt={Color:14},distance=..20]

History

Java Edition

Template:HistoryTable

Bedrock Edition

Template:HistoryTable

References

<references/>

External links

Navigation

All editions
Removed
Template:El only
Debug
Removed
Template:Els only
Template:El only
Removed
Template:El only
Removed
Template:Els only
Removed
Joke
Related

de:Befehl/execute es:Comandos/execute fr:Commandes ja:コマンド/execute ko:명령어/execute pl:Polecenia/execute pt:Comandos/execute ru:Команды консоли/execute uk:Команди консолі/execute zh:命令/execute