Jump to content

ExperienceOrb migration bug [1.18.1]


Zeram

Recommended Posts

Since 1.18 the ExperienceOrb improperly repairs items. Having one orb it sometimes may repair all armor. In the repairing method:

   private int repairPlayerItems(Player p_147093_, int p_147094_) {
      Entry<EquipmentSlot, ItemStack> entry = EnchantmentHelper.getRandomItemWith(Enchantments.MENDING, p_147093_, ItemStack::isDamaged);
      if (entry != null) {
         ItemStack itemstack = entry.getValue();
         int i = Math.min((int) (this.value * itemstack.getXpRepairRatio()), itemstack.getDamageValue());
         itemstack.setDamageValue(itemstack.getDamageValue() - i);
         int j = p_147094_ - this.durabilityToXp(i);
         return j > 0 ? this.repairPlayerItems(p_147093_, j) : 0;
      } else {
         return p_147094_;
      }
   }

the "this.value" is never been decreased. Looking to the [1.17.1] and older versions it should use "p_147094_" instead of "this.value".

 

Also the methods:

   private int durabilityToXp(int p_20794_) {
      return p_20794_ / 2;
   }

   private int xpToDurability(int p_20799_) {
      return p_20799_ * 2;
   }

merely ignore the the item specific repair cost using the default value "2" instead. Seems it should take "ItemStack" as a parameter to calculate proper remaining XP value.

So maybe the proper port should look like:
 

    private int repairPlayerItems(Player p_147093_, int p_147094_) {
        Map.Entry<EquipmentSlot, ItemStack> entry = EnchantmentHelper.getRandomItemWith(Enchantments.MENDING, p_147093_, ItemStack::isDamaged);
        if (entry != null) {
            ItemStack itemstack = entry.getValue();
            int i = Math.min(xpToDurability(itemstack, p_147094_), itemstack.getDamageValue());
            itemstack.setDamageValue(itemstack.getDamageValue() - i);
            int j = p_147094_ - this.durabilityToXp(itemstack, i);
            return j > 0 ? this.repairPlayerItems(p_147093_, j) : 0;
        } else {
            return p_147094_;
        }
    }

    private int durabilityToXp(ItemStack itemstack, int p_20794_) {
        return (int) (p_20794_ / itemstack.getXpRepairRatio());
    }

    private int xpToDurability(ItemStack itemstack, int p_20799_) {
        return (int) (p_20799_ * itemstack.getXpRepairRatio());
    }

 

Edited by Zeram
misspell
Link to comment
Share on other sites

Bug 1: spawn orb with 30 value and create two damaged item 2*29=58 damage and 2*30=60. One orb fully repairs 1th item then 2nd so outcome like from two orbs with 29 and 30 value.
Bug 2: spawn orb with value 1. It fully repair all armor with the getXpRepairRatio<2 let's say 1.68f because p_20794_ / 2 -> (int)(1 * 1.68f) / 2 = 0 -> int j = p_147094_ - 0 = p_147094_: the orb value is never being exhausted.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.