The bug
Based on 1.11.2 decompiled using MCP 9.35 rc1
The rules for when a mob which can pick up items should pick up items are currently (method net.minecraft.entity.EntityLiving.updateEquipmentIfNeeded(EntityItem)
):
(itemToCheck.getDamage() < itemEquipped.getDamage()) OR (itemToCheck.hasTagCompound() AND NOT(itemEquipped.hasTagCompound()))
Note: This shows the pseudo code with the fix for MC-44283.
The problem here is that if the mob has a less damaged item equipped but the item to pick up has NBT data it will swap the equipped item. However, after that the item to pick up is less damaged and therefor the mob swaps them items again and so on.
How to reproduce
Summon a mob which can pick up items
/summon husk ~ ~ ~ {CanPickUpLoot:1b}
Set the
mobGriefing
gamerule totrue
if it is not already/gamerule mobGriefing true
Throw an undamaged chestplate at the mob
/give @p diamond_chestplate
Throw a damaged chestplate (with NBT) at the mob
/give @p diamond_chestplate{Enchantments:[{id:unbreaking,lvl:1s}],Damage:1}
❌ The mob constantly swaps the items
Note: Because of MC-44283 the item in step 3 has to be nearly broken while the item in step 4 has to be slightly damaged.
Linked issues
is cloned by 1
Comments 3
The steps provided by @@unknown work in 1.13.2 but do not work in the latest versions (currently 20w28a). It appears the Damage
tag is ignored when determining whether the item has NBT. However, simply adding another tag (such as Enchantments
or display
) allows reproducing this bug in 1.13.2 and in the latest versions.
Resolving this as "Cannot Reproduce" (even though the reproduction steps still work) and using MC-193313 as clone instead because there were some versions in between, including 1.15.2 where this issue did not occur because mobs did not prefer enchanted items over unenchanted ones.
As per 1.13.1 the behavior still exists, albeit under slightly different conditions:
Item A must have no NBT tags.
Item B must be damaged.
In 1.13.1 equipment damage appears to be stored as an NBT tag, implying that:
Item A in the above cannot be enchanted, nor damaged.
Item B will exhibit its behavior whether it is enchanted or not.
So as per 1.13.1 the reproduction steps are:
Summon a mob which can pick up items
Set the
mobGriefing
gamerule totrue
if it is not alreadyThrow a
slightlyundamaged chestplate at the mobThrow a
nearly brokendamaged chestplate (with NBT) at the mob