mojira.dev
MC-80956

/entitydata outputs success message on invalid NBT tags

When trying to change an invalid tag of an entity via the /entitydata command, it won't output an error message, but instead display the alleged new NBT data, including the invalid tag.

/entitydata @e[type=!Player,c=1] {SomeInvalidTag:1}

However, executing

/entitydata @e[type=!Player,c=1] {}

afterwards will show that the tag wasn't actually applied (because entities aren't capable of actually storing it).

Solution

net.minecraft.command.CommandEntityData.processCommand(ICommandSender, String[])

NBTTagCompound nbttagcompound = new NBTTagCompound();
entity.writeToNBT(nbttagcompound);
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttagcompound.copy();
NBTTagCompound nbttagcompound2;

try {
    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 1).getUnformattedText());
}
catch(NBTException nbtexception) {
    throw new CommandException("commands.entitydata.tagError", new Object[] {nbtexception.getMessage()});
}

nbttagcompound2.removeTag("UUIDMost");
nbttagcompound2.removeTag("UUIDLeast");
nbttagcompound.merge(nbttagcompound2);

if(nbttagcompound.equals(nbttagcompound1)) {
    throw new CommandException("commands.entitydata.failed", new Object[] {nbttagcompound.toString()});
}
else {
    entity.readFromNBT(nbttagcompound);
    // The following lines were changed
    NBTTagCompound nbttagcompound3 = new NBTTagCompound();
    entity.writeToNBT(nbttagcompound3);
    if(nbttagcompound3.equals(nbttagcompound1)) {
        throw new CommandException("commands.entitydata.failed", new Object[] {nbttagcompound3.toString()});
    }
    notifyOperators(sender, this, "commands.entitydata.success", new Object[] {nbttagcompound3.toString()});
}

Linked issues

Attachments

Comments 2

Stil valid for current snapshot 15w51b.

This is explicitly not done for performance reasons.

Mario Welzig

michael

Confirmed

/entitydata, NBT

Minecraft 1.8.6, Minecraft 15w51b

Retrieved