Chelover_C60
昨天我在看问答版时,看到了这个问题
2.有很多堆as,每堆很多as重叠在一起互相之间没有区分度,如何让每堆只剩一个as

看到第二问的时候,我想到利用execute不同实体执行命令的微延迟(这个究竟该怎么称呼?)来仅给一堆盔甲架中的某一个盔甲架加标签,以此来区分不同盔甲架。因此,我写出了以下命令
  1. /execute as @e[type=minecraft:armor_stand] at @s run execute unless entity @e[distance=..0.001,type=armor_stand,tag=keep] run tag @s add keep
复制代码
但是在实际执行中,所有盔甲架都被添加了标签。由于当时比较晚,就没再继续研究,先去睡了。结果第二天发现被抢答了
第二天我在研究的时候,写了以下的命令
  1. /execute as @e[type=minecraft:armor_stand] at @s run function abc:123
复制代码
abc:123.mcfunction
  1. execute unless entity @e[distance=..0.001,type=armor_stand,tag=keep] run tag @s add keep
复制代码
在执行时,确实做到了每堆只有一个盔甲架加被添加了标签。同时,我用僵尸做了类似的实验,结果完全相同。那么问题来了:

wiki对execute的执行顺序表述如下:
游戏会在处理run后的命令和存储子命令之前,先处理其他子命令,故run后的命令和存储子命令无法影响其他子命令。run后的命令和存储子命令也无法相互影响。
——命令/execute - Minecraft Wiki,最详细的官方我的世界百科

那么上面的两种方法的主体命令都是execute,去掉run子命令后的主体命令是execute as @e[type=minecraft:armor_stand] at @s,两者没有区别,因此不存在处理顺序上的区别。run子命令后,一个是execute unless entity @e[distance=..0.001,type=armor_stand,tag=keep] run tag @s add keep,一个是function abc:123,但是由于function abc:123实际上就是execute unless entity @e[distance=..0.001,type=armor_stand,tag=keep] run tag @s add keep,所以两者还是没有区别,那么为什么执行结果就会不同呢?

雪颜の顾
把/execute as @e[type=minecraft:armor_stand] at @s run execute unless entity @e[distance=..0.001,type=armor_stand,tag=keep] run tag @s add keep
改成/execute as @e[type=minecraft:armor_stand] at @s unless entity @e[distance=..0.001,type=armor_stand,tag=keep] run tag @s add keep
试一试,或许可能就是这个原因

⊙u⊙
  1. execute as @e[type=armor_stand] at @s unless entity @e[distance=..0.01,type=armor_stand,tag=keep] run tag @s add keep

  2. execute as @e[type=armor_stand] at @s run function abc:123
  3.         #abc:123
  4.         execute unless entity @e[distance=..0.01,type=armor_stand,tag=keep] run tag @s add keep
复制代码

按照你的说法的话处理流程应该是这样...

1)
as    以所有适格对象为目标 > 筛选完毕
at    各目标使用自身坐标 > 获取完毕
unless    检测是否满足条件 > 全员通过

run tag    全员按顺序执行tag[我tag我自己]

2)
as    以所有适格对象为目标 > 筛选完毕
at    各目标使用自身坐标 > 获取完毕


run function    全员按顺序执行function[按顺序到function里走一遍]
AS1    通过unless > 给自己加tag
AS2+    不通过unless > 没有tag



Chelover_C60
雪颜の顾 发表于 2019-10-17 17:55
把/execute as @e[type=minecraft:armor_stand] at @s run execute unless entity @e[distance=..0.001,typ ...

这里加一个run execute就是为了把两段命令分割开,以此操控微延迟。
另外我试过去掉run execute,没有达到理想效果

Chelover_C60
本帖最后由 CHElover_C60 于 2019-10-17 22:09 编辑
⊙u⊙ 发表于 2019-10-17 18:16
按照你的说法的话处理流程应该是这样...

1)

/execute as @e[type=minecraft:armor_stand] at @s run execute unless entity @e[distance=..0.001,type=armor_stand,tag=keep] run tag @s add keep
第一种里at @s后接着有run execute,把两段命令分开了






来自选好最佳之后
如果你强调了run execute等于啥都没有,或者强调了所有目标选择器同时完成解析,我应该会考虑给个最佳

梓榆
本帖最后由 梓榆 于 2019-10-17 21:30 编辑

两年前的旧东西了
https://www.mcbbs.net/thread-770198-1-1.html




execute as @e at @s run execute ...
完全等价于
execute as @e at @s ...

两条命令根本没有分开,解析是一起完成的,运算是一起完成的。

事实上 ⊙u⊙ 的解释是完全正确的。as、at、unless 三个子命令按顺序执行,其中每个子命令在执行的时候会同时操作多个命令执行源(包括命令的执行者、执行位置等)。




execute as @e at @s run function ...
解析分开了,运算分开了,实体及时更新了。



源码
  1. ((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)CommandManager.literal("execute").requires((class_2168_1) -> {
  2.          return class_2168_1.hasPermissionLevel(2);
  3.       })).then(CommandManager.literal("run").redirect(commandDispatcher_1.getRoot()))).then(addConditionArguments(literalCommandNode_1, CommandManager.literal("if"), true))).then(addConditionArguments(literalCommandNode_1, CommandManager.literal("unless"), false))).then(CommandManager.literal("as").then(CommandManager.argument("targets", EntityArgumentType.entities()).fork(literalCommandNode_1, (commandContext_1) -> {
  4.          List<ServerCommandSource> list_1 = Lists.newArrayList();
  5.          Iterator var2 = EntityArgumentType.getOptionalEntities(commandContext_1, "targets").iterator();

  6.          while(var2.hasNext()) {
  7.             Entity class_1297_1 = (Entity)var2.next();
  8.             list_1.add(((ServerCommandSource)commandContext_1.getSource()).withEntity(class_1297_1));
  9.          }

  10.          return list_1;
  11.       }))))
复制代码

懒得解释了,因为我根本看不懂。

chyx
CHElover_C60 发表于 2019-10-17 20:56
这里加一个run execute就是为了把两段命令分割开,以此操控微延迟。
另外我试过去掉run execute,没有达 ...

主要的问题就是这样它分不开。
你写了一个function就分开了。


(那天晚上我写好了第一个题目,然后一看第二个题目一个命令不行,打不断,需要函数,这就得现场建数据包,又太晚了,就睡了。
我又不想发没有自己试过的指令XD
第二天起来被抢了XD)

第一页 上一页 下一页 最后一页