The bug
The gameLoopFunction
function runs after entities were updated while command blocks run before entities are updated. This makes it difficult to convert command block commands to function commands and vice versa.
How to reproduce
Place a repeating command block with the following command
/scoreboard players tag @e add hurt {HurtTime:10s}
Place two always active chain command blocks with the following commands behind it
/say @e[tag=hurt] /scoreboard players tag @e[tag=hurt] remove hurt
Power the repeating command block and hit a mob
→ The command block says the name of the mob you hitPlace the attached function
in the following directory of your world folder
data/functions/custom
Set the function
custom:hurt_test
asgameLoopFunction
/gamerule gameLoopFunction custom:hurt_test
Hit a mob
→ The function does not say the name of the mob; changing the NBT test toHurtTime:9s
solves this
Linked issues
is duplicated by 3
Attachments
Comments 2
Is there any reason why gameLoopFunction
functions have to run at this position? Placing a repeating command block in your world just to make sure a function is activated at the right time can be pretty annoying since:
you need to find to spawn chunks
changing the function name requires you to find the command block and change it there again
it requires
enable-command-block
to betrue
(likely not needed for functions themself) even though you only want to use functions
Functions are not a replacement for command blocks, they are an addition.
Currently it is likely the case that many players try to convert command block commands to functions and this behavior makes it pretty difficult to do this.
Additionally I am pretty sure while building with command blocks and using functions you might switch because something works better with command blocks respectively functions and you want to test which way works the best.
Solution: run functions in a repeating command block if it's important to run them before the entity updates.
Functions are not a replacement for command blocks, they are an addition.