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
relates to 1
Attachments
Comments 4
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
{
//...
}
}
}
its not a bug