Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-255912

apply_bonus with negative bonusMultiplier logs error after mining

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.19.2, 1.20.4, 24w06a
    • None
    • Confirmed
    • Data Packs, Debug
    • Low
    • Platform

      Loot function minecraft:apply_bonus with formula minecraft:uniform_bonus_count and negative bonusMultiplier can cause the block breaking process to error, when the tool used is enchanted with the enchantment specified in the function.

      This causes the XP to not drop when it should be. However, there is no known way to crash the server, it only logs error.

      Steps to reproduce
      Attached is a data pack that demonstrates the issue.

      1. Load the attached data pack
      2. Switch to survival mode
      3. Mine a diamond ore with Efficiency pickaxe
      4. Notice that no item or experience drops
      5. Check log file

      Code analysis
      Yarn 1.19.2

      ApplyBonusLootFunction implements the loot function in question. The problematic formula is UniformBonusCount only. This formula calculates the bonus count, in getValue method, as initialCount + random.nextInt(this.bonusMultiplier * enchantmentLevel + 1).

      this.bonusMultiplier is the value specified in bonusMultiplier field in the JSON file. The fromJson method that deserializes the JSON, however, does not set the minimum value for the field, allowing negative values to be used. If nextInt method is passed a value below 1, it throws an exception IllegalArgumentException: Bound must be positive, and since this.bonusMultiplier is negative, for all enchantmentLevel >= 1, this throws.

      Due to packet handling safeguards, this will not crash the server entirely, nor would it prevent block updates from occurring; the only thing prevented is dropping the XP and item stacks.

            Unassigned Unassigned
            apple502j apple502j
            Votes:
            3 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              CHK: