What counts as a 'player kill' for purposes of mob loot/XP?

...other than obvious - sword, bow, punching.

For example, the wiki has an entry on Zombie Pigman:

Rare drops

2.5% chance to drop a gold ingot if killed by a player
8.5% chance to drop their golden sword when their death is registered as a player kill. The chances of each can be increased by 1% per level of Looting.

Experience

Zombie pigmen drop 5 experience (12 if baby), when their death is registered as a player kill.

I know there exist pigmen-based XP farms that don't involve the player attacking any pigmen directly. So what sort of deaths count as 'player kill' for the purpose of loot/XP drop? - at least from the more common/practical ones... I'm well aware there are hundreds of ways one can kill a mob.

(if you have the extra knowledge about how these affect pigmen hostility; in particular if any drop XP but don't make zombie pigmen hostile, that would be a nice addition to the answer.)


Migrated and adjusted my answer from a more specific question to this more general one.


XP and "rare drops" drop if the mob is killed by any action that the game considers "killed by player" or if it dies up to three seconds later.

These actions are:

  • direct hit
  • indirect hit with the sweeping feature of a sword
  • hit by an arrow that the player shot
  • hit by a ghast fireball that was reflected by the player
  • attacked by a dog (often used in farms, since it doesn't require player action)
  • killed by a player thrown instant damage (or instant health for undead mobs) potion
  • blown up by TNT that was ignited by the player
  • pricked on player worn thorns armour

Also, due to the bug MC-56653, angry pigmen always drop XP and rare drops. This is commonly used in gold farms.

What doesn't count as a player kill:

  • blown up by player launched firework
  • shot/instant damaged/fireballed by dispenser
  • pushed off cliff (or punched off if the fall takes more than three seconds), into cactus, lava, water, void, etc.
  • drowned or burned with water or lava bucket

Knowing these actions is really helpful if you want to kill villagers without lowering your village reputation, pigmen and wolves without angering the pack, endermen without angering them or any other mob without increasing your kill statistic (for example in Adventure maps that use that statistic).