mojira.dev
MC-89174

/enchant with any invalid ID displays message "There is no such enchantment with ID 0"

After you've entered for example

/enchant @p 12345

the message you'll receive does not display the invalid ID that you've actually entered. The message will always say "There is no such enchantment with ID 0", and enchantment ID 0 does by the way exist. Same thing goes for invalid text IDs.


Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 4

Michael, it must be "There is no such enchantment with ID 12345" or so

oops, didn't saw the 0 on the end

Please link to this comment in the description

The following is based on a decompiled version of Minecraft 1.9 using MCP 9.24 beta.

The reason why this happens is because the method net.minecraft.command.CommandEnchant.execute(MinecraftServer, ICommandSender, String[]) first tries to read an enchantment number id. If this fails it tries to read an echantment string id. The returned enchantment is null if no matching enchantment was found. The problem is that if the enchantment is null it throws a NumberInvalidException with the returned enchantment, which is null and results in an ID of 0. Instead it should just print the given enchantment id String from the command.

/**
 * Callback for when the command is executed
 *  
 * @param server The Minecraft server instance
 * @param sender The source of the command invocation
 * @param args The arguments that were passed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.enchant.usage", new Object[0]);
    }
    else
    {
        EntityLivingBase entitylivingbase = (EntityLivingBase)func_184884_a(server, sender, args[0], EntityLivingBase.class);
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, 0);
        Enchantment enchantment;

        try
        {
            enchantment = Enchantment.getEnchantmentByID(parseInt(args[1], 0));
        }
        catch (NumberInvalidException var12)
        {
            enchantment = Enchantment.getEnchantmentByLocation(args[1]);
        }

        if (enchantment == null)
        {
            // Replaced this
            //throw new NumberInvalidException("commands.enchant.notFound", new Object[] {Integer.valueOf(Enchantment.getEnchantmentID(enchantment))});
            throw new CommandException("commands.enchant.notFound", new Object[] {args[1]});
        }
        else
        {
            //...
        }
    }
}

Swekob

Agnes Larsson

Confirmed

/enchant, ID, chat, command, enchant, enchantment, message, output

Minecraft 15w38b, Minecraft 15w39a, Minecraft 15w39b, Minecraft 15w39c, Minecraft 15w40b, ..., Minecraft 16w15b, Minecraft 1.10, Minecraft 1.10.2, Minecraft 16w41a, Minecraft 16w42a

Minecraft 16w44a

Retrieved