Nested function calls reevaluate maxCommandChainLength before queueing commands
The bug
Functions only consider the value of the gamerule maxCommandChainLength when the function starts, but should ignore any changes to it while the commands are running, see MC-124447.
However, this is not the case when a nested function is executed. In this case the length of the queued commands is compared with the current maxCommandChainLength value.
How to reproduce
- Download the attached datapack MC-143266.zip
and place it in the datapacks folder of your world - Run the function test:run_nested
/function test:run_nested
→
It did not run any of the commands from the test:nested function; you can slightly increase the value set for maxCommandChainLength in test:run_nested and the nested function will be executed
Code analysis
See net.minecraft.advancements.FunctionManager.execute(FunctionObject, CommandSource) (MCP name)
Solution: The maxCommandChainLength value could be stored in a field when the execution of a function starts and then the value of the field can be used for nested functions.
Created Issue:
Nested function calls reevaluate maxCommandChainLength before queueing commands
The bug
Functions only consider the value of the gamerule maxCommandChainLength when the function starts, but should ignore any changes to it while the commands are running, see
MC-124447.However, this is not the case when a nested function is executed. In this case the length of the queued commands is compared with the current maxCommandChainLength value.
How to reproduce
- Download the attached datapack [^###] and place it in the datapacks folder of your world
- Run the function test:run_nested
/function test:run_nested→
It did not run any of the commands from the test:nested function; you can slightly increase the value set for maxCommandChainLength in test:run_nested and the nested function will be executed
Code analysis
See net.minecraft.advancements.FunctionManager.execute(FunctionObject, CommandSource) (MCP name)
Solution: The maxCommandChainLength value could be stored in a field when the execution of a function starts and then the value of the field can be used for nested functions.
The bug
Functions only consider the value of the gamerule maxCommandChainLength when the function starts, but should ignore any changes to it while the commands are running, see
MC-124447.However, this is not the case when a nested function is executed. In this case the length of the queued commands is compared with the current maxCommandChainLength value.
How to reproduce
- Download the attached datapack [^###] and place it in the datapacks folder of your world
- Run the function test:run_nested
/function test:run_nested→
It did not run any of the commands from the test:nested function; you can slightly increase the value set for maxCommandChainLength in test:run_nested and the nested function will be executed
Code analysis
See net.minecraft.advancements.FunctionManager.execute(FunctionObject, CommandSource) (MCP name)
Solution: The maxCommandChainLength value could be stored in a field when the execution of a function starts and then the value of the field can be used for nested functions.
The bug
Functions only consider the value of the gamerule maxCommandChainLength when the function starts, but should ignore any changes to it while the commands are running, see
MC-124447.However, this is not the case when a nested function is executed. In this case the length of the queued commands is compared with the current maxCommandChainLength value.
How to reproduce
- Download the attached datapack MC-143266.zip
and place it in the datapacks folder of your world
- Run the function test:run_nested
/function test:run_nested→
It did not run any of the commands from the test:nested function; you can slightly increase the value set for maxCommandChainLength in test:run_nested and the nested function will be executed
Code analysis
See net.minecraft.advancements.FunctionManager.execute(FunctionObject, CommandSource) (MCP name)
Solution: The maxCommandChainLength value could be stored in a field when the execution of a function starts and then the value of the field can be used for nested functions.
relates to
relates to
relates to
As the title says, Function command returns wrong number of commands executed for embedded functions.
As far as I see, this wrong number of command is considered by the maxCommandChainLength game rule.
A data pack to replicate this issue is available in the attachment section here. (dp.zip)
Example: Given two functions:
liach:output
function liach:output/do
liach:output/do
say Expected to have 2 commands ran in the function liach:output
Execution result of liach:output (Looks wrong)
[liach] Expected to have 2 commands ran in the function liach:output
Executed 3 commands from function 'liach:output'
Execution result of liach:output/do (Looks right)
[liach] Expected to have 2 commands ran in the function liach:output
Executed 1 commands from function 'liach:output/do'
What I expect for execution result of liach:output
[liach] Expected to have 2 commands ran in the function liach:output
Executed 2 commands from function 'liach:output'
The data pack containing these 2 functions is attached below (note that there is a few unrelated functions for testing other bugs)
I am working on a solution that fixes this bug, MC-143266, MC-143269, and MC-126946 at the same time. Will update when I get progress.
The bug
maxCommandChainLength and maxCommandForkCount are only obtained and copied when commands are executed at the top level, which creates a new execution context. Changes in these gamerules usually do not affect execution under that execution context.
However, because functions executed as advancement rewards are also executed at the top level, you can execute a function under another execution context with possibly modified maxCommandChainLength and maxCommandForkCount. Considering MC-143266, this behavior may be unintentional.
How to reproduce
/function mc-265773:test_4
→ Both 1 and 2 are printed
/function mc-265773:test_3
→ Only 1 is printed
/function mc-265773:test_4
→ Both 1 and 2 are printed
These results imply that maxCommandChainLength modified in a function affects the execution of a function executed as a advancement reward.
{
"criteria": {
"": {
"trigger": "impossible"
}
},
"rewards": {
"function": "mc-265773:a"
}
}
advancement revoke @s only mc-265773:a say 1 say 2
gamerule maxCommandChainLength 3 advancement grant @s only mc-265773:a
gamerule maxCommandChainLength 4 advancement grant @s only mc-265773:a
A removal of chain length check for new function addition and addition of check to the chain after a regular execution should resolve this.
https://github.com/liachmodded/MC-126946-128565/blob/2cbe0650ebe385027e484e7496fc63ebba690cad/src/main/java/com/github/liachmodded/datapacks/mixin/CommandFunctionManagerMixin.java#L71