/execute
是各不同功能的子命令的集合,用于改变命令执行上下文(修饰子命令),执行逻辑判断(条件子命令)和管理并存储命令返回值(存储子命令)
概述[]
子命令分类[]
子命令按功能可分为以下几类:
- 修饰子命令:修改命令变量并改变命令执行时的状态,从而以特定的执行位置、执行基准点、执行者、执行朝向、执行维度执行后续子命令。
- 条件子命令:检测特定条件是否成立并输出结果,或限制子命令执行的条件。
- 存储子命令
[仅Java版]:将命令返回值存储至方块实体、实体或存储容器的NBT数据中,记分板的记分项中,或Boss栏的当前值或最大值中。 run
子命令:执行目标命令。
使用子命令[]
子命令可以在/execute
后串连在一起使用,可出现在命令的任意位置及重复任意次数(run
子命令除外,其只能位于末尾且只能使用一次)。
条件子命令或run
子命令必须作为命令结尾,否则不产生实际效果。
子命令处理顺序[]
各子命令按其在命令中的顺序被依次处理,下列命令中子命令虽然一致,但由于顺序不同,会产生不同效果:
/execute as @e at @s run tp ^ ^ ^1
:所有实体向各自所朝方向移动一格。/execute at @s as @e run tp ^ ^ ^1
:所有实体移动到执行者前方一格。
run
子命令会在其他子命令被处理后再处理,因此它不影响其他子命令。
返回值[]
若有语法错误或指定的命名空间ID不存在,命令就中途终止并提示错误,此时无返回值。
在Java版中,若命令未中途终止,命令执行后,会返回其success
(成功次数)和result
(结果)两个返回值,其:
- 值均来自结尾的条件子命令或
run
子命令。若被执行多次,返回值为最后一次执行的; - 均为整数,
result
遇小数时向下取整; success
总为0或1。- 无命令执行成功时两值均为0;
- 均可由存储子命令存储。
/execute
命令本身也有成功次数(无论是否中途终止),通常为0或1,但若被分开执行多次(如/execute as @a -> execute
)则可大于1
语法树[]
下面列出了各子命令及其语法的语法树。其中的所有-> execute
chainedCommand: ExecuteChainedOption_0
execute ...
... align <axes> -> execute
... anchored <anchor> -> execute
... as <targets> -> execute
... at <targets> -> execute
... facing ...
... <pos> -> execute
... entity <targets> <anchor> -> execute
... in <dimension> -> execute
... on (attacker|controller|leasher|origin|owner|passengers|target|vehicle) -> execute
... positioned ...
... <pos> -> execute
... as <targets> -> execute
... over <heightmap> -> execute
... rotated ...
... <rot> -> execute
... as <targets> -> 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
... loaded <pos> -> execute
... predicate <predicate> -> execute
... score <target> <targetObjective>
... (=|<|<=|>|>=) <source> <sourceObjective> -> execute
... matches <range> -> execute
... store (result|success) ...
... block <targetPos> <path> (int|float|short|long|double|byte) <scale> -> execute
... bossbar <id> (value|max) -> execute
... entity <target> <path> (int|float|short|long|double|byte) <scale> -> execute
... score <targets> <objective> -> execute
... storage <target> <path> (int|float|short|long|double|byte) <scale> -> execute
... run ...
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: BlockScanMode> [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>
修饰子命令[]
可用子命令:
align
:将执行位置转换为方块坐标。anchored
:将执行基准点设置为实体的脚部或眼部。as
:将执行者设置为特定实体。at
:将执行位置、执行朝向和执行维度设置为指定实体的坐标、朝向和维度。facing
:将命令的执行朝向设置为面向指定坐标或指定实体。in
:将命令执行维度设置为特定维度。on
:将执行者设置为与当前执行者有指定类型的关系的实体。positioned
:将执行位置设置为指定坐标或指定实体位置。rotated
:将执行朝向设为特定方向或设为指定实体的朝向。summon
[仅Java版]:立即创建一个实体,并将此实体设置为执行者。
align[]
- 将执行位置转换为方块坐标(向下取整)。
- 效果
- 改变执行坐标,指定轴上的坐标向下取整。
- 参数未正确指定时视为语法错误。
- 示例
/execute positioned -1.8 2.3 5.9 align xz run tp ~ ~ ~
:把自己从(-1.8, 2.3, 5.9)传送至(-2, 2.3, 5)。/execute positioned 2.4 -1.1 3.8 align yxz run spawnpoint @p ~ ~ ~
:当前执行位置为(2.4, -1.1, 3.8),将最近玩家的出生点设置为(2, -2, 3)。/execute align y run tp ~ ~ ~
:把自己的Y坐标微调,向下取整。
anchored[]
- 将执行基准点设置为实体的脚部或眼部,默认为脚部。
- 参数
- JE:
<anchor>
:entity_anchor - BE:
eyes|feet
- 需要设置的基准点位置。
- 必须为
eyes
或feet
。eyes
为眼部,feet
为脚部。
- 效果
- 将局部坐标的执行基准点设为眼睛或脚,并改变
facing
子命令所指向的位置。 - 参数不正确时,视为语法错误。
- 示例
/tp
的效果是通过将脚部移动到指定的位置来移动实体。/execute anchored eyes run tp ^ ^ ^
:将命令执行者的腿部移动到原眼部位置。/execute anchored eyes run tp ^5 ^ ^
:将命令执行者的腿部移动到原眼部位置左边5格的位置上。
as[]
- 将执行者设置为特定实体,但不改变其他命令变量。
[需要测试基岩版]
- 效果
- 将执行者改为目标实体(改变
@s
的含义)。 - 参数不正确时,视为语法错误。
- 若
<targets>
或origin: target
无法解析为一个或多个有效实体(指定玩家必须在线)时,命令终止执行。 - 当选择到多个实体时,以各个实体为执行者分别执行一次后续子命令。
- 示例
at[]
- 将执行位置、执行朝向和执行维度
[需要测试基岩版]设置为指定实体的坐标、朝向和维度,不改变命令执行者。
- 示例
/execute at @r run setblock ~ ~-1 ~ stone
:在一名随机玩家脚下放置一块石头。/execute as @e[type=sheep] at @s run tp ~ ~1 ~
:将所有绵羊向上移动1格。/execute at @e[type=sheep] run kill @s
:杀死执行者而非所有绵羊(at
子命令不修改执行者)。
facing[]
- 将命令的执行朝向设置为面向指定坐标或指定实体,不改变命令执行者和执行位置。
- 效果
- 将执行朝向设置为面向指定的坐标或目标实体。
- 参数不正确时,视为语法错误。
- 若
<targets>
或origin: target
无法解析为一个或多个有效实体(指定玩家必须在线)时,命令终止执行。 - 当选择到多个实体时,以各个实体的朝向分别执行一次后续子命令。
- 示例
/execute facing ^1 ^ ^ run tp ~ ~ ~
[仅Java版]:将执行者的视角左转90度。 /execute as @e at @s facing 0 64 0 run tp ^ ^ ^1
:将所有实体都朝(0, 64, 0)的方向移动一格(不改变自身朝向)。/execute as @e at @s facing 0 64 0 run tp ^ ^ ^1 ~ ~
:将所有实体都朝(0, 64, 0)的方向移动一格(改变自身朝向)。/execute as @e[type=!player] at @s facing entity @p feet run tp ^ ^ ^1
:所有非玩家实体朝着各自距离最近的玩家的方向移动一格(不改变自身的朝向)。
in[]
- 将命令执行维度设置为特定维度。命令将在指定的维度中执行。
- 效果
- 更新执行维度。并依据原维度与现维度间关系,按比例缩放相对坐标和局部坐标(不包括Y轴)。
- 参数不正确时,视为语法错误。
- 示例
/execute in the_end run locate structure end_city
:从任意维度中定位末地中的末地城。/execute in the_nether positioned as @s run tp ~ ~ ~
:将玩家传送到下界中的对应位置。/execute in the_nether run tp ~ ~ ~
:将玩家传送到下界中的对应位置。若玩家原先位于其他维度的(X, Y, Z)处,则传送到下界的(X÷8, Y, Z÷8)处。/execute in the_nether run tp ~ ~ ~5
:将玩家传送到下界中的对应位置。若玩家原先位于其他维度的(X, Y, Z)处,则传送到下界的(X÷8, Y, Z÷8+5)处。
on[]
- 将执行者设置为与当前执行者有指定类型的关系的实体。
- 语法
- JE:
on (attacker|controller|leasher|owner|passengers|target|vehicle) -> execute
- 效果
- 若指定的关系不适用于当前执行实体,或此关系下没有匹配实体,则返回0个元素。
- 参数不正确时,视为语法错误。
- 若此参数无法解析为一个或多个有效实体(指定玩家必须在线)时,命令终止执行。
- 示例
/execute as @e[type=sheep] on attacker run kill @s
:杀死5秒内对附近可检测到的所有绵羊发起攻击动作的所有最后一个实体。/execute as @e[type=cat] on leasher run damage @s 2 generic
:给拴着猫的实体施加2()点普通伤害。
positioned[]
- 将执行位置设置为指定坐标或指定实体位置,但不改变执行执行者、执行朝向和执行维度。
- 语法
- JE:
positioned <pos> -> execute
- BE:
positioned <position: x y z> <chainedCommand: ExecuteChainedOption_0>
- 将执行位置设置为指定坐标。
- JE:
positioned as <targets> -> execute
- BE:
positioned as <origin: target> <chainedCommand: ExecuteChainedOption_0>
- 将执行位置设置为指定实体位置。
- JE:
positioned over <heightmap> -> execute
- 将执行位置设置为符合特定高度图的一纵列方块的最高的位置。
- 参数
- JE:
<pos>
:vec3 - BE:
position: x y z
- 指定命令执行的坐标。
- 必须为三维坐标,元素为浮点数。允许波浪号与脱字号标记。
- JE:
<targets>
:entity - BE:
origin: target
- 指定命令执行的位置为此处指定的实体所处的坐标。
- 必须为玩家名、目标选择器或UUID。
- JE:
<heightmap>
:heightmap- 指定高度图。须为下列选项之一:
world_surface
:任意非空气方块。motion_blocking
:任意能阻挡移动的方块(如忽略花草)。motion_blocking_no_leaves
:任意不包括树叶的能阻挡移动的方块。ocean_floor
:任意能阻挡移动的非流体方块。
- 指定高度图。须为下列选项之一:
- 效果
- 改变命令的执行位置。
positioned <pos>
会将执行基准点设置为脚部。 - 参数不正确时,视为语法错误。
- 若
<targets>
或origin: target
无法解析为一个或多个有效实体(指定玩家必须在线)时,命令终止执行。 - 当选择到多个实体时,以各个实体的位置分别执行一次后续子命令。
- 示例
rotated[]
- 将执行朝向设为特定方向,或设为指定实体的朝向,但不改变执行者和执行位置。
- 效果
- 参数不正确时,视为语法错误。
- 当
<targets>
实体不存在时命令终止执行。 - 若
<targets>
或origin: target
无法解析为一个或多个有效实体(指定玩家必须在线)时,命令终止执行。 - 当选择到多个实体时,以各个实体的朝向分别执行一次后续子命令。
- 示例
/execute as @e[type=sheep] at @s rotated as @p run tp @s ^ ^ ^1
:让所有的绵羊以各自距离最近玩家的朝向作为方向移动1格。
summon[]
- 立即生成一个实体,并将执行者设置为此实体。
- 语法
- JE:
summon <entity> -> execute
- 参数
- JE:
<entity>
:entity_summon- 需要生成的实体类型。
- 必须为可召唤实体类型的命名空间ID。
- 效果
- 参数不正确时,视为语法错误。
- 示例
/execute summon villager run damage @e[type=iron_golem,sort=nearest,limit=1] 1 generic by @s
:在玩家位置上生成一名村民,并让它对距其最近的铁傀儡造成1()点普通伤害。
条件子命令[]
条件子命令包括if
和unless
两种,用于测试特定类型的条件。两者的语义相反但参数结构一致,if
表示“如果……就”,unless
表示“除非……否则”。
条件子命令可以单独使用,也可以与其他子命令一起使用,根据其处于整条命令中的位置,其行为也有区别:
- 位于整条命令的末尾时,条件子命令会直接输出测试结果。
- 不位于整条命令的末尾时,条件子命令会根据自身语义与测试结果,决定后续子命令是否执行。
- 若由多个变量(如执行者、执行位置、执行朝向)执行多次时,可作为变量过滤器使用。
可用条件类型:
biome
[仅Java版]:检测给定位置上的生物群系是否为特定生物群系。 block
:检测给定位置上的方块是否是特定的方块或方块状态及。blocks
:检测给定区域内的方块是否匹配另一个同等大小区域内的方块。data
[仅Java版]:检测方块、实体或存储容器是否拥有给定的NBT标签。 dimension
:检测命令执行时所处的维度是否为特定维度。entity
:检测一个或多个特定实体是否存在。loaded
:检测给定位置是否已被加载。predicate
[仅Java版]:检测谓词计算结果是否为正。 score
:检测指定目标的记分板中的记分项的分数是否与另一个(或同一个)目标的记分板的记分项的分数是否符合指定的关系,或者是否在给定的范围之内。
(if|unless) biome[]
- 检测给定位置上的生物群系是否为特定生物群系。
- 语法
- JE:
(if|unless) biome <pos> <biome> -> execute
- 效果
- 参数未正确指定时视为语法错误。
- 若未通过测试或出现下列情形,终止执行后续子命令(不位于末尾)或执行失败(位于末尾):
<pos>
所指定的位置未加载或位于世界外。
- 若位于末尾且执行成功,
success
和result
均返回1。
(if|unless) block[]
- 检测给定位置上的方块是否是特定的方块或方块状态。
- 参数
- JE:
<pos>
:block_pos - BE:
position: x y z
- JE:
<block>
:block_predicate - BE:
block: Block
- BE:
blockStates: block states
:BlockStateCommandParam- 需要检测的方块的方块状态。
- 必须为格式为
["<键1>"=<值1>,"<键2>"=<值2>,...]
的方块状态,例如:["old_leaf_type"="birch","persistent_bit"=true]
。
- 效果
- 参数未正确指定时视为语法错误。
- 若未通过测试或出现下列情形,终止执行后续子命令(不位于末尾)或执行失败(位于末尾):
<pos>
或position: x y z
所指定的位置未加载或位于世界外。
- 若位于末尾且执行成功,
success
和result
均返回1。
- 示例
/execute as @a at @s if block ~ ~-1 ~ stone run kill @s
:击杀所有踩在石头上的玩家。
(if|unless) blocks[]
- 检测给定区域内的方块是否匹配另一个同等大小区域内的方块。
- 效果
- 参数未正确指定时视为语法错误。
- 若未通过测试或出现下列情形之一,终止执行后续子命令(不位于末尾)或执行失败(位于末尾):
<start>
或begin: x y z
、<end>
或<end: x y z>
、<destination>
或destination: x y z
所指定的位置未加载或位于世界外。- 要检测的源区域方块数大于32768。
- 若位于末尾且执行成功,
success
返回1。result
返回:- 匹配上的方块数(
if
)。 - 1(
unless
)。
- 匹配上的方块数(
(if|unless) data[]
- 检测方块、实体或存储容器是否拥有给定的NBT标签。
- 效果
- 参数未正确指定时视为语法错误。
- 若未通过测试或出现下列情形之一,终止执行后续子命令(不位于末尾)或执行失败(位于末尾):
<pos>
所指定的位置未加载或位于世界外。<pos>
所指定的位置上不是方块实体。<target>
(data entity
)无法解析为一个或多个有效实体(指定玩家必须在线)。
- 若位于末尾且执行成功,
success
返回1。result
返回:- 匹配上的NBT标签数(
if
)。 - 1(
unless
)。
- 匹配上的NBT标签数(
- 示例
/execute as @a if data entity @s Inventory[{}].tag.Enchantments run give @s stone
:给予所有拥有附魔物品的玩家一块石头。
(if|unless) dimension[]
- 检测命令执行时所处的维度是否为特定维度。
- 语法
- JE:
(if|unless) dimension <dimension> -> execute
- 效果
- 参数未正确指定时视为语法错误。
- 若未通过测试,终止执行后续子命令(不位于末尾)或执行失败(位于末尾)。
- 若位于末尾且执行成功,
success
返回1。result
返回:- 匹配上的维度数(
if
)。 - 1(
unless
)。
- 匹配上的维度数(
(if|unless) entity[]
- 检测一个或多个特定实体是否存在。
- 效果
- 参数未正确指定时视为语法错误。
- 若未通过测试或出现下列情形,终止执行后续子命令(不位于末尾)或执行失败(位于末尾):
<entities>
或target: target
无法解析为一个或多个有效实体(指定玩家必须在线)。
- 若位于末尾且执行成功,
success
返回1。result
返回:- 匹配上的实体数(
if
)。 - 1(
unless
)。
- 匹配上的实体数(
- 示例
/execute if entity @e[type=sheep] run function foo:bar
:若世界中有绵羊就执行函数foo:bar
。/execute as @e[type=creeper] at @s unless entity @e[type=ocelot,distance=..3] run kill @s
:击杀所有在3格范围内没有豹猫的苦力怕。
(if|unless) loaded[]
- 检测给定位置是否已被加载。
- 语法
- JE:
(if|unless) loaded <pos> -> execute
- 效果
- 参数未正确指定时视为语法错误。
- 若未通过测试或出现下列情形,终止执行后续子命令(不位于末尾)或执行失败(位于末尾):
<pos>
所指定的位置位于世界外。
- 若位于末尾且执行成功,
success
和result
均返回1。
(if|unless) predicate[]
- 检测谓词(Predicate)是否通过(结果是否为正),用法详见谓词。
- 语法
- JE:
(if|unless) predicate <predicate> -> execute
- 参数
- JE:
<predicate>
:resource_location- 需要用于测试条件的谓词,其应当返回一个正值。
- 必须为命名空间ID。
- 效果
- 参数未正确指定时视为语法错误。
- 若未通过测试或出现下列情形,终止执行后续子命令(不位于末尾)或执行失败(位于末尾):
- 指定的谓词不存在。
- 若位于末尾且执行成功,
success
和result
均返回1。
(if|unless) score[]
- 检测指定目标的记分板中的记分项的分数是否与另一个(或同一个)目标的记分板的记分项的分数是否符合指定的关系,或者是否在给定的范围之内。
- 语法
- JE:
(if|unless) score <target> <targetObjective> (=|<|<=|>|>=) <source> <sourceObjective> -> execute
- BE:
<subcommand: Option_If_Unless> score <target: target> <objective: string> <operation: compare operator> <source: target> <objective: string> [chainedCommand: ExecuteChainedOption_0]
- 检测
<target>
的<targetObjective>
的分数与<source>
的<sourceObjective>
的分数是否符合特定运算符表示的关系。
- 检测
- JE:
(if|unless) score <target> <targetObjective> matches <range> -> execute
- BE:
<subcommand: Option_If_Unless> score <target: target> <objective: string> matches <range: integer range> [chainedCommand: ExecuteChainedOption_0]
- 检测
<target>
的<targetObjective>
的分数是否在指定<range>
内。
- 检测
- 参数
- JE:
<target>
:score_holder - BE:
target: target
- JE:
<targetObjective>
:objective - BE:
objective: string
- 需要检测的记分项。
- 必须为记分项的名称。
- JE:
(=|<|<=|>|>=)
- BE:
operation: compare operator
- 指定运算符,检查左操作数(目的记分项)与右操作数(源记分项)之间的关系是否符合此处定义的关系。
- JE:
<source>
:score_holder - BE:
source: target
- JE:
<sourceObjective>
:objective - BE:
objective: string
- 需要被比较的记分项。
- 必须为记分项的名称。
- JE:
<range>
:int_range - BE:
range: integer range
- 被检查分数需要符合的范围。
- 必须为整数范围。(例如
0
- 精准匹配0,..0
- 匹配小于等于0的值,0..
- 匹配大于等于0的值,0..1
- 匹配0~1的值,含)
- 效果
- 参数未正确指定时视为语法错误。
- 若未通过测试或出现下列情形,终止执行后续子命令(不位于末尾)或执行失败(位于末尾):
<target>
或target: target
、<source>
或source: target
为*
。
- 若位于末尾且执行成功,
success
和result
均返回1。
- 示例
/execute if score @s a = @s b
:检测自己的a分数与b分数是否相等。
存储子命令[]
存储子命令可以将最后一个命令的result
或success
值存储到指定位置。
它与其他子命令一起处理,先行记录存储位置,不影响其他子命令。当最后一个子命令执行后,将其返回值存入指定位置,可以是记分板、NBT数据或Boss栏。
可用存入位置:
block
:将result
或success
存入指定方块实体的指定NBT标签内。bossbar
:将result
或success
存为Boss栏的当前值或最大值。entity
:将result
或success
存入指定实体的指定NBT标签内。score
:将result
或success
存入指定分数持有者的指定记分项上。storage
:将result
或success
存入指定存储容器的指定NBT标签内。
store (result|success) block[]
- 将
result
或success
存入指定方块实体的指定NBT标签内。
- 语法
- JE:
store (result|success block <targetPos> <path> (int|float|short|long|double|byte) <scale> -> execute
- 结果
- 参数不正确时,视为语法错误。
- 路径不存在时不进行操作。
- 执行成功时,将返回值向下取整并乘以
<scale>
后存储在<targetPos>
处方块实体的<path>
NBT标签处,并存储为指定的NBT格式。
store (result|success) bossbar[]
- 将
result
或success
存为Boss栏的当前值或最大值。
- 语法
- JE:
store (result|success bossbar <id> (value|max) -> execute
- 参数
- JE:
<id>
:resource_location- 返回值需要存入的目标Boss栏的命名空间ID。
- 必须为命名空间ID。
- JE:
(value|max)
- 返回值需要存入的是Boss栏的当前值(
value
)或是最大值(max
)。
- 返回值需要存入的是Boss栏的当前值(
- 结果
- 参数不正确时,视为语法错误。
- 执行成功时,将返回值向下取整,存为命名空间ID为
<id>
的Boss栏的当前值或最大值。
store (result|success) entity[]
- 语法
- JE:
store (result|success) entity <target> <path> (int|float|short|long|double|byte) <scale> -> execute
- 结果
- 参数不正确时,视为语法错误。
- 路径不存在时不进行操作。
- 执行成功时,将返回值向下取整并乘以
<scale>
后存储在<target>
实体的<path>
NBT标签处,并存储为指定的NBT格式。
store (result|success) score[]
- 将
result
或success
存入指定分数持有者的指定记分项上。
- 语法
- JE:
store (result|success) score <targets> <objective> -> execute
- 结果
- 参数不正确时,视为语法错误。
- 执行成功时,将返回值向下取整并乘以
<scale>
后存储在<target>
持有的<objective>
分数中。
store (result|success) storage[]
- 将
result
或success
存入指定存储容器的指定NBT标签内。
- 语法
- JE:
store (result|success) storage <target> <path> (int|float|short|long|double|byte) <scale> -> execute
- 结果
- 参数不正确时,视为语法错误。
- 若目标存储容器不存在,则创建。
- 执行成功时,将返回值向下取整并乘以
<scale>
后存储在<target>
存储容器的<path>
NBT标签处,并存储为指定的NBT格式。
run子命令[]
- 要被执行的目标命令。
- 结果
- 执行此命令。指定的命令执行成功时成功,失败时失败。
更多示例[]
- 将所有快捷栏第一槽位物品带有效率魔咒的玩家传送到0, 64, 0:
/execute as @a if data entity @s Inventory[{Slot:0b}].tag.Enchantments[{id:"minecraft:efficiency"}] run tp @s 0 64 0
[仅Java版]
- 在所有玩家眼睛前方三格召唤烟雾粒子效果:
/execute as @a at @s anchored eyes run particle smoke ^ ^ ^3
[仅Java版]
- 将所有在5米以内有玩家的猪上鞍:
/execute as @e[type=pig] at @s store success entity @s Saddle byte 1 if entity @p[distance=..5]
[仅Java版]
- 让所有在水中的玩家在聊天框里说:“我的脚湿了!”:
/execute as @a at @s if block ~ ~ ~ water run say "我的脚湿了!"
- 让所有“test”记分板未设置的玩家在聊天框里说:“分数已重置”:
/execute as @a unless score @s test = @s test run say "分数已重置"
- 将距离最近的玩家3格内的所有猪扔向天空:
/execute at @p as @e[type=pig,distance=..3] run data merge entity @s {Motion:0.0,2.0,0.0]}
[仅Java版]
- 杀死所有没有头盔的僵尸:
/execute as @e[type=zombie] unless data entity @s ArmorItems[3].id run kill @s
[仅Java版]
历史[]
Java版 | |||||
---|---|---|---|---|---|
1.8 | 14w07a | 加入了/execute 命令。 | |||
14w08a | 在命令方块中运行的run 子命令现在会把成功值传回命令方块了。 | ||||
1.11 | 16w32a | 加入了方块状态支持。 | |||
1.13 | 17w45a | 语法被拆分。 | |||
17w45b | 重制了/execute store (result|success) 。 | ||||
18w02a | 加入了新的子命令以允许通过命令进行更多的控制。 | ||||
18w05a | 加入了/execute store (result|success) bossbar 。 | ||||
1.14 | 18w43a | 加入了/execute (if|unless) data 。 | |||
1.15 | 19w38a | 加入了/execute (if|unless) predicate 。
| |||
加入了/execute store (result|success) storage 。 | |||||
1.19.3 | 22w46a | 加入了/execute (if|unless) biome 。 | |||
1.19.4 | 23w03a | 加入了/execute on 、/execute (if|unless) dimension 和/execute (if|unless) loaded 。 | |||
23w04a | 为/execute on 加入了origin 关系。 | ||||
23w06a | 加入了/execute summon 。 | ||||
pre1 | 加入了/execute positioned over 。 | ||||
1.20.2 | 23w31a | 加入了/execute (if|unless) function 。 | |||
pre1 | 暂时移除了/execute (if|unless) function 。 | ||||
携带版Alpha | |||||
0.16.0 | build 1 | 加入了/execute 。
| |||
此命令的功能相当于其在Java版1.10的功能,但在/execute 中实体目标是可选的。 | |||||
基岩版 | |||||
1.19.10 | 1.19.10.20 | 更新了语法以近似匹配Java版,属于实验性玩法。 | |||
1.19.40 | 1.19.40.20 | 加入了/execute rotated 和/execute rotated as 子命令,属于实验性玩法。 | |||
1.19.40.21 | 加入了/execute facing 、/execute facing entity 和/execute align 子命令,属于实验性玩法。 | ||||
1.19.40.23 | 加入了/execute in 和/execute anchored <eyes|feet> 子命令,属于实验性玩法。 | ||||
1.19.50 | 1.19.50.23 | 1.19.10.20起的所有实验性玩法均不再属于实验性玩法。 | |||
1.19.70 | 1.19.70.21 | 移除了data: int 参数。 |
视频[]
语言