The bug
Unlike /data modify storage ..., /execute store result|success storage ... always sets the possibly modified data to the storage regardless of the success or failure of the modification. This causes the storage file to become dirty even without any modifications.
Code analysis
net.minecraft.server.commands.ExecuteCommand
private static CommandSourceStack storeData(CommandSourceStack source, DataAccessor accessor, NbtPathArgument.NbtPath path, IntFunction<Tag> function, boolean result) {
return source.withCallback((c, s, r) -> {
try {
CompoundTag data = accessor.getData();
int n = result ? r : (s ? 1 : 0);
path.set(data, () -> function.apply(n)); // The number of modifications is discarded.
accessor.setData(data); // The possibly modified data is always set.
} catch (CommandSyntaxException ex) {
}
}, CALLBACK_CHAINER);
}private static CommandSourceStack storeData(CommandSourceStack source, DataAccessor accessor, NbtPathArgument.NbtPath path, IntFunction<Tag> function, boolean result) {
return source.withCallback((c, s, r) -> {
try {
CompoundTag data = accessor.getData();
int n = result ? r : (s ? 1 : 0);
path.set(data, () -> function.apply(n)); // The number of modifications is discarded.
accessor.setData(data); // The possibly modified data is always set.
} catch (CommandSyntaxException ex) {
}
}, CALLBACK_CHAINER);
}Side note
This behavior can be observed in game by MC-208974 as follows:
Make sure that the storage
mc-248261:is empty/data get storage mc-248261:/data get storage mc-248261:→ Storage mc-248261: has the following contents: {}
/data modify storage mc-248261: _{}[] set value 0/data modify storage mc-248261: _{}[] set value 0→ Nothing changed. The specified properties already have these values
The storage is not modified by
/data modify/data get storage mc-248261:/data get storage mc-248261:→ Storage mc-248261: has the following contents: {}
/execute store result storage mc-248261: _{}[] int 0 run say !/execute store result storage mc-248261: _{}[] int 0 run say !However, the storage is modified by
/execute store/data get storage mc-248261:/data get storage mc-248261:→ Storage mc-248261: has the following contents: {_: {}}
Can confirm in 1.21: