The bug
This is basically MC-121934, but only for certain cases. Currently known to be affected:
/execute store (result|success) entity
/execute store (result|success) score
/execute (if|unless) score
Reproduction steps for store
, provided by @@unknown:
/summon minecraft:pig ~ ~ ~ {NoAI:1b,Tags:["foo","A"]}
/summon minecraft:pig ~ ~ ~ {NoAI:1b,Tags:["foo","B"]}
/scoreboard objectives add X dummy
/scoreboard objectives setdisplay sidebar X
/scoreboard players set @e[tag=foo] X 42
/execute as @e[tag=foo] at @s store result score @s[tag=A] X run say hi
/execute as @e[tag=foo] at @s store result score @s[tag=B] X run say hi
/execute as @e[tag=foo] at @s store result score @s[tag=foo] X run say hi
Expected behavior: In the last 3 lines, A and B to update the score of each respective pig only, and the final line updates both scores.
Actual behavior: The first 2 of the last 3 lines fail and only the final line updates both scores.
Reproduction steps for if/unless score
:
/summon armor_stand ~ ~ ~ {NoGravity:1b,Marker:1b,Tags:[A],CustomName:"\"A1\""}
/execute at @e[tag=A] run summon armor_stand ~ ~ ~1 {NoGravity:1b,Marker:1b,Tags:[A],CustomName:"\"A2\""}
/scoreboard objectives add X dummy
/scoreboard objectives setdisplay sidebar X
/scoreboard players set @e[tag=A] X 1
/execute as @e[tag=A] at @s positioned ~ ~ ~1 run say @e[distance=..0.1]
/execute as @e[tag=A] at @s positioned ~ ~ ~1 if entity @e[tag=A,distance=..0.1,limit=1] run say hi
/execute as @e[tag=A] at @s positioned ~ ~ ~1 if score @e[tag=A,distance=..0.1,limit=1] X = @s X run say hi
The third to last line is just to ensure the setup is correct, expected (and actual) output is
[A1] A2
[A2]
The second to last line is to demonstrate that 'execute..as..at..if entity' works with a particular selector, it correctly outputs "[A1] hi".
The final line fails "No entity found". It should succeed exactly as the previous line does, since the scores match (all are 1).
Code analysis
Code analysis by @unknown can be found in this comment.
Linked issues
Attachments
Comments 4
Here are repro steps:
/summon minecraft:pig ~ ~ ~ {NoAI:1b,Tags:["foo","A"]}
/summon minecraft:pig ~ ~ ~ {NoAI:1b,Tags:["foo","B"]}
/scoreboard objectives add X dummy
/scoreboard objectives setdisplay sidebar X
/scoreboard players set @e[tag=foo] X 42
/execute as @e[tag=foo] at @s store result score @s[tag=A] X run say hi
/execute as @e[tag=foo] at @s store result score @s[tag=B] X run say hi
/execute as @e[tag=foo] at @s store result score @s[tag=foo] X run say hi
In the last 3 lines, EXPECT the A and B to update score of each respective pig only, and final foo line to update both. ACTUAL is that A and B lines fail, but final line does update both scores.
Here are the repro steps for the 'score' version of the bug:
/summon armor_stand ~ ~ ~ {NoGravity:1b,Marker:1b,Tags:[A],CustomName:"\"A1\""}
/execute at @e[tag=A] run summon armor_stand ~ ~ ~1 {NoGravity:1b,Marker:1b,Tags:[A],CustomName:"\"A2\""}
/scoreboard objectives add X dummy
/scoreboard objectives setdisplay sidebar X
/scoreboard players set @e[tag=A] X 1
/execute as @e[tag=A] at @s positioned ~ ~ ~1 run say @e[distance=..0.1]
/execute as @e[tag=A] at @s positioned ~ ~ ~1 if entity @e[tag=A,distance=..0.1,limit=1] run say hi
/execute as @e[tag=A] at @s positioned ~ ~ ~1 if score @e[tag=A,distance=..0.1,limit=1] X = @s X run say hi
The third to last line is just to ensure the setup is correct, expected (and actual) output is
[A1] A2
[A2]
The second to last line is to demonstrate that 'execute..as..at..if entity' works with a particular selector, it correctly outputs "[A1] hi".
The final line fails "No entity found". It should succeed exactly as the previous line does, since the scores match (all are 1).
After poking through the decompiled code, I think the problem is that various 'scoreholder contexts' for entity selectors are throwing exceptions, rather than simply returning empy collections and failure results. Exceptions should not be used for 'expected failures' such as 'selector that targets no entities', as it breaks the overall control flow through an execute subcommand loop. It might be non-trivial to find all such exception-sources in the source code via inspection, however an appropriate exception handler at the 'root' of commands (e.g. whatever existing handler is printing out the red "No entity was found" message in chat) that logs the stack traces of these caught-exceptions could be used to help find all the call stacks which throw exceptions inappropriately, so they may be fixed over time.
Testing reveals this is actually MC-121934 for
store
. Description needs to be updated.