Skip to content

Brittle Modifier (TCon Compat) causes server crash when on 1 durability #485

Open

Description

@CrafterDaemon

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 = 0
  • Math.min(5, 0) = 0
  • random.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.

Activity

  1. changed the title [-]Brittle Modifier (TCon Compat) causes server crash with veinminer or on 1 durability[/-] [+]Brittle Modifier (TCon Compat) causes server crash when on 1 durability[/+] on Dec 29, 2025
  2. SkyBlade1978 commented on Sep 29, 2026

    @SkyBlade1978
    Contributor

    @dshadowwolf I suggest this needs a fix in MMDLib, maybe sonething like

    final int durability = ToolHelper.getCurrentDurability(tool);
    if (durability <= 1) {
    return;
    }

    final int damageDone = random.nextInt(Math.min(5, durability - 1));
    ToolHelper.damageTool(tool, damageDone, event.getPlayer());

    In TraitBrittle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions