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


    • Icon: Bug Bug
    • Resolution: Fixed
    • Minecraft 19w03a
    • Minecraft 18w50a, Minecraft 19w02a
    • None
    • Confirmed

      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.

      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);
          return int_1;

            boq [Mojang] Bartosz Bok
            tryashtar [Mod] tryashtar
            7 Vote for this issue
            4 Start watching this issue