The bug
All mobs that can naturally spawn with random armor or tools are intended to drop additional experience for each piece. This is explicitly included in the behavior files. For example, here is what husks use:
"minecraft:experience_reward": {
"on_death": "query.last_hit_by_player ? 5 + (query.equipment_count * Math.Random(1,3)) : 0"
}
This does not work. query.equipment_count
always returns 0 in this context, rendering it completely unfunctional.
The query itself works fine in other contexts, on both the server and client side. Other queries such as query.is_in_water
also work fine in this context.
How to reproduce
Ambiguous Vanilla Method
1. Spawn a bunch of husks or zombies or whatever
2. Kill them and observe how much experience you get
→ ❌ You get no additional experience from ones that have armor
Clean Custom Method
1. Download the attached world
2. Kill the husk wearing armor
→ ❌ No experience is dropped
This world overrides the husk behavior to remove some unneeded components, and simplifies its experience molang string to the following:
query.equipment_count * 50
Note
Fixing this naively will introduce an exploit! If mobs drop additional experience for armor they pick up, you can trivially buff the experience output of your mob farm by allowing mobs to pick up items, which they will drop on death, ready to be recycled again.
In Java Edition, mobs only give additional experience for natural equipment, not equipment picked up from the ground! For this reason, query.equipment_count
should not be used at all, but rather something different that can distinguish between natural and picked-up equipment. Also, the hand item should count as well; query.equipment_count
does not account for it.
Linked issues
testing discovered 1
Attachments
Comments 4
Good thinking. I can confirm that q.equipment_count
goes from 4 to 0 at the moment of death, even for pieces that don't drop and remain visually on the entity. I was able to verify it with an animation controller
Another problem with using q.equipment_count in this context is that it does not count tools at all, even when mobs are alive. If this bug is fixed by changing q.equipment_count to work on dead mobs and count equips before death, then MCPE-136134 should be fixed as well so that experience drops for tools.
Acutally it's not necessary to check equipment when dead. What is needed is to fix MCPE-74963 so that mobs will drop their xp before they drop their loot and equipment. And of course also change the query to one that distinguishes naturally-spawned from picked-up equips, and that counts tools held in hand.
Perhaps this is because they drop their armor as soon as they take fatal damage, but don’t drop experience until the death animation ends a second or two later.
I tried to test this with command blocks giving them armor during the death animation but it seems the equip command does not work on dead entities.