Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-248261

"/execute store" makes the storage file dirty without any modifications

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.18.1, 22w03a, 22w05a, 1.18.2 Pre-release 1, 1.18.2, 22w11a, 22w12a, 1.19 Release Candidate 2, 1.19, 1.19.1, 1.19.2, 22w42a, 1.19.3 Pre-release 3, 1.19.3 Release Candidate 1, 1.19.3 Release Candidate 2, 1.19.3, 23w03a, 1.19.4 Pre-release 3, 1.19.4, 23w12a, 23w17a, 23w18a, 1.20 Pre-release 7, 1.20.1, 23w31a, 1.20.2, 23w42a, 23w45a, 23w46a, 1.20.4, 24w14a, 1.21, 24w33a, 1.21.1, 24w36a, 1.21.3, 1.21.4, 25w04a
    • None
    • Community Consensus
    • Save Data
    • Low
    • Platform

      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);
      }
      

      Side note

      This behavior can be observed in game by MC-208974 as follows:

      1. Make sure that the storage mc-248261: is empty
        /data get storage mc-248261:

        → Storage mc-248261: has the following contents: {}

      2. /data modify storage mc-248261: _{}[] set value 0

        → Nothing changed. The specified properties already have these values

      3. The storage is not modified by /data modify
        /data get storage mc-248261:

        → Storage mc-248261: has the following contents: {}

      4. /execute store result storage mc-248261: _{}[] int 0 run say !
      5. However, the storage is modified by /execute store
        /data get storage mc-248261:

        → Storage mc-248261: has the following contents: {_: {}}

            Unassigned Unassigned
            intsuc intsuc
            Votes:
            6 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              CHK: