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

/data remove-ing multiple elements from a list skips every other match in sub-sequence

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: Minecraft 18w50a, Minecraft 19w02a
    • Fix Version/s: Minecraft 19w03a
    • Labels:
      None
    • Confirmation Status:
      Confirmed

      Description

      How to reproduce

      1. Place a chest and fill it with stone.
      2. Stand on the chest and try to remove the stone with this command:
        /data remove block ~ ~ ~ Items[{id:"minecraft:stone"}]
      3. Open the chest.
         Every second item was not removed

      This occurs with all kinds of NBT lists, and is not an artifact of the NBT saving/loading into memory – try a custom tag in an item tag where NBT remains pure, and the same problem occurs. The remaining items require additional /data remove commands to fully eliminate.

      If the list contains any element that does not match the filter, the next match will be removed properly. Therefore, sub-sequences of matching elements are affected.

      Code analysis by vdvman1:

      The reason for this is that the indexing does not account for the modified size of the list after an element is removed. The relevant function is used for more operations than removing, so the best fix is to traversing the list in reverse order, rather than subtracting from the index after success.
      NBTPathArgumentType$class_2207:

      private int method_9364(Tag tag_1, BiConsumer<ListTag, Integer> biConsumer_1) {
          int int_1 = 0;
          if (tag_1 instanceof ListTag) {
              ListTag listTag_1 = (ListTag)tag_1;
      
              for(int int_2 = listTag_1.size() - 1; int_2 >= 0; --int_2) { // modified line
                  if (this.field_9905.test(listTag_1.get(int_2))) {
                      biConsumer_1.accept(listTag_1, int_2);
                      ++int_1;
                  }
              }
          }
          return int_1;
      }
      

        Attachments

        1. image-2019-01-02-22-57-49-699.png
          25 kB
          [Mod] tryashtar
        2. image-2019-01-02-22-58-58-286.png
          22 kB
          [Mod] tryashtar

          Activity

            People

            • Assignee:
              boq [Mojang] Bartosz Bok
              Reporter:
              tryashtar [Mod] tryashtar
            • Votes:
              7 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                CHK: