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
datapacksfolder of your worldRun the function
test:run_nested/function test:run_nested→ ❌ It did not run any of the commands from the
test:nestedfunction; you can slightly increase the value set formaxCommandChainLengthintest:run_nestedand 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.
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