Some types of mobs will attack players that are on the same team as them despite friendly fire being off, if the team is rapidly left and joined using advancements/predicates. Some types of mobs will even continue to attack the player in creative and spectator mode.
Start with an advancement set to cause a player to leave their team on attacking a mob.
Then, set up a repeating command block, or tick function in a datapack that will cause a player to join a team as soon as an entity is targeting them.
Spawn in a group hostile mobs, on the same team as the player on and make sure friendly fire is set to off. Then, in survival or adventure, attack one of the mobs, causing you to rapidly leave then join the team.
At this point I would assume the hostile mobs should only briefly agro, before seeing that player is back on the same team and become passive. Some mobs types function exactly like this. However, many do not.
In many cases, mob you initially hit immediately will behave as I previously described, while the ones around it will attack you, despite being on the same team. Some mobs behave slightly differently after being agro'd in this way. Here's what I found in testing:
Mobs that will a attack despite being on the same team if provoked as described above:
Vindicator
Zombie/Husk/Drowned
Vex
Bees
Zombified Piglins
Endermite/Silverfish
Ravager
Wolf
Mobs that will continue to attack a player in even if they switch to creative/spectator mode if provoked as described above:
Pillager
Evoker (only uses evoker fangs)
Shulker (Shoots straight down if targeting someone in spectator)
Blaze (Does not actively shoot in creative but predicate shows it continues to target the player)
Mobs that are bugged in some other way if provoked as described above:
Phantom
Continue to target the player according to predicates despite being on the same team. However, I was never directly attacked by one, and didn't seen to notice them swooping at the player.
Creeper
The creeper you attack will not follow you, however, its fuse will light and explode if you do not step away. If you step out of its range and the creeper begins to "calm", it will not re-trigger if you enter its range again. Not sure if this is intentional or not, but figured I should mention it just in case.
Mobs that seem to work as I'd expect them to (doesn't attack teammates):
Skeleton/Stray/Wither Skeleton (With or without bow)
Spider/Cave Spider
Guardian/Elder Guardian
Slime/Magma Cube
Ghast
Witch
Polar Bear
Mobs I could not test due to not adhering to friendly fire rules at all in the current versions/snapshots:
Piglin
Brute
Hoglin
Zoglin
I apologize if I have done a poor job explaining this issue. To make things clearer, I've attached a zip containing a simple world with a datapack and command blocks to easily replicate the bug. The attached photo shows evokers attacking me in spectator mode.
Thank you for your report!
However, this issue is Invalid.
Please put only one bug report in each ticket. It is very difficult to keep track of bugs when they are not in their own tickets.
However, please review the Bug Tracker Guidelines before creating new reports. Be sure to search for an existing issue as it is likely to have already been reported.
Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki