The bug
When enabling or reloading a data pack that has functions for both #tick
and #load
, the former function tag runs before the latter, which causes problems in some cases such as initializing scoreboard values before increasing them per tick. The bug occurs since 1.13.
#load
should run before #tick
to make it intuitive for other players.
How to reproduce
Install the data pack below in a world for better reproduction.
Ensure the
gametime
scoreboard objective does not exist before enabling the data pack.Use either of the following commands to enable the data pack:
/reload /datapack enable <name>
Observe the value of
$game
in the sidebar after a few seconds.
→ ✔ The value starts from-2147483648
and then increases per tick.Use the following commands quickly to reset the
$game
value:/reload /scoreboard players reset $game gametime
→ ❌ The value starts from
1
instead of the minimum integer value.
Log
Log snippet by @unknown can be found in this comment and below:
[22:18:18] [Render thread/INFO]: [CHAT] Reloading!
[22:18:18] [Server thread/INFO]: Loaded 0 recipes
[22:18:18] [Server thread/INFO]: Loaded 0 advancements
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onLoad
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onTick
From there, the #load
function tag of a data pack sends an "onLoad" message in chat, and the #tick
function tag sends an "onTick" message.
After enabling or reloading the data pack, it shows the "onTick" message once before showing the "onLoad" message. The data pack then continues sending "onTick" messages for each tick.
Code analysis
Code analysis by @unknown can be found in this comment.
Attachments
Comments 6
Confirmed for 1.16.3
The log file snippet:
[22:18:18] [Render thread/INFO]: [CHAT] Reloading!
[22:18:18] [Server thread/INFO]: Loaded 0 recipes
[22:18:18] [Server thread/INFO]: Loaded 0 advancements
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onLoad
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onTick
[22:18:18] [Server thread/INFO]: [Server] onTick
Code analysis in ServerFunctionManager
public void tick() {
// should move this line ...
this.executeTagFunctions(this.ticking, TICK_FUNCTION_TAG);
if (this.postReload) {
this.postReload = false;
List<CommandFunction> list = this.library.getTags().getTagOrEmpty(LOAD_FUNCTION_TAG).getValues();
this.executeTagFunctions(list, LOAD_FUNCTION_TAG);
}
// ... down here
}
Affects 1.18.1.
Here's a minimal pack for 1.18: https://cdn.discordapp.com/attachments/740584574320640104/919988870047748117/MC-187539.zip
I can confirm for 1.19-rc2, and very likely for 1.19 since I believe they won't fix it today before the release.
Confirmed for 1.16 Pre-Release 7