User:Aeldrion/Projects/CVM/Villager Warrior

The warrior is a villager that sells combat-related items and fights mobs that are hostiles to other villagers.

Spawning
Villager warriors spawn in villages. Newly spawned villagers have a 15% chance of turning into a warrior.

Fighting mobs
Warriors will fight any Zombie, Husk, Zombie Villager and Drowned in a 24-block radius, as well as derivate CVM mobs.

When a warrior has a target within 24 blocks, it will try to attack it every two to five seconds. If the nearest target is within four blocks, it will use meelee attacks, dealing 5 to 8 damage. Warriors can also use sweep attacks to damage multiple targets at the same time. If no target is within four blocks, it will shoot arrows instead. A warrior can accidentally shoot arrows at another mob or player if it is in front of the warrior's target.

Fleeing
After every attack, warriors will try to run away from its target. They will keep fighting quickly after even if they couldn't run away far enough.