
Command
/execute
Runs another command after changing who runs it, where it runs, or whether it runs at all, and can save the outcome of that command.
| /execute (align <axes>|anchored <anchor>|as <targets>|at <targets>|in <dimension>|summon <entity>) ... |
| /execute facing entity <targets> <anchor> ... |
| /execute facing <pos> ... |
| /execute (if|unless) biome <pos> <biome> [...] |
| /execute (if|unless) block <pos> <block> [...] |
| /execute (if|unless) blocks <start> <end> <destination> (all|masked) [...] |
| /execute (if|unless) data (block <source>|entity <source>|storage <source>) <path> [...] |
| /execute (if|unless) (dimension <dimension>|entity <entities>|loaded <pos>|predicate <predicate>) [...] |
| /execute (if|unless) function <name> ... |
| /execute (if|unless) items (block <source>|entity <source>) <slots> <item_predicate> [...] |
| /execute (if|unless) score <target> <targetObjective> (< <source>|<= <source>|= <source>|> <source>|>= <source>) <sourceObjective> [...] |
| /execute (if|unless) score <target> <targetObjective> matches <range> [...] |
| /execute (if|unless) slots (block <source>|entity <source>) <slots> [...] |
| /execute (if|unless) stopwatch <id> <range> [...] |
| /execute on (attacker|controller|leasher|origin|owner|passengers|target|vehicle) ... |
| /execute positioned (as <targets>|over <heightmap>) ... |
| /execute positioned <pos> ... |
| /execute rotated as <targets> ... |
| /execute rotated <rot> ... |
| /execute run <command> |
| /execute store (result|success) (block <target>|entity <target>|storage <target>) <path> (byte <scale>|double <scale>|float <scale>|int <scale>|long <scale>|short <scale>) ... |
| /execute store (result|success) bossbar <id> (max|value) ... |
| /execute store (result|success) score <targets> <objective> ... |
| Argument | Kind of value | What to type |
|---|---|---|
| <axes> | Axes | For align: any combination of the letters x, y and z, each used at most once, for example xz or xyz. |
| <anchor> | Entity anchor | Either feet or eyes. |
| <targets> | Target selector | The entities to use for as, at, positioned as, rotated as and facing entity. With store result score it is the score holders that receive the value. One or more entities. |
| <pos> | Exact position | A position. For positioned and facing these are X Y Z coordinates and may use ~ or ^. For if block, if biome and if loaded it is a block position. |
| <biome> | Game id or tag | For if biome: a biome id or a biome tag starting with #. The id of a biome, or a #tag of them. |
| <block> | Block test | For if block: the block to look for, as an id or a block tag starting with #, optionally with block states and data. |
| <start> | Block position | For if blocks: one corner of the first area. |
| <end> | Block position | For if blocks: the opposite corner of the first area. |
| <destination> | Block position | For if blocks: the lowest corner of the area to compare with. |
| <source> | Block position | For if data, if items and if slots: the block position, entity or storage id to read. For if score: the second score holder. |
| <path> | Data path | The data path to test or to store into. |
| <dimension> | Dimension | The id of a dimension, for example minecraft:overworld, minecraft:the_nether or minecraft:the_end. |
| <entities> | Target selector | For if entity: the entities to look for. The test passes if at least one exists. One or more entities. |
| <name> | Function | For if function: the id of a function, or a function tag starting with #. |
| <slots> | Item slots | For if items and if slots: a slot name such as weapon.mainhand, hotbar.0 or container.*, or a slot source. |
| <item_predicate> | Item test | For if items: the item to count, as an id, an item tag starting with # or * for any item, optionally followed by component tests in square brackets. |
| <predicate> | Predicate | For if predicate: the id of a predicate from a data pack, or a predicate written inline. |
| <target> | Score holder | For if score: the score holder to test. For store: the block position, entity or storage id that receives the value. |
| <targetObjective> | Scoreboard objective | For if score: the objective of the score being tested. |
| <sourceObjective> | Scoreboard objective | For if score: the objective of the score to compare with. |
| <range> | Whole number range | For if score matches: a whole number or range such as 5, 1..10, 3.. or ..7. For if stopwatch: a range of seconds, decimals allowed. |
| <id> | Id | For if stopwatch: the id of the stopwatch. For store bossbar: the id of the boss bar. |
| <heightmap> | Heightmap | For positioned over: world_surface, ocean_floor, motion_blocking or motion_blocking_no_leaves. |
| <rot> | Rotation | For rotated: yaw and pitch in degrees. ~ keeps the current value. |
| <scale> | Decimal number | For store into data: the number the value is multiplied by before it is saved. |
| <objective> | Scoreboard objective | For store score: the objective that receives the value. |
| <entity> | Game id | For summon: the id of the entity type to summon. The id of an entity. |
| Permission level | 2: operators, worlds with cheats on, command blocks and functions |
| Works in | Operators on multiplayer servers, singleplayer worlds with cheats enabled, and command blocks and functions. |
| Result | The result is that of the command after run. When the command ends with an if or unless test instead of run, it reports "Test passed" or "Test failed"; tests that count something (blocks, data, entity, items, slots) report and return the count, the other tests return 1. |
| Chaining | Sub-commands can be combined in any order and any number, and are applied from left to right. The chain ends with run and a command, or with an if or unless test. |
| as | Changes who runs the command to the given entities. The command runs once for each entity. The position and rotation do not change. |
| at | Moves the command to the position, rotation and dimension of the given entities, without changing who runs it. The command runs once for each entity. |
| align | Rounds the current position down to whole block coordinates on the listed axes. |
| anchored | Chooses whether local coordinates (^ ^ ^) and facing are measured from the feet or the eyes of the entity running the command. |
| facing | Turns the command to look at a position, or with facing entity at the feet or eyes of an entity. |
| in | Runs the command in another dimension. |
| on | Switches to an entity related to the current one: attacker (the last entity that attacked it), controller (the passenger steering it), leasher (the entity holding its lead), origin (the entity that shot or created it), owner (the owner of a tamed animal), passengers (every entity riding it), target (the entity it is attacking) or vehicle (the entity it is riding). If there is no such entity, the command does not run. |
| positioned | Sets the position to the given coordinates, to the position of other entities with positioned as, or to the top of the terrain at the current X and Z with positioned over. |
| rotated | Sets the rotation to the given yaw and pitch, or to the rotation of other entities with rotated as. |
| summon | Summons a new entity at the current position and runs the rest of the command as that entity. |
| if and unless | Continue only if the test passes (if) or fails (unless). Tests: biome, block, blocks, data, dimension, entity, function, items, loaded, predicate, score, slots and stopwatch. |
| if blocks | Compares two areas of the same size block by block. all compares every block; masked ignores Air in the first area. The area may contain at most 32768 blocks. |
| if score | Compares a score with another score using <, <=, =, >= or >, or checks it against a range with matches. The test fails if a score is not set. |
| if items and if slots | if items counts the items in the chosen slots of a container block or of entities that match an item test. if slots counts the slots that exist for the given slot name. |
| if function | Runs a function or function tag and passes if it returns a value other than 0. |
| if stopwatch | Checks whether the elapsed time of a stopwatch, in seconds, is inside the given range. Fails with an error if the stopwatch does not exist. |
| if loaded | Passes if the chunk at the position is fully loaded and its entities are being updated. |
| store | Saves the outcome of the final command. store result saves the number /execute store saves, store success saves 1 if it succeeded and 0 if it failed. The value can go into a score, a boss bar (value or max), or a data path of a block, entity or storage with a number type and a scale. |
| run | Runs the command written after it with everything set by the sub-commands before it. |
| No matching entity | If as, at, positioned as, rotated as or facing entity match no entity, the rest of the command does not run. |
| Fork limit | The number of times one command can split into several runs is capped by the game rule max_command_forks (default 65536). |
/execute as @a at @s run setblock ~ ~-1 ~ minecraft:gold_blockPlaces a Block of Gold under every player.
/execute at @p run summon minecraft:lightning_bolt ~ ~ ~Strikes lightning at the position of the nearest player.
/execute positioned 0 64 0 run kill @e[type=minecraft:zombie,distance=..10]Kills every Zombie within 10 blocks of the position 0 64 0.
/execute if block ~ ~-1 ~ minecraft:grass_block run say Standing on grassSends the message only if the block below is a Grass Block.
/execute unless entity @e[type=minecraft:creeper,distance=..16] run say No Creepers nearbySends the message only if no Creeper is within 16 blocks.
/execute if score @s kills matches 10.. run give @s minecraft:diamond 1Gives you a Diamond if your score in the objective kills is 10 or more.
/execute store result score @s health run data get entity @s HealthSaves your current health into your score in the objective health.
/execute as @e[type=minecraft:zombie] at @s unless block ~ ~-1 ~ minecraft:air run kill @sKills every Zombie that has something other than Air below it.
/execute in minecraft:the_nether run tp @s 0 80 0Teleports you to 0 80 0 in the Nether.
/execute as @a at @s anchored eyes positioned ^ ^ ^3 run particle minecraft:flame ~ ~ ~Shows a flame particle 3 blocks in front of the eyes of every player.
/execute if entity @a[gamemode=creative]Tests whether any player is in Creative mode and reports how many.
/execute store success score @s has_sword run execute if items entity @s weapon.mainhand minecraft:diamond_swordSets your score in the objective has_sword to 1 if you hold a Diamond Sword in your main hand, otherwise to 0.





