The bug
If a piglin is in a hostile state due to another piglin being attacked by the player or any other mob, it will drop XP and rare drops upon death by any source (including mob damage, suffocation and /kill).
To reproduce
Construct some iron golems. Spawn multiple zombified piglins. Wait for the golems to kill the piglins. Experience orbs will be dropped, and maybe also rare drops if you're lucky.
Trap a skeleton where he can shoot at you but not escape. Spawn multiple zombified piglins in the line of fire. Experience orbs will be dropped, and maybe also rare drops if you're lucky.
Summon multiple piglins and a single Johnny vindicator. Killing the piglins with
/kill @e[type=piglin,distance=..10]
or suffocating them before their anger timer runs out (after 20-40 seconds) should cause them to drop XP, despite never having interacted with the player.
Analysis
From a decompilation of 14w21b's class "abd" method bz() (which appears to be the "for each tick" AI handler for zombified piglins), there is code that appears to be checking for whether the piglin is angry and has the UUID of who he's angry at but no actual target, and if so it attempts to find the player corresponding to the UUID. And for some reason it also sets what appears to be the "damaged by player" counter (field "aM"), even if the UUID doesn't actually correspond to a player. And further, it appears to be setting the counter to the wrong value.
It appears that it'll also set the "damaged by player" counter incorrectly when loading the zombified piglin from NBT, although in this case I'd guess it'll probably be setting it to 0 so it shouldn't matter much.
Code analysis by @unknown can be found in this comment.
Linked issues
is duplicated by 14
relates to 1
testing discovered 1
Attachments
Comments 99
Note it's not just iron golems. I've personally tested skeletons, and I suspect any mob that you can get to attack the zombie pigmen would work.
revert the fix, the gold farms are a pain to build and you should be able to reap a reward for a few hours of hard work.
also bedrock gold farms use trident killers, maybe implement those before doing this to us.
It’s been 10 years, this was now a mechanic used by player for a decade and it just broke farms. At this point this was now a feature not a bug. Revert this, it makes no sense to have done this so long after. people who did not want the xp make no sense.
Revert the fix, it broke so many farms that take hours to build. After 10 years it already became a feature.
Revert it. There’s no other functionality that creates a fully automatic xp farm than this. This only affects players who spend 10 plus hours building a massive build and it affects them negatively.
Confirmed.