setRepairAmount of the PlayerItemMendEvent is broken ?

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None
    • 3216-Spigot-ff89b97-61e4ca7 (MC: 1.17.1) (Implementing API version 1.17.1-R0.1-SNAPSHOT)
    • Yes

      I tried to modify the repair amount of mending using the setRepairAmount method.
      But as soon i use this method e.g. setRepairAmount(1) the PlayerItemMendEvent will be called more then 500 times (which results that the item is instantly repaired).

      Output: https://paste.md-5.net/ajirexulic.md

      In Class A:

      @EventHandler
          public void mending(PlayerItemMendEvent event) {
              System.out.println("MENDING EVENT CALLED");
          }

      In Class B:

      @EventHandler
          public void mending(PlayerItemMendEvent event) {
              event.setRepairAmount(1);
          }
      

      (Two event listeners to be sure if the event will be called multiple times or if the debug message will be outputed multiple times)

          [SPIGOT-6708] setRepairAmount of the PlayerItemMendEvent is broken ?

          Phoenix616 added a comment - - edited

          There is definitely a behaviour change from 1.16 that might even lead to a stack overflow and disconnect of the player if a plugin changes the repaired amount.

          How it worked before: All exp was consumed and the item in question repaired for the set repair amount.

          How it works now: Only the exp that is necessary for the modified repair amount is consumed and another item is tried.

          Actually I looked into it a bit more closely and it seems like in 1.16 it actually tried additional items too, the difference being that in 1.16 the actual amount of the experience orb entity was adjusted each time the repair process was done. In 1.17 it is now a recursive method call which doesn't modify the experience orb amount.

          This means that there is no way to get the actual exp used to repair anymore in the event (previously one was able to get that from the entity in the event), imo. this could be easily solved by again updating the orb's amount like it was done before which should fix these issues as well as keep the api comatible.

          Phoenix616 added a comment - - edited There is definitely a behaviour change from 1.16 that might even lead to a stack overflow and disconnect of the player if a plugin changes the repaired amount. How it worked before: All exp was consumed and the item in question repaired for the set repair amount. How it works now: Only the exp that is necessary for the modified repair amount is consumed and another item is tried. Actually I looked into it a bit more closely and it seems like in 1.16 it actually tried additional items too, the difference being that in 1.16 the actual amount of the experience orb entity was adjusted each time the repair process was done. In 1.17 it is now a recursive method call which doesn't modify the experience orb amount. This means that there is no way to get the actual exp used to repair anymore in the event (previously one was able to get that from the entity in the event), imo. this could be easily solved by again updating the orb's amount like it was done before which should fix these issues as well as keep the api comatible.

          False added a comment -

          As workarount i use setCancelled(true) but i have to repair the item mayself then.

          Also the experience orb had 6 experience in my case, so if i set the repairamount to 1 the event should be called 6 times with your argumentation. But it was called over 500 times ;o
          So you mean to debuf the mending enchantment you have to cancel and implement the repair myself ?

          False added a comment - As workarount i use setCancelled(true) but i have to repair the item mayself then. Also the experience orb had 6 experience in my case, so if i set the repairamount to 1 the event should be called 6 times with your argumentation. But it was called over 500 times ;o So you mean to debuf the mending enchantment you have to cancel and implement the repair myself ?

          md_5 added a comment -

          I don't think it's broken.
          You are setting the amount repaired to 1, when an experience orb usually has more than 1 experience.
          It's then using the remaining experience left on the orb to try and mend other items (in this case the item again).
          One way to get out of this is with setCancelled(true)

          md_5 added a comment - I don't think it's broken. You are setting the amount repaired to 1, when an experience orb usually has more than 1 experience. It's then using the remaining experience left on the orb to try and mend other items (in this case the item again). One way to get out of this is with setCancelled(true)

            Assignee:
            Unassigned
            Reporter:
            False
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: