(Java Minecraft 1.14) How to attribute damage to a particular source?

Solution 1:

small_fireballs don't seem to store their shooter in NBT for some reason. They even disappear when the server stops. But most other projectiles store their shooter in NBT:

  • arrow: OwnerUUIDMost and OwnerUUIDLeast (not documented in the wiki yet)
  • dragon_fireball: none
  • egg: owner.M and owner.L
  • ender_pearl: owner.M and owner.L
  • experience_bottle: owner.M and owner.L
  • fireball: none
  • llama_spit: Owner.OwnerUUIDMost and Owner.OwnerUUIDLeast
  • potion: owner.M and owner.L
  • shulker_bullet: Owner.M and Owner.L (Yes, capitalised. They also store the shooter coordinates.)
  • small_fireball: none
  • snowball: owner.M and owner.L
  • spectral_arrow: Owner.OwnerUUIDMost and Owner.OwnerUUIDLeast
  • trident: Owner.OwnerUUIDMost and Owner.OwnerUUIDLeast
  • wither_skull: none

When you copy the UUID (parts) of a player to those tags, that makes it count as shot by that player in all contexts, meaning that pigmen will get angry at that player, XP will drop, they will get advancements and so on. It also works similarly in some ways with other entities, for example you can make two skeletons aggressive at each other that way.

There are also similar tags for the owner of a dog, the thrower of an item, etc.

Source: https://minecraft.gamepedia.com/Chunk_format#Projectiles (archive)