The bug
The Owner tag of projectiles (arrows, snowballs, eggs, tridents, ender pearls, etc.) determines which mob/player the target mob becomes angry at when it is hit by a projectile. The Owner tag is also used by ender pearls to determine which mob/player to teleport when an ender pearl lands. Datapacks sometimes change the Owner tag of projectiles. In 1.16.5, this works properly. However, now, changing the Owner tag of projectiles does not have any effect until the world is reloaded.
To reproduce
Ender Pearl Teleportation
Spawn a mooshroom.
Throw an ender pearl straight up.
Before the ender pearl lands, run the below command:
/data modify entity @e[type=minecraft:ender_pearl,limit=1,sort=nearest] Owner set from entity @e[type=minecraft:mooshroom,limit=1,sort=nearest] UUID
Wait for the ender pearl to land. Notice that you are teleported instead of the mooshroom. ❌
Repeat steps 1-4, but this time, exit and reload the world in between steps 3 and 4. This time, when the ender pearl lands, the mooshroom is teleported instead of you. ✔
Optional: Repeat steps 1-4 in 1.16.5. The mooshroom is teleported even though you didn't reload the world. ✔
Neutral Mob Aggravation
Spawn a polar bear.
Spawn a mooshroom.
Put the below command into a repeating command block:
/execute at @e[type=minecraft:polar_bear] run data modify entity @e[type=minecraft:snowball,distance=..20,limit=1,sort=nearest] Owner set from entity @e[type=minecraft:mooshroom,limit=1,sort=nearest] UUID
Switch to survival mode.
Throw a snowball at the polar bear.
The polar bear attacks and kills you instead of the mooshroom. ❌
Throw a snowball at the polar bear again, but this time, exit and reload the world before the snowball hits the polar bear. The polar bear attacks and kills the mooshroom. ✔
Optional: Repeat steps 1-6 in 1.16.5. The polar bear attacks the mooshroom even though you didn't reload the world. ✔
Related issues
is duplicated by
Comments


At section "Neutral Mob Aggravation", you are let the polar bear attack the mooshroom based on snowball.
All mobs that is able to be angry has NBT tag "AngryAt". You can try modify the tag directly, and add the result to your report.

Directly modifying the AngryAt tag of the polar bear works as expected.

Confirmed for 1.17.1.
In my case, it affects fireballs. Reflecting Ghast fireballs back at the Ghast (using commands), after modifying the Owner NBT, doesn't trigger Return To Sender, as I'd expect it to.
The original owner is cached. As a workaround, you can force it to update by killing, unloading, or otherwise removing the original owner

Can confirm in 21w43a.

Actually, force updates like killing and unloading is okay, but at this solution, the amount of commands will be increased a lot. For example:
Feature: Change teleportation target of an ender pearl
Origin: Directly change the Owner tag.
Now:
Summon a new pearl
Modify Owner data to the new pearl
Modify Motion data to the new pearl
Kill the old one
That's why we need it to be fixed.
"The pearl will be falling down even if merge its Motion." - Someone who has the problem too

Can confirm in 1.19.3
Can confirm in 1.17.1.