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

Mending incorrectly calculates overflow after full repair


    • Icon: Bug Bug
    • Resolution: Fixed
    • 23w40a
    • 1.19.4, 1.20 Release Candidate 1, 1.20.1, 1.20.2 Pre-release 2
    • None
    • Confirmed
    • Enchantments
    • Normal
    • Platform

      The bug

      (All code references are using Mojang's mappings)

      Each experience point should repair 2 durability according to ExperienceOrb#xpToDurability, but the recursive ExperienceOrb#repairPlayerItems doesn't use the correct value to calculate the xp amount left over for more repairs. It still uses the overall value of the orb for each call of repairPlayerItems instead of the amount parameter, which is the correct value after the first recursive call.

      For this issue to occur, its required that 1 item have less durability that the xp value * 2 so the function has a chance to engage in recursion.

      The fix should be as simple as using the amount parameter instead of this.value.

      To reproduce

      You can see the incorrect results by doing the following:

      1. Give yourself 2 pieces of armor both with 20 damage with
        /give @s <some_armor>{Damage:20}

        and equip them.

      2. Apply the mending enchant to both of them with
        /enchant @s mending
      3. Spawn an experience orb with a value of 11 with
        /summon experience_orb ~5 ~ ~5 {Value:11}
      4. Collect the xp orb.

      Observed result

      Both armor pieces were fully repaired, repairing 40 damage.

      Expected result

      Only 22 damage should've been repaired.

      EDIT #1: This has probably been a bug since 21w13a which included the fixes for MC-194183 and MC-205918 which I assume caused this, looking at the diff between ExperienceOrb.java for that version and 1.20-rc1.

            Dat12 [Mojang] etanaratsastaja
            Machine Maker Jake Potrebic
            4 Vote for this issue
            4 Start watching this issue