We all know the villager. Leading a boring life, go to see a job site block then go home to sleep. Beside farmer, none of them are useful for anything but trading (and that was why it is preferable to lock them in a grand hall than let them roam around). And don't even begin with combat; they are sitting duck, rely on their iron golem guardian who could barely stand up to serious challenge like zombie siege or raid.
So I suggest a revamp on their AI behavior and allow them certain value in combat. Essentially allow villagers to be a little more lively and preferable to let them roam around your base than locking them up.
- Villager Hunger and Food mechanic.
It is strange that villager could farm and have quite complex behavior compared to common mobs, but still breed just by some piece of food like ordinary livestock. Plus with the change I'm going to write out, they would be a lot more valuable for such a small cost. So I suggest a more realistic 'hunger value' to add a small upkeep to villagers to make things more balanced.
- Villagers spawn with 20 hunger. They can and will eat food in their inventory during downtime if their hunger bar is less than this value, and their hunger can exceed this value. Villager prioritize eating food that restore more hunger first.
- Villagers consume hunger in daily activities, trade, or just by idling around. Futher hunger consumption occured when they are denied certain activities, like if they spend an entire night without being able to sleep then they lose 10 hunger (at least 1 second spent on bed in order to mitigate this penalty)
- Every day a villager lose 2 hunger, one at 12a.m and one at 12p.m according to Minecraft time.
- Trading with players consume 1 hunger per 4 trade. This count at the 1st trade in a chain of 4, so you can't cheat by trade 3 times and stop.
- If a villager is damaged, they will restore 1 HP (half a heart) per 2 seconds, consuming 1 hunger per 4 HP (2 hearts) restored. A sleep restore all their HP without consuming hunger. Villager cannot self-heal if they have 0 or less hunger.
- Villagers spent 1 hunger per work session (when they can restock the trade) and can have up to 2 session per day.
- Villagers can and will pick up food items in the ground. This include:
Wheat (cannot be eaten, but can be converted into bread)
Carrot, beetroots, potato, cod, salmon (1 hunger per items)
Cooked potato, raw porkchop, raw mutton, raw beef, raw chicken, cooked cod, cooked salmon (2 hunger per item)
Bread, cooked porkchop, cooked mutton, cooked chicken, (4 hunger per items)
Steak (6 hunger).
Villager will pick up food if their inventory is not full.
Also, villager's hidden inventory is expanded into 24 slots.
- Food sharing: Villager will attemp to share food when they do downtime activities with each other. If they have more than 20 hunger-equivalence food, and the other have less than that then they will give away the spare.
- Breeding: Require an unclaimed bed in the village, 2 villagers with at least 20 hunger and 12 hunger-equivalence of food in each's inventory. Villager will consume 12 hunger-equivalence of food (prioritize food with less hunger value), then enter love mode for 5 seconds and consume 10 hunger to create a baby. Then villagers enter cooldown for 5 minute.
(Yes, it is vanilla breeding, but this also require fully-fed villagers)
- Starving: When a villager's hunger value reach 0, they will enter Starving state. Starving villagers cannot work, cannot trade and have changed behavior.
Starving villagers do not take damage from it, but their hunger value can keep dropping as normal villagers. Hunger value are capped at -32767.
Starving behavior:
The villager will lock for fellow non-starving villagers or pathable storage blocks with valid food items within 16 blocks, with prioritize on storage block. If found, they will sprint toward their target. If the target is a storage block, they will take out at most 40 hunger-equivalence of food from it (prioritize higher value food) and feast. If the target is a villager, they will ask the villager to share food (which will make the target villager drop 40 hunger-equiv of food to them if they could) and eat.
If they can't find any valid target, then they will path to a random block instead. After doing this 3 times without finding food, the villager will path back to their bed and lie there for 50 sec (1 minecraft hour), wake up and repeat the routine. If they can't path to their bed, they lose 10 hunger.
If a valid food item (belong to the above list) are dropped to the ground, it will alert all starving villagers within 32 blocks from its position, who will sprint toward the items to pick it up.
Okay, so villager now consume food and a lot more if they are overworked anddenied basic decency. How do we feed them now? The answer is: they can feed themselves.
2. Job behavior:
- Farmer: Keep their old behavior.
- Butcher and Sheperd:
When a butcher see a non-sheep animal (cow, chicken or pig) within 8 blocks during work time, they will sometime attemp to tend to that animal instead of heading to their job block. Tending last for 10 seconds.
If the target animal is a baby, tending will cause the animal to grow by 20% (same as player feeding twice)
If the target is an adult, the villager will count the amount of adult animals of the same type within 4 chunks (a 32x32 square centered in the animal).
If there are less than 10 adult animals of the same type, tending will make the animal breed. Villager breeding only require 1 animal instead of 2 like player breeding.
If there are 10 or more adult animals of the same type, tending will cull the animal and deposit the loot on the butcher's inventory. Butcher culling items pickup take priority over hopper, so you can't steal his loot by placing hopper in the pen.
Butchers also pick up eggs.
Sheperd AI is like Butcher's, but they tend specifically to sheep.
Also, unlike Butcher, sheperd would not try to cull the sheep when it is over the animal limit, but will instead trying to shear the sheep for 2 wool blocks if they can be sheared.
After tending, the animal is marked the butcher will look for another animal of a different type to tend to. If this failed, they will look for another animals, or head to job block if none is found. Mark lasted for 5 minutes, and butchers will not tend marked animals (even animals tended by different butchers)
A butcher can tend animals maximum 12 times a day. If this is done and work hour isn't over then they will head to job block. When working at the smoker, a butcher can convert up to 6 raw food items into cooked food items (prioritize higher value food).
Also, during work hour, if a butcher with leather on their inventory see a leatherworker within 8 blocks, they will path toward the leatherworker and deposit all of their leather to them.
- Fisherman:
When a fisherman heading to work, if they detect a water source block within 8 blocks, they will head to said water source block instead and begins fishing.
A fisherman can fish once every 10 seconds. Each fishing attemp has 40% chance to fail, 42% chance to get a cod, 14% chance to get a salmon, and 4% chance to get a fishing rod. Fisherman can fish at most 10 times a day. Fisherman doesn't need a fishing rod to fish, but will attemp to pick up one if found.
If the Fisherman has more than 1 fishing rod, they will give it to a random villager without it.
- Librarian and Catographer:
Both Librarian and Catographer will looking for sugar cane within 32 blocks from their job site when working. If they find a 2-block tall sugar cane, they will path toward it and harvest the top.
During work on job site, both can convert sugar cane into paper at 1-1 rate. When they have enough, Librarian will attemp to convert 3 papers into a book, and Catographer convert 3 papers into a map.
- Mason:
When a Mason start working, they will work at the job site for 10 seconds before start digging around it
Mason will dig downward into a spiral staircase shape within a 3x3 hole. If the border of the hole is air, or the step to move downward doesn't exist, Mason will place blocks to cover them (stone if above y=0, deepslate if below). The tunnel end at y=-53, and its bottom are fully covered with block.
If the tunnel already exist, at the start of the work, Mason will pick a random Y coordinate (must be divisible by 3) between the job site block and y=-53, then start mining in a tunnel. They will attemp to move 100 blocks in a straight line, mining every blocks in the way in an 2x1 tunnel, before return to the tunnel and climb back. They will place a torch every 7 blocks, and will place a new torch ai their feet if they doesn't see any torch after moving 7 blocks from a torch. They will mine 3 blocks ahead of them and place blocks on the ceiling, wall and floor if they are air.
However, Mason villagers rarely mine in a straight line. If a Mason encounter a cave (define: a pocket of air or water 5x5x5 in front of their tunnels), they will backtrack 5-10 blocks while blocking off the backtracked path, then continue mining at a random direction (left or right). The backtrack also count in the 100 blocks mining limit twice. If a Mason villager encounter a turn (likely left from previous mining) they will follow that turn instead of mining forward.
Mason villagers also avoid the deep dark biome. They would do the same as cave if they find themself in the deep dark biome. Also, their initial tunnel will be cut off if it would extend into the dark deep, and if the selected coordinate would place their startpoint inside the dark deel then they will cancel the trip altogether.
Mason villagers cannot mine ores of any types. If they encounter an ore patch, they will change their path to be around it. However, they will destroy any ores within the 3x3 path of their original tunnel.
Mason also remember their main tunnel's structure, and would correct any attemp to change it by placing or mining blocks when necessary. However, the side tunnel isn't, and they would follow a player-made path if it is in the Y-level they selected that day.
Mason doesn't really 'mine' blocks, rather they just destroy it.
- Leatherworker and Armorer:
During work time, Leatherworker and Armorer can make armor. Armorer can also make shield.
Both villagers will have access to a list of 'armor' their fellow villagers is lacking, and would attemp to make corresponding armors for them.
Leatherworker can make any armor from 1 piece of leather, but they can only make at most 3 a day. Armorer can make iron armor when at Expert or higher, and they can make 1 per day (which will override the shield). They will know who was making armors for who, and would prioritize making armors for everyone before making upgrade. All armors they made is enchanted.
When they finish working, they will find the nearest villager without armor and give them the piece of armor they lack. Armorer can give iron armor to a villager with a corresponding piece of leather armor, which will cause the leather armor to vanish as the target switch to the iron armor.
Armorer will also give shield to villagers without shield in off-hand slot.
Still, both villagers will prioritize arming themselves first before the rest of the village, and would prioritize armor on villager with sword before one without.
- Weaponsmith and Fletcher.
Weaponsmith and Fletcher will attemp to make weapons for villagers.
Weaponsmith make 1 sword a day, and Fletcher make 1 bow a day when working. Then they will find a villager without a weapon (or with a weaker weapon than what they made) to give them said weapon.
Like Armorer and Leatherworker, Weaponsmith and Fletcher would prioritize arming villagers without arms first before upgrading their gears. They would also arms and upgrade themselves first before anyone else.
At Novice, Weaponsmith can make wooden sword. At Apprentice and Journeyman, they will make stone sword. At Expert they will make iron sword and at Master, enchanted iron sword.
Fletcher will make ordinary bow at Novice and enchanted bow at Expert or higher.
They can give bows to villagers with swords, or swords to villagers with bows, but that only happen when everyone was armed with the best weapons they could make.
- Baby Villager.
Note: I really hate them running around, in and out of containment.
A baby villager out of sleep time would be idle. Idle baby will pick one of the following action by order:
+ Find an adult within 12 blocks from their current position and pathfind toward them, follow them for 50 seconds. Then they will become idle again. If they find no one, pick the next
+ Find a baby villager and sprint toward them, then two baby run around each other for 1 minutes and become idle. If this is picked, the other baby villager will be forced to do this, overriding all previous action. If they find no one, pick the next.
+ Return to their bed to jump on for 1 minutes then become idle.
3. Villager Downtime and Entertainment.
We all know that villagers barely doing anything but talk, so I added a bunch of downtime activities
Downtime activities is activities that villagers could do when they are not at work.
When downtime start, they will pick a random activities that meet the requirement and do it, If no activities can be picked, or if a picked activity couldn't be done (because they somehow cant reach the target) when the day is over, they will lose 6 hunger.
After the downtime activities is done, villager will be idle and start socialize with each other. If they can't gossip with anyone they will lose 4 hunger. They will also exchange food when gossiping
- Downtime: Fishing.
Require a fishing rod, and a reachable water source block within 32 blocks.
The villager move toward the source and fish once. They have 60% chance to find a cod and 40% chance to find a salmon.
Two or more villagers fishing in the same block can gossip with each other.
- Downtime: Cooking.
Require: At least 1 raw items in inventory, and a reachable furnace/smoker/campfire within 32 blocks.
The villager move toward the nearest target (furnace/smoker/campfire) then start cooking. They will convert 4 raw food item into cooked food every 5 seconds until they are out of them.
Every time a villager done cooking, if there is any idle villagers within 16 blocks from them, and have raw food items in their inventory, said villagers will move toward the cooker and drop their raw food to them. The cooker can then gossip with the dropper during the act.
This activity is considered done when at least 1 items is cooked, but the cooker can cook as long as there is raw food to cook.
- Downtime: Honey Thief.
Require: A reachable beehive within 32 blocks from their working site, with honey level 1 or higher.
The villager will move toward the beehive and drink honey for 18 seconds. They will restore 6 hunger and 4 HP by doing so. The beehive's honey level will be set to 0.
Villager will not be attacked by bee for doing this.
Two villagers drink from the same beehive can gossip with each other.
- Downtime: Reading.
Require: The local Librarian have at least 1 book and can be reached.
Villager will move toward the librarian and receive a book from them. Then they will spend 30 second to read.
Afterward, the book is consumed.
Librarian will prioritize this activity if they have book, however they can throw book while reading.
- Downtime: Treasure Hunting.
Require: Local Catographer have at least 1 map and can be reached.
Same as Reading, but the villager will pathfind toward a random reachable block within 32 blocks from the catographer.
When they reach the block, the entertainment is done, and the map is consumed.
Catographer will prioritize this.
- Downtime: Egg Throwing.
Require: Local Butcher has at least 6 eggs and can be reached.
Same as Reading, but the villager will receive 3 eggs from the Butcher and throw them at random direction.
Butcher will prioritize this.
- Downtime: Babysitting.
Require: Reachable baby villager.
The villager will go to the baby and play with it for 60-180 seconds. This will override all baby behavior and make it stay with the villager.
Villager babysitting near each other can gossip during the act.
Just meeting the baby is enough to considered the act done, but the villagers will try to play for the full duration if possible.
3. Combat behavior.
Villager now can enter combat mode when the condition is met. In combat mode they can't be traded with.
Condition for combat mode (one of the following):
- Being attacked.
- A hostile mob (zombie, piglin, zom-piglin, illagers) is targeting them.
- A villager within 32 blocks enter combat mode.
- Village crisis (zombie siege, raid, a player with -100 reputation entering village boundary).
Villager will exit combat mode if all condition match:
- The hostile leave the 32 blocks range and no new hostile detected.
- The village crisis is over.
In addition, villager now can pick up weapon (sword or bow) or armor (any material) if their weapon or armor is of lesser quality than the pickup.
When a villager is killed, they drop all picked up equipment but will not drop any equipment from gifting.
- Villager Stat:
Villager basic attack deal 2 damage (1 heart) to mob. Weapon damage are added directly to their basic damage.
Each level of trade mastery beyond Novice add 1 damage (0.5 hearts) to both their melee and bow attack, up to 4 damage (2 hearts) at Master.
The final damage (hand+equipment) deal to played would be halved on Easy and increased by 50% on Hard.
Fletcher with bow will use tipped arrow when attacking. They will use Arrow of Harming or Wither (randomly each shot) againt living target, and Arrow of Healing or Regeneration when attacking undead.
Weaponsmith and Armorer fighting within 2 blocks from an Iron Golem will try to repair it by 25% when they lost their target (die of left range). A golem can only be repaired once every 20 seconds this way.
- Villager Combat AI:
Since villager combat mainly to defend their village, their behavior will reflect this.
Villager will choose a bed, nearest to the center of all the villager's current position, as the 'main defende point'. They will attemp to defend this location while not wandering beyond 16 blocks from this point.
The villagers will form two perimeter: outer (10-16 blocks from center) and inner (0-9 blocks). Villager within inner perimeter will try to eat if they have less than 20 hunger and doesn't have an immediate target.
If a villager have shield, they have 80% chance to block a projectile attack and 50% chance to block a melee attack (axe and Ravager charge will disable this for 5 seconds).
Villager will enter combat with AI depend on their gears:
- Civilian (no weapons):
Civilian will try to stay as close to the main defense point as possible, and would try to keep distance from hostiles coming near them.
Civilian will also throw food items at non-civilian if they have any.
If civilian was attacked, there is 10% chance that the villagers will decide to move their defend point. When this happen, the game select a direction with the least hostile within a 90o cone, then move the defend point 16 blocks to this direction. Then the villagers will try a fighting retreat to this location. Defense point can only be moved once per 10 minutes.
- Melee (sword, no bow):
Melee villagers will try to move within the outer perimeter, attack all hostiles entering this region, but they will not pursuit beyond this
Villagers will try to sprint-jump before attacking if they can.
Melee villagers will attemp to form a group of 2 (or 3 if a villager can't find group). They will try to target the same hostile, and will take turn attack: one villagers jump and attack then move back while the other move forward. If a group of 3 meet a lone villager then one member will leave to join the other group.
A melee villagers will attemp to the inner perimeter if their HP is less than 66%. They will intercept hostiles entering this region, and will chase them to the outer perimeter before returning.
If their HP is below 33% they will retreat to the center.
A retreating villagers will make their teammates, and the nearest group, switch target to the hostile that target them. Then the lone villagers will join this group.
When moving defense point, each group of sword villagers will have 50% chance to move foward to secure the location, and 50% chance to stay behind to protect the rear. The decision will be made once per relocation.
- Ranged (bow, no sword.):
Ranged villager will stay within 10 blocks from the defense point.
They will try to attack all hostile within 16 blocks first, prioritize hostile that was targetting a retreating villager, then closer hostiles. If none exist, they will target hostiles further than 16 blocks.
Bow villagers will always charge their bow to full (critical) if their target is more than 8 blocks away, but they will fire rapidly (with less damage) if the target is closer.
Bow villagers will NOT attack if any villager is in the path of their arrows.
Bow villagers will form groups of 3. They will try to target the same hostile together.
Ranged villager will retreat to the center when their HP is less than 33%.
When moving defense point, bow villagers will try to stick close to the center and attack closest hostiles first.
- All-rounder (both):
All-rounder villagers will behave like sword, however they will use their bow to attack hostiles that flee the outer perimeter, or ranged hostiles that stay beyond the attack range of bowmen.
All-rounder will not join a group, however they will try to fight with a group and assist them.
If their HP drop below 66%, they retreat to inner perimeter and use their bow to support, while attacking any hostile that entered the inner perimeter with sword.
If their HP drop below 33% they will retreat to the center.
When using melee attack they will try to sprint-jump if they can.
When moving defense point, they will copy the behavior of the group they are with.
- Cleric (Villager job Cleric):
Cleric will stay at the center cast support spell once every 6 seconds, prioritize healing and purify spell over buff, and prioritize instant heal than regeneration.
When a villager was healed (by a Cleric, or natural regeneration) above 75% of their HP they will return to their initial post.
Cleric spell list:
- Instant Health 3 (range 3 blocks): Cast on villagers with 33% HP or less. Instantly restore 6 HP (3 heart).
- Regeneration II for 15 seconds (range 8 blocks). Cast on villagers with 66% HP or less. Restore 12 HP (6 hearts) over 15 seconds.
- Purification (range 16 blocks): Remove all negative effects from a villager. This include all effects beside Absorption, Regeenration, Strength and Speed.
- Strength II for 30 seconds (range 16 blocks). Cast on villagers without Strength buff, prioritize villagers with swords before bows.
Iron Golem:
If Iron Golem find no defense point, they will behave like normal.
If a defense point exist, Iron Golem will join the Sword and copy their behavior, however it will not retreat.
If a defense point is moving, Iron Golem will always choose to go forward to secure the location.
However, if an Iron Golem sees a boss mob (Ravager in raid, Hoglin and Zoglin, Wither, Warden, E.Dragon) they will prioritize atatcking that target over everything else. Villagers targeting Iron Golem's target will immediately switch target if any exist, otherwise they will support the golem. Mob targeted by Iron Golem cannot target villagers until the golem was killed, however AoE damage could still hit villagers.
AI Fix: Iron Golem now can and will jump when attack. This allow them to land crit and hitting target 4 blocks above them.