execute指令

旧版

绝对坐标

相对坐标(实体为原点,其中~代表不进行偏移)

局部坐标(在相对坐标的基础上,加入了实体的视线偏移,坐标轴随着实体视线的改变而改变,使用插入符^)

 

语法

execute <实体> <x> <y> <z> <命令>(让符合要求的实体执行指令)

比如:execute @e[type=chicken] ~ ~2 ~ summon tnt,代表在鸡的头上两格生成TNT

可以限制在指定方块被检测到时才执行命令:

execute <实体> <x> <y> <z> <命令> detect <x2> <y2> <z2> <方块> <数据/状态> <命令…>(方块数据值默认是0)

比如:execute @e[type=chicken] ~ ~ ~ detect ~ ~-1 ~ diamond_block 0 summon tnt ~ ~2 ~,代表在站在钻石块上面的鸡的头上两格生成TNT

 

旧版的缺点在于,执行实体、执行位置、执行朝向、执行维度(比如:主世界、地狱、末地)被同时修改

 

新版

execute子命令的种类:修饰子命令,条件子命令,存储子命令,run子命令

 

修饰子命令

align:矫正坐标,向下取整。比如:在(-2.7,65.2,33.9)执行指令,/execute align x run summon minecraft:sheep,代表在(-3,65.2,33.9)的位置生成羊(也可以写align xz/xyz)

anchored:修改指令执行的基准点。格式:/execute anchored <eyes/feet>。比如:/execute anchored eyes run summon minecraft:sheep ^ ^ ^1 {NoGravity:1b},代表在玩家眼睛前方一格生成羊

as:改变命令的执行者。比如:/execute as @e[type=minecraft:sheep] run summon minecraft:cow,执行实体由玩家变成了羊,由于只改变执行者,结果会在玩家的位置生成牛,牛的个数等于羊的个数

at:改变命令的执行位置、执行朝向和执行维度。比如:/execute as @e[type=minecraft:sheep] at @s run summon minecraft:cow,其中@s代表执行实体,即羊,结果会在每只羊的位置生成一头牛

facing:改变执行朝向。两种格式。1、/execute facing <坐标>;2、/execute facing entity <实体> <eyes/feet>;比如:/execute as @e[type=minecraft:villager] at @s anchored eyes facing entity Steve eyes run tp @s ~ ~ ~ ~ ~,代表让所有的村民看向Steve。第一种让执行朝向朝着某个坐标,第二种让执行朝向朝着指定实体的眼睛或脚(一般要加limit=1)

in:改变执行维度。比如:/execute in the_end positioned 11 22 33 run summon minecraft:lightening_bolt,代表在末地的(11,22,33)处生成闪电

positoned:两种格式。1、/execute positioned <坐标>;比如:/execute as @e[type=chicken] at @s positioned ^ ^ ^3 run summon cow ~ ~ ~,代表在所有鸡面前三格的位置生成一头牛;2、/execute positioned as <实体>;比如:/execute as @e[type=chicken] at @s positioned as @e[type=sheep,sort=nearest,limit=1] run summon cow ~ ~ ~,代表所有鸡在离它们最近的羊的位置生成一头牛。第一种直接改变执行位置,第二种把执行位置变成指定的实体所在的位置(一般要加limit=1)

rotated:改变执行朝向。两种格式:1、/execute rotated <x-旋转角度> <y-旋转角度>;2、/execute rotated as <实体>。第二种一般要加limit=1。和facing的区别:facing是朝向某个实体,是“看着谁”;rotated是照着选中的实体来设置执行的朝向,是“学着谁看”

 

run子命令

 

条件子命令

if <条件>:若条件成立,则执行子命令

unless <条件>:若条件不成立,则执行子命令

条件子命令可检测六种类型的条件:if/unless block/blocks/data/entity/predicate/score

其中:

if/unless <位置> <方块名称> …(比如:/execute as @e at @s if block ~ ~-1 ~ minecraft:bedrock run kill @s,代表杀死站在基岩上的实体)

if/unless data block <坐标> <路径(NBT路径格式)> …

if/unless data entity <目标实体> <路径> …(比如:/execute if data entity @s(OnGround:1b),代表检测自己是否站在地上)

if/unless data storage <存储> <路径> …

if/unless entity …(比如:/execute if entity @e[type=minecraft:creeper,distance=..10],代表检测周围十米是否具有苦力怕)

 if/unless predicate <谓词id> …

if/unless score <目标甲> <计分项A> <运算符> <目标乙> <计分项B> …

if/unless score <目标甲> <计分项A> matches <范围> …

 

存储子命令

将命令返回的结果/成功次数存储为计分板的分数/NBT的数据/boss栏的最大值/当前值

store result/success block <方块坐标> <路径> <类型(byte/short/int/long/float/double)> <倍率> …

store result/success entity <实体> <路径> <类型> <倍率> …(比如:/execute as @e[type=pig] at @s store success entity @s Saddle byte 1 if entity @p[distance=..5],代表让五米内有玩家的猪带上鞍)

store result/success storage <存储id> <路径> <类型> <倍率> …

store result/success bossbar <id> value/max …

store result/success score <目标实体/分数持有者> <计分项> …

 

posted @ 2022-05-02 16:06  树叶本子  阅读(2805)  评论(0)    收藏  举报