-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
In TraitBrittle.class,
The crash is happening because of this line:
Integer damageDone = random.nextInt(Math.min(5, durability - 1));The problem:
When durability = 1:
durability - 1 = 0Math.min(5, 0) = 0random.nextInt(0)-> IllegalArgumentException: bound must be positive
Random.nextInt(n) requires n > 0. You can't call nextInt(0).
fix:
public void beforeBlockBreak(@Nonnull ItemStack tool, @Nonnull BreakEvent event) {
Block block = event.getState().func_177230_c();
if (block.func_176223_P().func_185904_a() == Material.field_151576_e) {
Integer durability = ToolHelper.getCurrentDurability(tool);
if (durability > 1) { // Add this check
Integer damageDone = random.nextInt(Math.min(5, durability - 1));
ToolHelper.damageTool(tool, damageDone, event.getPlayer());
}
}
}or you can just do
Integer maxDamage = Math.max(1, Math.min(5, durability - 1)); // Ensure at least 1
Integer damageDone = random.nextInt(maxDamage);Found this while working on my modpack, thought I should report it.
Metadata
Metadata
Assignees
Labels
No labels