-
Bug
-
Resolution: Fixed
-
Minecraft 18w50a, Minecraft 19w02a
-
None
-
Confirmed
How to reproduce
- Place a chest and fill it with stone.
- Stand on the chest and try to remove the stone with this command:
/data remove block ~ ~ ~ Items[{id:"minecraft:stone"}]
- 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; }