mojira.dev
MC-248769

"/data remove" always traverses the NBT path to the end

The bug

Unlike the other NBT operations that may stop traversing the NBT path early when the current parent NBTs are empty, /data remove always traverses the NBT path to the end.

Code analysis

net/minecraft/commands/arguments/NbtPathArgument.java

public static class NbtPath {
    ...

    public int remove(Tag target) {
        var parents = Collections.singletonList(target);

        for(var i = 0; i < nodes.length - 1; ++i) {
            parents = nodes[i].get(parents);
            // If `parents` is empty, we could return 0 here.
        }

        return apply(parents, nodes[nodes.length - 1]::removeTag);
    }

    ...
}

Comments 3

This does appear to describe a problem with the game.

Do you mean "doesn't"?
I think it actually has an affect, as in creating the parent tags if they didn't exist, like MC-208974. Not 100% sure though.

In the case of remove, the parent tags are not created. However, it has a bad effect on performance of /data remove, especially when a long NBT path is used and no parent tags are found in the middle of the process.

intsuc

(Unassigned)

Plausible

(Unassigned)

nbt

1.18.1, 1.18.2 Pre-release 2

Retrieved