mojira.dev
MC-114715

Mobs picking up items can drop their current item even with drop chance of 0

The bug

Mobs with a drop chance of 0 can still drop their item when they pick up a better item. With a drop chance of exactly 0 this happens in about 10% of the cases where a mob picks up an item.

How to reproduce

  1. Summon multiple mobs with a drop chance of 0. Do this for example by using the following command multiple times

    /execute @e ~ ~ ~ /summon husk ~ ~ ~ {CanPickUpLoot:1b,HandItems:[{id:"stone",Count:1b}],HandDropChances:[0f,0f]}
  2. Summon a better item for all mobs

    /execute @e[type=husk] ~ ~ ~ /summon item ~ ~ ~ {Item:{id:"wooden_sword",Count:1b}}
  3. Wait until the mobs have picked up the sword

  4. List all items

    /say @e[type=item]

    → You should see stone items being listed; if not repeat the steps again

Code analysis

Based on 1.11.2 decompiled using MCP 9.35 rc1

The method net.minecraft.entity.EntityLiving.updateEquipmentIfNeeded(EntityItem) uses the condition (double)(this.rand.nextFloat() - 0.1F) < dropChance to drop the current item. This creates problems like this because for example 0 - 0.1 < 0. Additionally this calculation breaks the concept of drop chances. For example a very unlikely dropped item with a chance of 0.0001% is suddenly dropped in 10.0001% of all cases where a mob picks up an item.

A better calculation could for example be

(double)(this.rand.nextFloat()) * 0.9 < d0

Linked issues

Comments 2

Confirmed for 1.13.1.

But if this bug is fixed, can pick up items mobs (e.g zombies) may no longer always drop they pick up items.

marcono1234

boq

Confirmed

(Unassigned)

CanPickUpLoot, DropChances, chance, equipment, mob, pickup

Minecraft 1.11.2, Minecraft 17w06a, Minecraft 1.12.2, Minecraft 1.13-pre1, Minecraft 1.13.1

19w37a

Retrieved