mojira.dev
MC-143952

data/chunks.dat isn't saved if the most recent /forceload command failed

If at the time of saving the world, the most recent /forceload add or /forceload remove command failed (e.g. if a data pack does /forceload add to the same chunk periodically), then no changes to any force-loaded chunks are saved at all.

The cause of this is that a single chunk's dirty state overwrites the dirty state of all force-loaded chunks (which are stored in chunks.dat).

Reproduction steps:

  1. /forceload add 0 0
  2. /forceload add 0 0
  3. Save and restart the world.

  4. /forceload query

    → ❌  No force loaded chunks were found in minecraft:overworld

Code analysis (by @unknown):
In net.minecraft.server.level.ServerLevel#setChunkForced, the dirty state of chunks.dat is set to the result of addition/removal of a forced chunk. If the server saves/stops with the dirty state false, forced chunks will not be saved in chunks.dat properly.

Linked issues

Comments 9

Confirmed for 1.15.2 and 20w08a.

Precise reproduction steps:

  1. /forceload add 0 0
  2. /forceload add 0 0
  3. Save and restart the world.

  4. /forceload query

    → ❌ No force loaded chunks were found in minecraft:overworld

Code analysis:

In net.minecraft.server.level.ServerLevel#setChunkForced, the dirty state of chunks.dat is set to the result of addition/removal of a forced chunk. If the server stops with the dirty state false, forced chunks will not be saved in chunks.dat properly.

I can also confirm this for 1.15.2. Does anyone know of any workarounds for this issue?

@atenfyr
The cause of this issue is that a dirty state of a single chunk overwrites the dirty state of all the forceload chunks (chunks.dat). A workaround is never to make /forceload add|remove fail by using the following functions whenever adding/removing a forceload chunk. Then the chunks.dat is kept dirty and is always saved.

  • forceload/add.mcfunction

    execute store success storage mc-143952: marked byte 1.0 run forceload query ~ ~
    execute if data storage mc-143952: {marked: false} run forceload add ~ ~
  • forceload/remove.mcfunction

    execute store success storage mc-143952: marked byte 1.0 run forceload query ~ ~
    execute if data storage mc-143952: {marked: true} run forceload remove ~ ~

@intsuc

Making sure that the latest /forceload command on a server doesn't fail did the trick. Thanks!

Can confirm for 22w19a, this is also the same as MC-170764

Confirmed in 1.19.3. Can someone please update the title and description to actually be accurate? The issue has nothing to do with whether it was one chunk or multiple chunks. The title should communicate that data/chunks.dat doesn't save if the most recent /forceload command failed at the time of saving. The first comment's reproduction steps and code analysis would be good to replace the current inaccurate description.

If appropriate, I wouldn't mind taking ownership of this issue and making these edits myself.

@unknown, ticket is yours now.

Can confirm for version 1.19.4. Still a real issue.

Can confirm in 1.21

Syl2010

GrantGryczan

(Unassigned)

Community Consensus

Platform

Normal

Commands

command, world

Minecraft 1.13.2, 1.15.2, 20w08a, 20w16a, 20w17a, ..., 1.19.4, 1.20.1, 23w32a, 23w35a, 1.21

25w02a

Retrieved