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

minecraft-commandsminecraft-java-edition

Let's say that I have an item which allows a player to summon blaze fireballs (minecraft:small_fireball) and shoot them where they are looking. Is it possible for me to somehow attribute damage done by these fireballs to the player that shot them?

When a blaze shoots the fireball and kills a player, the chat says 'Nik3141 was killed by blaze', but when I kill someone else with the fireballs, it says 'Username burned to death'. So the game knows that I am not a blaze shooting the projectile. Other than turning off death messages and trying to do my own custom death messages with tellraw, is it possible for me to make the chat message say 'Username burned whilst trying to escape Nik3141' or something like that automatically?

This is in a datapack, so anything using advancements is an acceptable solution.

Best Answer

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)