
命令
/execute
在改变执行者、执行位置或是否执行之后运行另一条命令,并且可以保存该命令的结果。
| /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> ... |
| 参数 | 值的类型 | 输入内容 |
|---|---|---|
| <axes> | 轴 | 对于 align:字母 x、y 和 z 的任意组合,每个最多使用一次,例如 xz 或 xyz。 |
| <anchor> | 实体锚点 | 只能是feet或eyes。 |
| <targets> | 目标选择器 | 用于 as、at、positioned as、rotated as 和 facing entity 的实体。使用 store result score 时,接收该值的是分数持有者。一个或多个实体。 |
| <pos> | 精确位置 | 一个位置。对于positioned和facing,这些是X Y Z坐标,可以使用~或^。对于 if block、if biome 和 if loaded,它是方块位置。 |
| <biome> | 游戏ID或标签 | 对于 if biome:生物群系 ID 或以 # 开头的生物群系标签。某个生物群系的ID,或包含多个生物群系的 #tag。 |
| <block> | 方块测试 | 对于 if block:要查找的方块,用 ID 或带 # 的方块标签表示,可附带方块状态和数据。 |
| <start> | 方块位置 | 对于 if blocks:第一个区域的一个角。 |
| <end> | 方块位置 | 对于 if blocks:第一个区域的对角。 |
| <destination> | 方块位置 | 对于 if blocks:用于比较的区域的最低角。 |
| <source> | 方块位置 | 对于 if data、if items 和 if slots:要读取的方块位置、实体或 storage ID。对于 if score:第二个分数持有者。 |
| <path> | 数据路径 | 要测试或要存入的数据路径。 |
| <dimension> | 维度 | 某个维度的ID,例如 minecraft:overworld、minecraft:the_nether 或 minecraft:the_end。 |
| <entities> | 目标选择器 | 对于 if entity:要查找的实体。只要至少存在一个,测试就通过。一个或多个实体。 |
| <name> | 函数 | 对于 if function:函数的 ID,或以 # 开头的函数标签。 |
| <slots> | 物品槽位 | 对于 if items 和 if slots:栏位名称,例如 weapon.mainhand、hotbar.0 或 container.*,或栏位来源。 |
| <item_predicate> | 物品测试 | 对于 if items:要计数的物品,用 ID、以 # 开头的物品标签,或表示任意物品的 * 给出,之后可跟方括号中的组件测试。 |
| <predicate> | 谓词 | 对于 if predicate:数据包中谓词的 ID,或内联写出的谓词。 |
| <target> | 分数持有者 | 对于 if score:要测试的分数持有者。对于store:接收数值的方块位置、实体或存储ID。 |
| <targetObjective> | 计分板记分项 | 对于 if score:被测试分数所属的记分项。 |
| <sourceObjective> | 计分板记分项 | 对于 if score:用于比较的分数所属的记分项。 |
| <range> | 整数范围 | 对于 if score matches:整数或范围,例如5、1..10、3.. 或 ..7。对于 if stopwatch:秒数范围,允许小数。 |
| <id> | ID | 对于 if stopwatch:秒表的 ID。对于store bossbar:Boss栏的ID。 |
| <heightmap> | 高度图 | 对于positioned over:world_surface、ocean_floor、motion_blocking或motion_blocking_no_leaves。 |
| <rot> | 旋转 | 对于rotated:yaw和pitch,单位为度。~保持当前值。 |
| <scale> | 小数 | 对于store into data:保存前对数值相乘的数。 |
| <objective> | 计分板记分项 | 对于store score:接收数值的记分项。 |
| <entity> | 游戏ID | 对于summon:要召唤的实体类型的ID。某个实体的ID。 |
| 权限等级 | 2:管理员、开启作弊的世界、命令方块和函数 |
| 适用于 | 多人服务器上的管理员、启用作弊的单人世界,以及命令方块和函数。 |
| 结果 | 结果是run之后的命令的结果。当命令以if或unless测试而不是run结尾时,会显示“测试通过”或“测试失败”;对某物计数的测试(blocks、data、entity、items、slots)会显示并返回数量,其他测试返回1。 |
| 链式调用 | 子命令可以按任意顺序、任意数量组合,并从左到右依次应用。链以run和一条命令结尾,或以if或unless测试结尾。 |
| as | 将命令的执行者更改为指定的实体。该命令对每个实体各运行一次。位置和旋转不变。 |
| at | 将命令移动到给定实体的位置、旋转和维度,而不改变执行者。该命令对每个实体各运行一次。 |
| align | 将当前位置在所列轴上向下取整为完整的方块坐标。 |
| anchored | 选择局部坐标(^ ^ ^)和朝向是从执行命令的实体的脚部还是眼睛开始计算。 |
| facing | 使命令看向某个位置,或用facing entity看向实体的脚或眼睛。 |
| in | 在另一个维度中运行命令。 |
| on | 切换到与当前实体相关的实体:attacker(最后攻击它的实体)、controller(操控它的乘客)、leasher(牵着它的拴绳的实体)、origin(射出或创造它的实体)、owner(驯服动物的主人)、passengers(骑乘它的所有实体)、 target(它正在攻击的实体)或vehicle(它正在骑乘的实体)。如果没有这样的实体,命令不会运行。 |
| positioned | 将位置设为给定坐标,用positioned as设为其他实体的位置,或用positioned over设为当前X和Z处的地形顶部。 |
| rotated | 将旋转设为给定的水平和垂直角度,或用rotated as设为其他实体的旋转。 |
| summon | 在当前位置召唤一个新实体,并以该实体的身份运行命令的其余部分。 |
| if和unless | 仅在检测通过(if)或失败(unless)时继续。测试:biome、block、blocks、data、dimension、entity、function、items、loaded、predicate、score、slots和stopwatch。 |
| if blocks | 逐方块比较两个大小相同的区域。all比较每个方块;masked忽略第一个区域中的空气。该区域最多可包含32768个方块。 |
| if score | 用<、<=、=、>=或>将一个分数与另一个分数比较,或用matches检查它是否在某个范围内。如果未设置分数,测试失败。 |
| if items和if slots | if items统计容器方块或实体中所选栏位里符合物品测试的物品数量。if slots统计指定栏位名称所对应的栏位数量。 |
| if function | 运行函数或函数标签,如果返回的值不是0则通过。 |
| if stopwatch | 检查秒表经过的时间(以秒计)是否在给定范围内。如果秒表不存在,则失败并报错。 |
| if loaded | 如果该位置的区块已完全加载且其中的实体正在更新,则通过。 |
| store | 保存最后一条命令的结果。store result保存/execute store所保存的数值,store success在成功时保存1,失败时保存0。该值可以存入分数、Boss栏(value或max),或方块、实体或存储的带数字类型和缩放的数据路径。 |
| run | 使用前面的子命令所设定的一切,运行写在其后的命令。 |
| 无匹配的实体 | 如果as、at、positioned as、rotated as或facing entity没有匹配到任何实体,命令的其余部分不会运行。 |
| 分支上限 | 一条命令可拆分成多次运行的次数受游戏规则 max_command_forks 限制(默认为65536)。 |
/execute as @a at @s run setblock ~ ~-1 ~ minecraft:gold_block在每个玩家下方放置:金块。
/execute at @p run summon minecraft:lightning_bolt ~ ~ ~在最近玩家的位置劈下闪电。
/execute positioned 0 64 0 run kill @e[type=minecraft:zombie,distance=..10]杀死位置0 64 0周围10格范围内的所有僵尸类型实体。
/execute if block ~ ~-1 ~ minecraft:grass_block run say Standing on grass仅当下方的方块是草方块时才发送消息。
/execute unless entity @e[type=minecraft:creeper,distance=..16] run say No Creepers nearby仅当16个方块范围内没有苦力怕时才发送消息。
/execute if score @s kills matches 10.. run give @s minecraft:diamond 1如果你在记分项kills中的分数为10或更高,则给予你钻石。
/execute store result score @s health run data get entity @s Health将你当前的生命值保存到你在记分项health中的分数里。
/execute as @e[type=minecraft:zombie] at @s unless block ~ ~-1 ~ minecraft:air run kill @s杀死所有下方不是空气的僵尸类型实体。
/execute in minecraft:the_nether run tp @s 0 80 0将你传送到0 80 0(维度:下界)。
/execute as @a at @s anchored eyes positioned ^ ^ ^3 run particle minecraft:flame ~ ~ ~在每位玩家眼前3个方块处显示一个火焰粒子。
/execute if entity @a[gamemode=creative]测试是否有玩家处于创造模式,并报告有多少名。
/execute store success score @s has_sword run execute if items entity @s weapon.mainhand minecraft:diamond_sword如果你的主手持有钻石剑,则将你在记分项has_sword中的分数设为1,否则设为0。





