-
Bug
-
Resolution: Fixed
-
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
- /recipe give @a *
- /recipe take @a *
in them the game crashes with following error-report:
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) [...]
[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):
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.
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):
toastGui.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI((EntityLivingBase)null, this.recipesOutputs.get((int)(delta * (long)this.recipesOutputs.size() / 5000L % (long)this.recipesOutputs.size())), 8, 8);