Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-114715

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

    XMLWordPrintable

    Details

    • Confirmation Status:
      Confirmed
    • Category:
      (Unassigned)

      Description

      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
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                boq [Mojang] Bartosz Bok
                Reporter:
                marcono1234 [Mod] Marcono1234
              • Votes:
                2 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  CHK: