You're in Grave Danger

You're in Grave Danger

18M Downloads

Crash in Better Minecraft Fabric 1.19.2 from improper Random call

ccrvincent opened this issue ยท 3 comments

commented

Describe the bug
Server crashes on player death. Stack trace indicates that GraveHelper#deleteItemFromList is calling Random#nextInt with a 0 upper bound, which isn't valid.

Additional context
Mentioned in a server host's Discord from someone else. Looks like it's just missing an empty inventory check in deleteItemFromList.

Running BetterMinecraft FABRIC 1.19.2
Time: 2023-01-05 19:48:22
Description: Exception in server tick loop

java.lang.IllegalArgumentException: bound must be positive
    at java.base/java.util.Random.nextInt(Random.java:321)
    at com.b1n_ry.yigd.core.GraveHelper.deleteItemFromList(GraveHelper.java:71)
    at com.b1n_ry.yigd.core.GraveHelper.onDeath(GraveHelper.java:154)
    at net.minecraft.class_1309.md2fd7f0$lambda$generateGrave$0$10(class_1309.java:39112)
    at com.b1n_ry.yigd.Yigd.lambda$onInitialize$3(Yigd.java:265)
    at net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.lambda$static$2(ServerTickEvents.java:62)
    at net.minecraft.server.MinecraftServer.handler$cfi002$onEndTick(MinecraftServer.java:7821)
    at net.minecraft.server.MinecraftServer.method_3748(MinecraftServer.java:857)
    at net.minecraft.server.MinecraftServer.method_29741(MinecraftServer.java:665)
    at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer.java:257)
    at java.base/java.lang.Thread.run(Thread.java:833)
commented

Thanks for the report. Should be really easy to fix. Not quite sure when I'll have access to my computer for this next, so I'm sorry for any delay until the new update. A temporary solution would be to disable item-loss in the configs. It might not be as balanced as you would want it to be, but at least there won't be any crashes when people die with empty inventories. Also, let me know if there's any improvements you would like to see to the item loss mechanic (or anything else for that matter)

commented

I made a bare-minimum fix of making sure there's something to process and put it in a PR. Super slap-dash (I didn't even clone the repo locally, just used the web editor) but should work until you can put together something more thorough.

commented

As you maybe saw I merged the PR, and have also fixed the code from malfunctioning in the latest update of the mod I just released. Let me know if you would find anything else that's not behaving like you'd expect it to do in the mod