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

"item_durability_changed" triggers when base change is 0, but not when Unbreaking reduces the change to 0

XMLWordPrintable

    • Confirmed

      Reproduction

      Given the following advancement, placed in world/data/advancements/custom/unbreaking.json:

      {
          "criteria": {
              "custom_test_name": {
                  "trigger": "minecraft:item_durability_changed"
              }
          }
      }
      

      And the following commands to test it at will:

      /advancement test @p custom:unbreaking
      /advancement revoke @p custom:unbreaking

      If an item receives a base durability change of 0, the advancement will trigger. This can be done by casting a fishing rod and reeling it in while the bobber is still in the air. However, if an item receives 1+ durability loss, and that loss is reduced to 0 by the Unbreaking enchantment, the advancement will not trigger.

      Reason

      Using names from MCP1.11+, the ItemStack.attemptDamageItem() method checks first if the incoming durability is 0, performs the Unbreaking enchantment, and returns false if the resulting loss is 0:

      if (amount > 0)
      {
          // Modify with Unbreaking enchantment
      
          if (amount <= 0)
          {
              return false;
          }
      }
      
      // Activate "item_durability_changed" trigger
      

      Since the trigger is activated after the if statement, it cannot activate if Unbreaking reduces durability to 0.

      One solution could be to only activate the trigger if durability loss is 1+ (activating the trigger after the nested if statement), while another solution could be to include 0 durability loss. The first solution may be preferable for consistency since the Unbreakable tag does prevent the trigger from activating altogether, but the second solution could be fun for detecting the player reeling in a rod without catching anything.

            dinnerbone [Mojang] Nathan Adams
            skylinerw [Mod] Skylinerw
            Votes:
            3 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: