Skip to content
WikilyWIKILY
All games23 Wikis · pick your game
Commands and cheatsAll commands

Switch game

23 Wikis · pick your game
/execute

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.

Syntax

/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> ...

Arguments

ArgumentKind of valueWhat to type
<axes>AxesFor align: any combination of the letters x, y and z, each used at most once, for example xz or xyz.
<anchor>Entity anchorEither feet or eyes.
<targets>Target selectorThe 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 positionA 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 tagFor if biome: a biome id or a biome tag starting with #. The id of a biome, or a #tag of them.
<block>Block testFor if block: the block to look for, as an id or a block tag starting with #, optionally with block states and data.
<start>Block positionFor if blocks: one corner of the first area.
<end>Block positionFor if blocks: the opposite corner of the first area.
<destination>Block positionFor if blocks: the lowest corner of the area to compare with.
<source>Block positionFor 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 pathThe data path to test or to store into.
<dimension>DimensionThe id of a dimension, for example minecraft:overworld, minecraft:the_nether or minecraft:the_end.
<entities>Target selectorFor if entity: the entities to look for. The test passes if at least one exists. One or more entities.
<name>FunctionFor if function: the id of a function, or a function tag starting with #.
<slots>Item slotsFor if items and if slots: a slot name such as weapon.mainhand, hotbar.0 or container.*, or a slot source.
<item_predicate>Item testFor 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>PredicateFor if predicate: the id of a predicate from a data pack, or a predicate written inline.
<target>Score holderFor if score: the score holder to test. For store: the block position, entity or storage id that receives the value.
<targetObjective>Scoreboard objectiveFor if score: the objective of the score being tested.
<sourceObjective>Scoreboard objectiveFor if score: the objective of the score to compare with.
<range>Whole number rangeFor 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>IdFor if stopwatch: the id of the stopwatch. For store bossbar: the id of the boss bar.
<heightmap>HeightmapFor positioned over: world_surface, ocean_floor, motion_blocking or motion_blocking_no_leaves.
<rot>RotationFor rotated: yaw and pitch in degrees. ~ keeps the current value.
<scale>Decimal numberFor store into data: the number the value is multiplied by before it is saved.
<objective>Scoreboard objectiveFor store score: the objective that receives the value.
<entity>Game idFor summon: the id of the entity type to summon. The id of an entity.

Details

Permission level2: operators, worlds with cheats on, command blocks and functions
Works inOperators on multiplayer servers, singleplayer worlds with cheats enabled, and command blocks and functions.
ResultThe 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.
ChainingSub-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.
asChanges who runs the command to the given entities. The command runs once for each entity. The position and rotation do not change.
atMoves the command to the position, rotation and dimension of the given entities, without changing who runs it. The command runs once for each entity.
alignRounds the current position down to whole block coordinates on the listed axes.
anchoredChooses whether local coordinates (^ ^ ^) and facing are measured from the feet or the eyes of the entity running the command.
facingTurns the command to look at a position, or with facing entity at the feet or eyes of an entity.
inRuns the command in another dimension.
onSwitches 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.
positionedSets 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.
rotatedSets the rotation to the given yaw and pitch, or to the rotation of other entities with rotated as.
summonSummons a new entity at the current position and runs the rest of the command as that entity.
if and unlessContinue 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 blocksCompares 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 scoreCompares 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 slotsif 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 functionRuns a function or function tag and passes if it returns a value other than 0.
if stopwatchChecks 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 loadedPasses if the chunk at the position is fully loaded and its entities are being updated.
storeSaves 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.
runRuns the command written after it with everything set by the sub-commands before it.
No matching entityIf as, at, positioned as, rotated as or facing entity match no entity, the rest of the command does not run.
Fork limitThe number of times one command can split into several runs is capped by the game rule max_command_forks (default 65536).

Examples

/execute as @a at @s run setblock ~ ~-1 ~ minecraft:gold_block

Places 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 grass

Sends the message only if the block below is a Grass Block.

/execute unless entity @e[type=minecraft:creeper,distance=..16] run say No Creepers nearby

Sends the message only if no Creeper is within 16 blocks.

/execute if score @s kills matches 10.. run give @s minecraft:diamond 1

Gives 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 Health

Saves 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 @s

Kills every Zombie that has something other than Air below it.

/execute in minecraft:the_nether run tp @s 0 80 0

Teleports 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_sword

Sets your score in the objective has_sword to 1 if you hold a Diamond Sword in your main hand, otherwise to 0.

Join the creator communityThe people who build the Minecraft Java Edition wiki are on our Discord. Ask questions or suggest pages.Join Discord (opens Discord in a new tab)