MineColonies

MineColonies

53M Downloads

[BUG] Mending only applies to the first Mending enchanted item when multiple such items exist

zlainsama opened this issue ยท 0 comments

commented

Is there an existing issue for this?

  • I have searched the existing issues

Are you using the latest MineColonies Version?

  • I am running the latest alpha version of MineColonies for my Minecraft version.

Did you check on the Wiki? or ask on Discord?

  • I checked the MineColonies Wiki and made sure my issue is not covered there. Or I was sent from discord to open an issue here.

What were you playing at the time? Were you able to reproduce it in both settings?

  • Single Player
  • Multi Player

Minecraft Version

1.20.1

MineColonies Version

1.1.375-BETA

Structurize Version

1.0.670-BETA

Related Mods and their Versions

No response

Current Behavior

When a citizen has multiple Mending enchanted items in their inventory, only first one got repaired.

Screenshot of a Knight's inventory

image

Expected Behavior

All Mending enchanted items get repaired.

Reproduction Steps

  1. Equip archers/druids/knights with multiple Mending enchanted items.
  2. Watch them fight mobs, take damage and survives.

Logs

https://gist.github.com/zlainsama/7a4805565e6e244c61ecea5646e05648

Anything else?

By making this line search for damaged items should fix this.

InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(citizen.getInventoryCitizen(), stack -> stack.isEnchanted() && EnchantmentHelper.getEnchantments(stack).containsKey(
Enchantments.MENDING));

Add && stack.isDamaged() so that it looks like this:
InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(citizen.getInventoryCitizen(), stack -> stack.isEnchanted() && EnchantmentHelper.getEnchantments(stack).containsKey(Enchantments.MENDING) && stack.isDamaged());
With this, fully repaired items will get skipped, allows other Mending enchanted items get repairs.

But this repairs all Mending enchanted items instead of only equipped ones, to match vanilla behavior, a search only in equipped slots is required.

In recent versions, citizens also have armor slots separated from their main inventory, a fix should also take that into consideration.