TheMarstonConnell / randomlootmod

A RPG loot mod for Minecraft - DEPRECATED
https://www.curseforge.com/minecraft/mc-mods/random-loot-mod
Other
9 stars 10 forks source link

Game crashes when the chance for cases is 0 #95

Open bloodyshade opened 2 years ago

bloodyshade commented 2 years ago

Given the chances for cases are set to 0 in the config (which supposedly is accepted), the game will crash with the following error when it decides to roll a case when you kill a monster: java.lang.IllegalArgumentException: bound must be positive

This seems to be due line 29 of WeightedChooser: totalEntries = rnd.nextInt(totalEntries);

In this case, totalEntries would be 0 if the entries are 0 in the config, causing it to pass 0 to java.util.Random.nextInt, which seems to be invalid in the context of that function (passing 1 to nextInt() would in turn cause it to return 0, which is probably the expected outcome here).

Not sure if the best option is to check the value and fail/return earlier, changing it to totalEntries+1 when passing to nextInt or something else entirely. I'd rather leave the decision to the dev here.

Not sure it matters in this specific case, but I'm running randomloot-1.16.5-2.3.9