mojira.dev
MC-113131

Mob item pick up behavior is not distinct resulting in mobs constantly dropping and picking up items

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

  1. Summon a mob which can pick up items

    /summon husk ~ ~ ~ {CanPickUpLoot:1b}
  2. Set the mobGriefing gamerule to true if it is not already

    /gamerule mobGriefing true
  3. Throw an undamaged chestplate at the mob

    /give @p diamond_chestplate
  4. 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

Comments 3

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

    /summon husk ~ ~ ~ {CanPickUpLoot:true}
  • Set the mobGriefing gamerule to true if it is not already

    /gamerule mobGriefing true
  • Throw a slightly undamaged chestplate at the mob

    /give @p diamond_chestplate 1
  • Throw a nearly broken damaged chestplate (with NBT) at the mob

    /give @p diamond_chestplate{Damage:1} 1

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.

marcono1234

(Unassigned)

Confirmed

(Unassigned)

CanPickUpLoot, NBT, damage-value, item, mob, skeleton, zombie

Minecraft 1.11.2, Minecraft 1.13, Minecraft 1.13.1

Retrieved