Mending incorrectly calculates overflow after full repair
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:
- Give yourself 2 pieces of armor both with 20 damage with
/give @s <some_armor>{Damage:20}and equip them.
- Apply the mending enchant to both of them with
/enchant @s mending
- Spawn an experience orb with a value of 11 with
/summon experience_orb ~5 ~ ~5 {Value:11} - 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.
Created Issue:
mending incorrectly calculates overflow after full repair
(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.
You can see the incorrect results by doing the following:
- Give yourself 2 pieces of armor both with 20 damage with
/give @s <some_armor>{Damage:20}and equip them.
- Apply the mending enchant to both of them with
/enchant @s mending- Spawn an experience orb with a value of 11 with
/summon experience_orb ~5 ~ ~5 {Value:11}- Collect the xp orb and observe that both armor pieces were fully repaired, repairing 40 damage while only 22 should've been possible.
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".
(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.
You can see the incorrect results by doing the following:
- Give yourself 2 pieces of armor both with 20 damage with
/give @s <some_armor>{Damage:20}
and equip them.
- Apply the mending enchant to both of them with
/enchant @s mending- Spawn an experience orb with a value of 11 with
/summon experience_orb ~5 ~ ~5 {Value:11}- Collect the xp orb and observe that both armor pieces were fully repaired, repairing 40 damage while only 22 should've been possible.
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".(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.
You can see the incorrect results by doing the following:
- Give yourself 2 pieces of armor both with 20 damage with
/give @s <some_armor>{Damage:20}and equip them.
- Apply the mending enchant to both of them with
/enchant @s mending
- Spawn an experience orb with a value of 11 with
/summon experience_orb ~5 ~ ~5 {Value:11}
- Collect the xp orb and observe that both armor pieces were fully repaired, repairing 40 damage while only 22 should've been possible.
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".
EDIT #1: This has probably been a bug since 21w13a which included the fixes for https://bugs.mojang.com/browse/MC-194183 and https://bugs.mojang.com/browse/MC-205918
which I assume caused this, looking at the diff between ExperienceOrb.java for that version and 1.20-rc1.
(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.
You can see the incorrect results by doing the following:
- Give yourself 2 pieces of armor both with 20 damage with
/give @s <some_armor>{Damage:20}and equip them.
- Apply the mending enchant to both of them with
/enchant @s mending
- Spawn an experience orb with a value of 11 with
/summon experience_orb ~5 ~ ~5 {Value:11}
- Collect the xp orb and observe that both armor pieces were fully repaired, repairing 40 damage while only 22 should've been possible.
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".
EDIT #1: This has probably been a bug since 21w13a which included the fixes for https://bugs.mojang.com/browse/MC-194183 and https://bugs.mojang.com/browse/MC-205918
which I assume caused this, looking at the diff between ExperienceOrb.java for that version and 1.20-rc1.
(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.
You can see the incorrect results by doing the following:
- Give yourself 2 pieces of armor both with 20 damage with
/give @s <some_armor>{Damage:20}and equip them.
- Apply the mending enchant to both of them with
/enchant @s mending
- Spawn an experience orb with a value of 11 with
/summon experience_orb ~5 ~ ~5 {Value:11}
- Collect the xp orb and observe that both armor pieces were fully repaired, repairing 40 damage while only 22 should've been possible.
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".
EDIT #1: This has probably been a bug since 21w13a which included the fixes for https://bugs.mojang.com/browse/MC-194183 and https://bugs.mojang.com/browse/MC-205918 which I assume caused this, looking at the diff between ExperienceOrb.java for that version and 1.20-rc1.
mending incorrectly calculates overflow after full repairMending incorrectly calculates overflow after full repair
(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.
You can see the incorrect results by doing the following:
- Give yourself 2 pieces of armor both with 20 damage with
/give @s <some_armor>{Damage:20}and equip them.
- Apply the mending enchant to both of them with
/enchant @s mending
- Spawn an experience orb with a value of 11 with
/summon experience_orb ~5 ~ ~5 {Value:11}
- Collect the xp orb and observe that both armor pieces were fully repaired, repairing 40 damage while only 22 should've been possible.
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".
EDIT #1: This has probably been a bug since 21w13a which included the fixes for
https://bugs.mojang.com/browse/MC-194183and https://bugs.mojang.com/browse/MC-205918 which I assume caused this, looking at the diff betweenExperienceOrb.java for that version and 1.20-rc1.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.
To reproduce
You can see the incorrect results by doing the following:
- Give yourself 2 pieces of armor both with 20 damage with
/give @s <some_armor>{Damage:20}and equip them.
- Apply the mending enchant to both of them with
/enchant @s mending
- Spawn an experience orb with a value of 11 with
/summon experience_orb ~5 ~ ~5 {Value:11}
- Collect the xp orb and observe that both armor pieces were fully repaired, repairing 40 damage while only 22 should've been possible.
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.
EDIT #1: This has probably been a bug since 21w13a which included the fixes for
MC-194183andMC-205918which I assume caused this, looking at the diff between ExperienceOrb.java for that version and 1.20-rc1.
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.
To reproduceYou can see the incorrect results by doing the following:
- Give yourself 2 pieces of armor both with 20 damage with
/give @s <some_armor>{Damage:20}and equip them.
- Apply the mending enchant to both of them with
/enchant @s mending
- Spawn an experience orb with a value of 11 with
/summon experience_orb ~5 ~ ~5 {Value:11}
- Collect the xp orb and observe that both armor pieces were fully repaired, repairing 40 damage while only 22 should've been possible.
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.
EDIT #1: This has probably been a bug since 21w13a which included the fixes for
MC-194183andMC-205918which I assume caused this, looking at the diff between ExperienceOrb.java for that version and 1.20-rc1.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:
- Give yourself 2 pieces of armor both with 20 damage with
/give @s <some_armor>{Damage:20}and equip them.
- Apply the mending enchant to both of them with
/enchant @s mending- Spawn an experience orb with a value of 11 with
/summon experience_orb ~5 ~ ~5 {Value:11}- 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-194183andMC-205918which I assume caused this, looking at the diff between ExperienceOrb.java for that version and 1.20-rc1.
In 1.20.2 Pre-Release 2