Mojira Archive
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

Fixed

Marcono1234

[Mojang] Bartosz Bok

2017-03-22, 05:42 PM

2019-09-10, 11:16 AM

2019-09-06, 03:24 PM

2

3

Confirmed

(Unassigned)

CanPickUpLoot, DropChances, chance, equipment, mob, pickup

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

19w37a