The bug
When /return
is executed within an advancement reward function, it will discard all subsequent commands globally, not just the local commands that the function has.
How to reproduce
Install the data pack in Attachments
Run
/function mc-266968:a
Results
The following table shows whether each message was expected to be printed or not, and whether it was actually printed or not.
Message | Expected | Actual | |
---|---|---|---|
a-1 | Yes | Yes | ✔ |
a-2 | Yes | No | ❌ |
b-1 | Yes | Yes | ✔ |
b-2 | No | No | ✔ |
As the table suggests, say a-2
in mc-266968:a
was not executed because it was discarded by return 0
in mc-266968:b
.
Resources
data/mc-266968/functions/a.mcfunction
say a-1
advancement grant @s only mc-266968:b
say a-2
data/mc-266968/functions/b.mcfunction
advancement revoke @s only mc-266968:b
say b-1
return 0
say b-2
data/mc-266968/advancements/b.json
{
"criteria": {
"": {
"trigger": "impossible"
}
},
"rewards": {
"function": "mc-266968:b"
}
}
Code analysis
An advancement reward function is executed as an initial function, which has a frame with depth 0, regardless of the current depth. Because /return
discards all command queue entries above the depth of the currently executed function, /return
executed in an advancement reward function discards all entries, which have a depth >= 0.
Attachments
Comments 0
No comments.