Treasure2!

Treasure2!

6M Downloads

0 or <0 passed to random.nextInt when throwing gold coin into wishing well

noobanidus opened this issue ยท 3 comments

commented

Forge: 2838
Minecraft: 1.12.2
Treasure2: 1.3.5
Gottschcore: f14.23.5.2768-v1.7.0

Crash log: here

This appears to be an issue where the bounds of the integer being passed into random.nextInteger aren't being checked, and as a result triggering the "bound must be positive" misleading error (which doesn't mean the number is negative, it can also be 0).

This is the relevant line in the coin item itself; it specifies that the minimum value should be 0. I'm not entirely sure how that relates to the RandomHelper.randomInt function itself.

This most likely happens as a result of me failing to notice the comment in the file update for the most recent part of Treasure2 about deleting the custom loot tables as the treasure2 folder is roughly the same as it was in the previous version.

Either way, bounds-checking before actually calling Random.nextInteger is probably a good idea as you can either return a default value (presumably the minimum) or give a clearer error message -- or both.

commented

Ah crud. I just found the error, which is due to the new loot table setup. But you're right, I should be checking the bounds regardless.

commented

Yeah, all it takes is a typo somewhere and then a weird edge case and all of a sudden something that worked fine before is crashing... I have felt this pain myself.

commented

Fixed in v.1.3.6