Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-120572

/recipe crashes the game

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 20w17a
    • Minecraft 1.12.1, Minecraft 1.12.2, Minecraft 18w07c, Minecraft 1.13-pre5, Minecraft 1.13, Minecraft 18w31a, Minecraft 1.13.1, Minecraft 1.13.2, Minecraft 19w03b, Minecraft 19w03c, Minecraft 1.14 Pre-Release 2, Minecraft 1.14 Pre-Release 3, Minecraft 1.14 Pre-Release 4, Minecraft 1.14 Pre-Release 5, 1.15.2, 20w06a, 20w07a
    • Confirmed
    • Commands, Crash

      The bug & how to reproduce it

      If a redstone clock powers command blocks with

      1. /recipe give @a *
      2. /recipe take @a *

      in them the game crashes with following error-report:

      18w07c
       
      Description: Unexpected error 
      
      java.lang.ArithmeticException: / by zero 
      at bjz.a(SourceFile:41) 
      at bkc$a.a(SourceFile:115) 
      at bkc.a(SourceFile:35) 
      at bib.az(SourceFile:1025) 
      at bib.a(SourceFile:419) 
      at net.minecraft.client.main.Main.main(SourceFile:123) 
      [...] 
      
      1.13-pre5
      [15:21:49] [Server thread/INFO]: [@: Took 524 recipes from Gewinner413]
      [15:21:49] [Server thread/INFO]: [@: Unlocked 524 recipes for Gewinner413]
      [15:21:49] [Client thread/FATAL]: Unreported exception thrown!
      java.lang.ArithmeticException: / by zero
      	at cgu.a(SourceFile:44) ~[1.13-pre5.jar:?]
      	at cgx$a.a(SourceFile:112) ~[1.13-pre5.jar:?]
      	at cgx.a(SourceFile:32) ~[1.13-pre5.jar:?]
      	at cep.c(SourceFile:810) ~[1.13-pre5.jar:?]
      	at cep.a(SourceFile:373) [1.13-pre5.jar:?]
      	at net.minecraft.client.main.Main.main(SourceFile:143) [1.13-pre5.jar:?]
      

      The .zip file is the world that you can see on the picture with the setup. YouTube video showing the bug.

      Code analysis

      The following is based on a decompiled version of Minecraft 1.12.1 using MCP 9.40pre-1 with new mappings. Code analysis by Bemoty

      The code line causing this exception to be thrown is (MCP line 43):

      net.minecraft.client.gui.toasts.RecipeToast.draw()
      toastGui.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI((EntityLivingBase)null, this.recipesOutputs.get((int)(delta / (5000L / (long)this.recipesOutputs.size()) % (long)this.recipesOutputs.size())), 8, 8);
      

      The problem appears to be that the algorithm to determine which item of the item recipes the player receives should be shown in the recipe toast divides delta by zero whenever (long)this.recipesOutputs.size() is > 5000L.

      net.minecraft.client.gui.toasts.RecipeToast.draw()
      this.recipesOutputs.get((int)(delta / (5000L / (long)this.recipesOutputs.size()) % (long)this.recipesOutputs.size()))
      

      Forge team fixed this issue by simply rearranging arithmetic operations in order to make divisions by zero impossible (given that this.recipesOutputs.size() can never be zero):

      FIX: net.minecraft.client.gui.toasts.RecipeToast.draw()
      toastGui.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI((EntityLivingBase)null, this.recipesOutputs.get((int)(delta * (long)this.recipesOutputs.size() / 5000L % (long)this.recipesOutputs.size())), 8, 8);
      

        1. 2017-09-08_16.38.47.png
          172 kB
          Linus Nadler
        2. crash-2017-09-08_17.40.38-client.txt
          11 kB
          [Mod] bemoty

            xilefian [Mojang] Felix Jones
            Linde0404 Linus Nadler
            Votes:
            12 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: