The bug
If a new data storage file (.dat file under the data directory) is added, it can usually be loaded successfully while the world is opened.
However, if the file was failed to be loaded previously after the world was opened, it cannot be loaded until the world is reopened.
How to reproduce
Open a world
Run
/data get storage mc-263058: a
Move the attached data storage file under the data directory
Run
/data get storage mc-263058: a
→ ❌ Found no elements matching a
If step 2 is skipped, the command in step 4 will succeed.
Code analysis
net/minecraft/world/level/storage/DimensionDataStorage.java
@Nullable
public <T extends SavedData> T get(Function<CompoundTag, T> load, String key) {
SavedData data = this.cache.get(key);
if (data == null && !this.cache.containsKey(key)) {
data = this.readSavedData(load, key);
this.cache.put(key, data);
}
return (T)data;
}
DimensionDataStorage#get
attempts to read saved data when the value corresponding to the given key in the cache is null
and the cache does not contain the key. Here, DimensionDataStorage#readSavedData
returns null
if the read fails, but this result is also cached. Once this happens, it no longer meets the latter condition, and the saved data of the key cannot be read until the world is reopened.
Modifying your world data while the world is opened is not supported.