[SPIGOT-5298] EntityEquipment (armour, hand) drop chances are systematically wrong by -0.1. Created: 30/Aug/19  Updated: 31/Aug/19  Resolved: 31/Aug/19

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: totemo Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Environment:

Linux x86_64, Java 8, 12

Spigot versions from at least the last 5 or 6 months, potentially a lot longer.

Single test plugin.

Source code and Maven build script provided: https://github.com/totemo/TestDropChances


Version: git-Spigot-065a373-6ed8a18 (MC: 1.14.4) (build 2459)
Guidelines Read: Yes

 Description   

Spigot CraftEntityEquipment deliberately decreases drop chances by 0.1 on set and adds 0.1 on get.

    private void setDropChance(EnumItemSlot slot, float chance) {
        if (slot == EnumItemSlot.MAINHAND || slot == EnumItemSlot.OFFHAND) {
            ((EntityInsentient) entity.getHandle()).dropChanceHand[slot.b()] = chance - 0.1F;
        } else {
            ((EntityInsentient) entity.getHandle()).dropChanceArmor[slot.b()] = chance - 0.1F;
        }
    }

    private float getDropChance(EnumItemSlot slot) {
        if (slot == EnumItemSlot.MAINHAND || slot == EnumItemSlot.OFFHAND) {
            return ((EntityInsentient) entity.getHandle()).dropChanceHand[slot.b()] + 0.1F;
        } else {
            return ((EntityInsentient) entity.getHandle()).dropChanceArmor[slot.b()] + 0.1F;
        }
    }

You can use the provided test plugin (https://github.com/totemo/TestDropChances) to spawn mobs with known armour and hand drop chances.

If you spawn mobs with `/testdropchances 0.099` note that they will not drop their equipment on death ever when killed with a non-looting sword.

The NBT fields of the mob are incorrect by the 0.1 offset, as can be verified by vanilla commands:

/data get entity @e[type=minecraft:wither_skeleton,distance=..20,limit=1] ArmorDropChances
/data get entity @e[type=minecraft:wither_skeleton,distance=..20,limit=1] HandDropChances

When the mob dies, these 0.1 offsets are not taken into account by CraftBukkit n.m.s.EntityInsentient.dropEquipment() and Spigot-Server n.m.s.EntityInsentient.dropDeathLoot().

The relevant drop chance arrays are initialised to expected vanilla drop chances:

        Arrays.fill(this.dropChanceArmor, 0.085F);
        Arrays.fill(this.dropChanceHand, 0.085F);

This is the situation in the current build but also applied about 5 or 6 months ago in Spigot 1.13.2. I didn't follow up on it at the time thinking it was a temporary situation.

The offsets in CraftEntityEquipment are clearly deliberate, but I would liken them to junk DNA. Taking them out would probably resolve this.


Generated at Fri Apr 11 15:30:06 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.