Как пользоваться командой execute в майнкрафт

Обновлено: 08.05.2024

The Minecraft Wiki is no longer considered as official by Microsoft and therefore several changes are required to be made, including to the wiki's logo. Please read this announcement for more information.

Commands/execute

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

Синтаксис [ ]

Использование [ ]

Поставит под игроком Alexander блок лавы.

Поставит 10 блоков гравия над 5 самыми дальними игроками, которые стоят на траве.

Очень полезным свойством команды /execute является то, что она может выполнять сама себя. Так можно проверять большие структуры на целостность всего одним командным блоком, не выстраивая огромные цепочки с командой /testforblock .
Для удобства чтения такая команда разделена на 3 строки, и вписывать её нужно в командный блок.

Bedrock Edition [ ]

Syntax [ ]

execute <origin: target> <position: x y z> <command: command> An alternate syntax allows the command to be executed only if a specific block is detected: execute <origin: target> <position: x y z> detect <detectPos: x y z> <block: Block> <data: int> <command: command>

Arguments [ ]

Specifies the target to be the command's executor. Must be a player name or target selector. If more than one entity is selected, the command is run once as each of them.

Specifies the position from which to run the command. Coordinates specified with tilde and caret notation are relative to the target, not to the position of the command's execution.

Specifies the command to be run. Must be a valid command.

detectPos: x y z

Specifies the position of the block to check. May use tilde and caret notation to specify distances relative to position: x y z .

Specifies the block ID that the block at detectPos, must match for the command to run. Must be a valid block ID.

Must be a valid block data for that type of block or -1 to match any block data.

Minecraft Wiki

Из-за новой политики Microsoft в отношении сторонних ресурсов, Minecraft Wiki больше не является официальной. В связи с этим были внесены некоторые изменения, в том числе и обновлён логотип вики-проекта. Подробности на нашем Discord-сервере.

Java Edition [ ]

In Java Edition, there are twelve instructions (or sub-commands) for the /execute command. Multiple sub-commands are connected after /execute. Subcommands are divided into 4 categories: modify subcommands, condition subcommands, store subcommands, and run subcommand.

  • Modify subcommands modify command variables and change the situation the command is executed, and execute subcommands following it 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 true and output results or limit conditions of execution.
  • Store subcommands can store the return values of the command in a scoreboard or the data of an entity, block entity, or storage, and can also change the maximum or current value of a boss bar.
  • run subcommand is used for carrying out another command.

All needed sub-commands can be concatenated together. Subcommands other than the run subcommand can be arranged arbitrarily and used multiple times. But the run subcommand can only be used once and must be put at the end of the subcommands chain. A run subcommand or a condition subcommand finalizes the command, otherwise the command does nothing. The game processes these subcommands in order from front to end, 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

The game processes other subcommands before processing run subcommands, so the run subcommand cannot affect other subcommands. In some cases, the command may terminate halfway and does nothing.

/execute command also has a success count (whether or not terminates halfway), which is different from success and result value. This is usually 0 or 1 , but if the last subcommand is executed many times separately (as perhaps with "/execute as @a -> execute") then success can be a number higher than 1 . When executing it with a command block, the success count is returned to the command block, which can be checked by a conditional command block for success or be read with a redstone comparator.

There are twelve instructions (or sub-commands) for the /execute command, and each has its own special syntax, so describing syntax takes a large branching tree.

Please update this section to reflect recent updates or newly available information.
  • … align <axes> -> execute
  • … anchored <anchor> -> execute
  • … as <targets> -> execute
  • … at <targets> -> execute
  • … facing (<pos>|entity <targets> <anchor>) -> execute
  • … in <dimension> -> execute
  • … positioned (<pos>|as <targets>) -> 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
    • … block <pos> <block> -> [execute]
    • … blocks <start> <end> <destination> (all|masked) -> [execute]
    • … data . . .
      • … block <sourcePos> <path> -> [execute]
      • … entity <source> <path> -> [execute]
      • … storage <source> <path> -> [execute]
      • … (<|<=|=|>|>=) <source> <sourceObjective> -> [execute]
      • … matches <range> -> [execute]

      Modify subcommands [ ]

      align [ ]
      • Given (-1.8, 2.3, 5.9), /execute align xz changes the position to (-2, 2, 5).
      • Given (2.4, -1.1, 3.8), /execute align yxz run spawnpoint @p
      anchored [ ]

      Kill yourself, because " at " does not change the executor: execute at @e[type=sheep] run kill @s

      facing [ ]

      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

      , the player is teleported to (16,64,16) in the Nether. If a player at position (16,64,16) in Overworld runs command execute in minecraft:the_nether run tp

      , the player is teleported to (2,64,2) in the Nether. If a player at position (80,64,80) in Overworld runs command execute in minecraft:the_nether run tp

      5 , the player is teleported to (10,64,15) in the Nether.

      positioned [ ]
      rotated [ ]
      • For the horizontal rotation (yaw), -180.0 for due north, -90.0 for due east, 0.0 for due south, 90.0 for due west, to 179.9 for just west of due north, before wrapping back around to -180.0.
      • For the vertical rotation (pitch), -90.0 for straight up to 90.0 for straight down.

      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 commands have identical argument structures.

      Result of condition subcommands Unparseable if the argument is 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 is the subcommand following it executed; otherwise it terminates. If it is executed multiple times by multiple variables (e.g. executors, execution positions, execution rotations), it acts as a variable filter - Only the variable that matches the condition executes the next subcommand. When at the end of the subcommands chain, it checks whether the condition is met and then outputs.

      There are six different types of conditions:

        – Tests a single real block – Tests a real 3D rectangular volume against another – Tests the data held by a real block, entity, or a storage – Tests whether an entity like the one given is real – Tests a predicate - Tests an target's score
      (if|unless) block [ ]
      • If <pos> is unloaded or out of the world.
      • If test doesn't pass.
      (if|unless) blocks [ ]
      • If <start> , <end> , or <destination> 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.
      (if|unless) data [ ]
      • 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 valid entities (named players must be online)
      • If test doesn't pass.
      (if|unless) entity [ ]
      (if|unless) predicate [ ]
      • If the predicate doesn't exist.
      • If test doesn't pass.
      (if|unless) score [ ]
      • If target or source is * .
      • If test doesn't pass.
      Example [ ]
      Kill all players standing on a wool: execute as @a at @s if block

      Store subcommand [ ]

      Store the final command's result or success value somewhere. It is first processed along with other subcommands, recording the location to store in. After the last subcommand (may be a condition subcommand or a run subcommand) is executed, return values will be stored in the location. Note that the return values of commands must be an integer. If a decimal, it is rounded down.

      There are five different modes of storage:

        – Store return value under one of a block's NBTs – Store return value as a bossbar data – Store return value under one of an entity's NBTs – Store return value under a target's score on an objective – Store return value under one of a storage's NBTs
      store (result|success) block [ ]
      store (result|success) bossbar [ ]
      store (result|success) entity [ ]
      store (result|success) score [ ]
      store (result|success) storage [ ]

      Run subcommand [ ]

      The run command's single argument is the command to be executed, the variables of which may be modified by the subcommands used.

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

      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[].tag.Enchantments[] run tp @s 0 64 0
      • Create a smoke particle three blocks in front of all players: /execute as @a at @s anchored eyes run particle smoke ^ ^ ^3
      • Place a saddle on 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]
      • Make a player say "My feet are soaked!" in chat if they are located in a block of water: /execute as @a at @s if block

      Руководство по команде execute

      [1.8+][Guide] Как пользоваться командой /execute

      [1.8+][Guide] Как пользоваться командой /execute

      Сначала небольшое описание команды. /execute - это команда, которая позволяет выполнять какие-то команды относительно какой-либо сущности или игрока в майнкрафте. Я понимаю, что прозвучало сложно, но сейчас я всё подробно объясню. Но если вы ранее не имели дело с КБ, то вам стоит сначала разобраться в других командах.

      [1.8+][Guide] Как пользоваться командой /execute

      Начём с того, как пишется команда /execute.
      Пример: /execute

      Т.е. относительно того, кого мы указали в селекторе будет выполнятся какая-либо команда.

      0.5 0.2 0.5 0.05 10

      [1.8+][Guide] Как пользоваться командой /execute

      Т.е. относительно всех игроков спавнятся частицы пламени, и вот получается такой эффект.

      Также есть такая дополнительная команда, которая действует только для /execute. Это команда detect, которая проверяет есть ли блок в указанном месте.
      Пример: /execute detect (Координаты) (id блока) (data блока)

      gold_block 0 effect @p 8 1 3

      [1.8+][Guide] Как пользоваться командой /execute

      Эта команда делает так, что если вы стоите на золотом блоке, то вам даётся эффект прыжка 4-го уровня (Не 3-го, 4-го).

      Также можно писать команду /execute в команде /execute (Да, звучит странно), что позволяет вам искать сущности относительно других сущностей, и уже относительно них выполнять команды.
      Пример: /execute execute

      [1.8+][Guide] Как пользоваться командой /execute

      Т.е. если относительно вас на расстоянии 2 блоков есть крипер, то в него бьёт молния.

      [Гайд] Команда /execute и её возможности

      [Гайд] Команда /execute и её возможности

      Итак, в снапшотах версии 1.8 было добавлено очень много команд, упрощающих создание карт на прохождение. К этим командам относится и /execute. Она предназначена для выполнения команд относительно какой-либо сущности. Давайте для начала рассмотрим синтаксис самой команды.

      Итак, команда, указываемая в самом конце выполняется относительно выбранной сущности. Иными словами, интерпретатор принимает за стартовую точку отсчёта (x=0, y=0, z=0) координаты выбранного объекта. Указывая координаты, мы смещаем выбранную точку.

      Рассмотрим на примере: Команда /execute @p[r=5]

      minecraft:stone выберет ближайшего игрока в радиусе пяти блоков, и примет за начало отсчёта его координаты (Например: x=6, y=3, z=4), сместит их на указанное количество блоков (В указанном ранее примере финальными будут координаты: x=10, y=4, z=11), и выполнит команду /setblock

      minecraft:stone, установив камень в выбранном по изложенному ранее алгоритму месте.

      Также, не стоит забывать, что команда /execute была добавлена в версии 1.8 (Снапшоты).

      Contents

      Читайте также: