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.

Every two to five seconds, the warrior will shoot arrows at its target if it is further than four blocks away. If the target is within four blocks, it will use meelee attacks instead, dealing 5 to 8 damage. The warrior will also try to get closer to the mob it is fighting.

If there are multiple targets within four blocks, the warrior will use a sweep attack and damage all targets at the same time.

Fleeing
When a warrior is damaged and has under 10 health points, it will stop fighting and run away, like other villagers do.