Minecraft
  1. Minecraft
  2. MC-89174

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

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: Minecraft 15w38b, Minecraft 15w39a, Minecraft 15w39b, Minecraft 15w39c, Minecraft 15w40b, Minecraft 15w41b, Minecraft 15w42a, Minecraft 15w43a, Minecraft 15w43b, Minecraft 15w43c, Minecraft 15w44a, Minecraft 15w44b, Minecraft 15w45a, Minecraft 15w46a, Minecraft 15w47c, Minecraft 15w49a, Minecraft 15w49b, Minecraft 15w50a, Minecraft 16w06a, Minecraft 1.9 Pre-Release 1, Minecraft 1.9.2, Minecraft 16w15b, Minecraft 1.10, Minecraft 1.10.2, Minecraft 16w41a, Minecraft 16w42a
    • Fix Version/s: Minecraft 16w44a
    • Security Level: Minecraft - Public (Viewable by everyone)
    • Confirmation Status:
      Confirmed

      Description

      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 [Helper] Marcono1234 can be found in this comment.

        Issue Links

          Activity

          Hide
          Michael added a comment -

          its not a bug

          Show
          Michael added a comment - its not a bug
          Hide
          [Mod] SunCat added a comment -

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

          Show
          [Mod] SunCat added a comment - Michael, it must be "There is no such enchantment with ID 12345" or so
          Hide
          Michael added a comment -

          oops, didn't saw the 0 on the end

          Show
          Michael added a comment - oops, didn't saw the 0 on the end
          Hide
          [Helper] Marcono1234 added a comment - - edited

          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
                  {
                      //...
                  }
              }
          }
          
          Show
          [Helper] Marcono1234 added a comment - - edited 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 { //... } } }

            People

            • Assignee:
              [Mojang] Agnes Larsson
              Reporter:
              Swekob
            • Votes:
              5 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                CHK: