villager

{
  "format_version": "1.18.10",
  "minecraft:entity": {
    "description": {
      "identifier": "minecraft:villager",
      "is_spawnable": true,
      "is_summonable": true,
      "is_experimental": false
    },
  
    "component_groups": {
      "minecraft:celebrate": {
        "minecraft:behavior.celebrate_survive": {
          "priority": 5,
          "fireworks_interval": {
            "range_min": 2.0,
            "range_max": 7.0
          },
          "duration": 30.0,
          "on_celebration_end_event": {
            "event": "minecraft:stop_celebrating",
            "target": "self"
          }
        },
        "minecraft:behavior.move_outdoors": {
          "priority": 2,
          "speed_multiplier": 0.8,
          "timeout_cooldown": 8.0
        }
      },

      "become_witch": {
        "minecraft:transformation": {
          "into": "minecraft:witch",
          "delay": 0.5
        }
      },
      
      "become_villager_v2": {
        "minecraft:transformation": {
          "into": "minecraft:villager_v2",
          "keep_level": true
        }
      },

      "become_zombie": {
        "minecraft:transformation": {
          "into": "minecraft:zombie_villager"
        }
      },

      "behavior_peasant": {
        "minecraft:shareables": {
          "items": [
            {
              "item": "minecraft:bread",
              "want_amount": 3,
              "surplus_amount": 6,
              "stored_in_inventory": true
            },
            {
              "item": "minecraft:carrot",
              "want_amount": 60,
              "surplus_amount": 4,
              "stored_in_inventory": true
            },
            {
              "item": "minecraft:potato",
              "want_amount": 60,
              "surplus_amount": 24,
              "stored_in_inventory": true
            },
            {
              "item": "minecraft:beetroot",
              "want_amount": 60,
              "surplus_amount": 24,
              "stored_in_inventory": true
            },
            {
              "item": "minecraft:wheat_seeds",
              "want_amount": 64,
              "surplus_amount": 64,
              "stored_in_inventory": true,
              "pickup_only": true
            },
            {
              "item": "minecraft:beetroot_seeds",
              "want_amount": 64,
              "surplus_amount": 64,
              "stored_in_inventory": true,
              "pickup_only": true
            },
            {
              "item": "minecraft:wheat",
              "want_amount": 45,
              "surplus_amount": 18,
              "craft_into": "minecraft:bread",
              "stored_in_inventory": true
            }
          ]
        },
        "minecraft:behavior.harvest_farm_block": {
          "priority": 9,
          "speed_multiplier": 0.5
        }
      },

      "behavior_non_peasant": {
        "minecraft:shareables": {
          "items": [
            {
              "item": "minecraft:bread",
              "want_amount": 3,
              "surplus_amount": 6,
              "stored_in_inventory": true
            },
            {
              "item": "minecraft:carrot",
              "want_amount": 12,
              "surplus_amount": 24,
              "stored_in_inventory": true
            },
            {
              "item": "minecraft:potato",
              "want_amount": 12,
              "surplus_amount": 24,
              "stored_in_inventory": true
            },
            {
              "item": "minecraft:beetroot",
              "want_amount": 12,
              "surplus_amount": 24,
              "stored_in_inventory": true
            }
          ]
        }
      },

      "farmer":{
        "minecraft:type_family": {
          "family":[ "villager", "peasant", "farmer", "mob" ]          
        },
        "minecraft:variant": {
          "value": 0
        },

        "minecraft:trade_table": {
          "display_name": "entity.villager.farmer",
          "table": "trading/farmer_trades.json",
          "convert_trades_economy": true
        }
      },

      "fisherman":{
        "minecraft:type_family": {
          "family":[ "villager", "peasant", "fisherman", "mob" ]          
        },
        "minecraft:variant": {
          "value": 0
        },

        "minecraft:trade_table": {
          "display_name": "entity.villager.fisherman",
          "table": "trading/fisherman_trades.json",
          "convert_trades_economy": true
        }
      },

      "shepherd":{
        "minecraft:type_family": {
          "family":[ "villager", "peasant", "shepherd", "mob" ]          
        },
        "minecraft:variant": {
          "value": 0
        },

        "minecraft:trade_table": {
          "display_name": "entity.villager.shepherd",
          "table": "trading/shepherd_trades.json",
          "convert_trades_economy": true
        }
      },

      "fletcher":{
        "minecraft:type_family": {
          "family":[ "villager", "peasant", "fletcher", "mob" ]          
        },
        "minecraft:variant": {
          "value": 0
        },

        "minecraft:trade_table": {
          "display_name": "entity.villager.fletcher",
          "table": "trading/fletcher_trades.json",
          "convert_trades_economy": true
        }
      },

      "librarian":{
        "minecraft:type_family": {
          "family":[ "villager", "librarian", "mob" ]          
        },
        "minecraft:variant": {
          "value": 1
        },

        "minecraft:trade_table": {
          "display_name": "entity.villager.librarian",
          "table": "trading/librarian_trades.json",
          "convert_trades_economy": true
        }
      },

      "cartographer":{
        "minecraft:type_family": {
          "family":[ "villager", "cartographer", "mob" ]          
        },
        "minecraft:variant": {
          "value": 1
        },

        "minecraft:trade_table": {
          "display_name": "entity.villager.cartographer",
          "table": "trading/cartographer_trades.json",
          "convert_trades_economy": true
        }
      },

      "cleric":{
        "minecraft:type_family": {
          "family":[ "villager", "priest", "cleric", "mob" ]          
        },
        "minecraft:variant": {
          "value": 2
        },

        "minecraft:trade_table": {
          "display_name": "entity.villager.cleric",
          "table": "trading/cleric_trades.json",
          "convert_trades_economy": true
        }
      },

      "armorer":{
        "minecraft:type_family": {
          "family":[ "villager", "blacksmith", "armorer", "mob" ]          
        },
        "minecraft:variant": {
          "value": 3
        },

        "minecraft:trade_table": {
          "display_name": "entity.villager.armor",
          "table": "trading/armorer_trades.json",
          "convert_trades_economy": true
        }
      },

      "weaponsmith":{
        "minecraft:type_family": {
          "family":[ "villager", "blacksmith", "weaponsmith", "mob" ]          
        },
        "minecraft:variant": {
          "value": 3
        },

        "minecraft:trade_table": {
          "display_name": "entity.villager.weapon",
          "table": "trading/weapon_smith_trades.json",
          "convert_trades_economy": true
        }
      },

      "toolsmith":{
        "minecraft:type_family": {
          "family":[ "villager", "blacksmith", "toolsmith", "mob" ]          
        },
        "minecraft:variant": {
          "value": 3
        },

        "minecraft:trade_table": {
          "display_name": "entity.villager.tool",
          "table": "trading/tool_smith_trades.json",
          "convert_trades_economy": true
        }
      },

      "butcher":{
        "minecraft:type_family": {
          "family":[ "villager", "artisan", "butcher", "mob" ]          
        },
        "minecraft:variant": {
          "value": 4
        },

        "minecraft:trade_table": {
          "display_name": "entity.villager.butcher",
          "table": "trading/butcher_trades.json",
          "convert_trades_economy": true
        }
      },

      "leatherworker":{
        "minecraft:type_family": {
          "family":[ "villager", "artisan", "leatherworker", "mob" ]          
        },
        "minecraft:variant": {
          "value": 4
        },

        "minecraft:trade_table": {
          "display_name": "entity.villager.leather",
          "table": "trading/leather_worker_trades.json",
          "convert_trades_economy": true
        }
      },

      "baby": {
        "minecraft:is_baby": {  },
        "minecraft:scale": {
          "value":0.5
        },
        "minecraft:ageable": {
          "duration": 1200,
          "grow_up": {
            "event": "minecraft:ageable_grow_up",
            "target": "self"
          }
        },
        "minecraft:behavior.take_flower":{
          "priority": 7
        },
        "minecraft:behavior.play": {
          "priority": 8,
          "speed_multiplier": 0.32
        }
      },

      "adult": {
        "minecraft:behavior.make_love": {
          "priority": 6
        },
        "minecraft:behavior.receive_love":{
          "priority": 7
        }
      }
    },

    "components": {
      "minecraft:is_hidden_when_invisible": {
      },
      "minecraft:type_family": {
        "family": ["villager", "mob"]
      },

      "minecraft:breathable": {
        "total_supply": 15,
        "suffocate_time": 0
      },
      "minecraft:health": {
        "value": 20,
        "max": 20
      },
      "minecraft:hurt_on_condition": {
        "damage_conditions": [
          {
            "filters": { "test": "in_lava", "subject": "self", "operator": "==", "value": true },
            "cause": "lava",
            "damage_per_tick": 4
          }
        ]
      },
      "minecraft:collision_box": {
        "width": 0.6,
        "height": 1.9
      },
      "minecraft:nameable": {
      },
      "minecraft:movement": {
        "value": 0.5
      },
      "minecraft:navigation.walk": {
        "is_amphibious": true,
        "can_path_over_water": true,
        "can_pass_doors": true,
        "can_open_doors": true,
        "can_walk": true,
        "avoid_water": true
      },
      "minecraft:annotation.open_door": {

      },
      "minecraft:movement.basic": {
      },
      "minecraft:jump.static": {
      },
      "minecraft:can_climb": {
      },
      "minecraft:inventory": {
        "inventory_size": 8,
        "private": true
      },
      "minecraft:damage_sensor": {
        "triggers": [
          {
            "on_damage": {
              "filters": { "test" :  "is_family", "subject" : "other", "value" :  "lightning" },
              "event": "become_witch"
            },
            "deals_damage": false
          },
          {
            "on_damage": {
              "filters": {
                "any_of": [
                  {"test": "is_family", "subject": "other", "value": "zombie"},
                  {"test": "is_family", "subject": "other", "value": "husk"}
                ],
                "all_of": [
                  {"test": "has_damage", "value": "fatal"}
                ]
              },
              "event": "become_zombie"
            }
          }
        ]
      },
      "minecraft:persistent": {
      },
      "minecraft:behavior.float": {
        "priority": 0
      },
      "minecraft:behavior.trade_with_player": {
        "priority": 1
      },
      "minecraft:behavior.look_at_trading_player": {
        "priority": 2
      },
      "minecraft:behavior.panic": {
        "priority": 3,
        "speed_multiplier": 0.6
      },
      "minecraft:behavior.avoid_mob_type": {
        "priority": 3,
        "entity_types": [
          {
            "filters": { 
                "any_of": [
                  { "test" : "is_family", "subject" : "other", "value" : "zombie"},
                  { "test" : "is_family", "subject" : "other", "value" : "zombie_villager"},
                  { "test" : "is_family", "subject" : "other", "value" : "illager"},
                  { "test" : "is_family", "subject" : "other", "value" : "vex"}
                ]
            },
            "max_dist": 8,
            "walk_speed_multiplier": 0.6,
            "sprint_speed_multiplier": 0.6
          }
        ]
      },
      "minecraft:behavior.move_indoors": {
        "priority": 4,
        "speed_multiplier": 0.8
      },
      "minecraft:behavior.restrict_open_door": {
        "priority": 5
      },
      "minecraft:behavior.open_door": {
        "priority": 6,
        "close_door_after": true
      },
      "minecraft:behavior.share_items": {
        "priority": 8,
        "max_dist": 3,
        "goal_radius":  2.0,
        "speed_multiplier": 0.5,
        "entity_types": [
          {
            "filters": { "test" :  "is_family", "subject" : "other", "value" :  "villager"}
          }
        ]
      },
      "minecraft:behavior.pickup_items": {
        "priority": 9,
        "max_dist": 3,
        "goal_radius": 2,
        "speed_multiplier": 0.5,
        "can_pickup_to_hand_or_equipment": false
      },
      "minecraft:behavior.random_stroll": {
        "priority": 11,
        "speed_multiplier": 0.6
      },
      "minecraft:behavior.look_at_player": {
        "priority": 12,
        "look_distance": 8,
        "probability": 0.02
      },
        "minecraft:physics": {
      },
      "minecraft:pushable": {
        "is_pushable": true,
        "is_pushable_by_piston": true
      },
      "minecraft:conditional_bandwidth_optimization": {
      }
    },
    "events":{
      "become_witch": {
        "add": {
          "component_groups": [
            "become_witch"
          ]
        }
      },
      "become_zombie": {
        "sequence": [
          {
            "filters": {"test": "is_difficulty", "value": "normal"},
            "randomize": [
              {
                "weight": 50,
                "add": { "component_groups": [ "become_zombie" ] }
              },
              {
                "weight": 50
              }
            ]
          },
          {
            "filters": {"test": "is_difficulty", "value": "hard"},
            "add": {
              "component_groups": [
                "become_zombie"
              ]
            }
          }
        ]
      },
      "minecraft:entity_spawned": {
        "sequence": [
          {
            "filters": { "test": "has_component", "operator": "!=", "value": "minecraft:variant" },
            "randomize": [
              {
                "weight": 5,
                "add": { "component_groups": [ "baby" ] }
              },
              {
                "weight": 95,
                "add": { "component_groups": [ "adult" ] }
              }
            ]
          },
          {
            "filters": { "test": "has_component", "operator": "!=", "value": "minecraft:variant" },
            "randomize": [
              {
                "weight": 5,
                "add": { "component_groups": [ "farmer", "behavior_peasant" ] }
              },
              {
                "weight": 5,
                "add": { "component_groups": [ "fisherman", "behavior_peasant" ] }
              },
              {
                "weight": 5,
                "add": { "component_groups": [ "shepherd", "behavior_peasant" ] }
              },
              {
                "weight": 5,
                "add": { "component_groups": [ "fletcher", "behavior_peasant" ] }
              },
              {
                "weight": 20,
                "add": { "component_groups": [ "librarian", "behavior_non_peasant" ] }
              },
              {
                "weight": 20,
                "add": { "component_groups": [ "cartographer", "behavior_non_peasant" ] }
              },
              {
                "weight": 20,
                "add": { "component_groups": [ "cleric", "behavior_non_peasant" ] }
              },
              {
                "weight": 6,
                "add": { "component_groups": [ "armorer", "behavior_non_peasant" ] }
              },
              {
                "weight": 6,
                "add": { "component_groups": [ "weaponsmith", "behavior_non_peasant" ] }
              },
              {
                "weight": 6,
                "add": { "component_groups": [ "toolsmith", "behavior_non_peasant" ] }
              },
              {
                "weight": 10,
                "add": { "component_groups": [ "butcher", "behavior_non_peasant" ] }
              },
              {
                "weight": 10,
                "add": { "component_groups": [ "leatherworker", "behavior_non_peasant" ] }
              }
            ]
          }
        ]
        
      },

      "minecraft:entity_transformed": {
        "sequence": [
          // Transform baby zombie to baby villager
          {
            "filters": { "test": "has_component", "subject": "other", "value": "minecraft:is_baby" },
            "add": { "component_groups": [ "baby" ] }
          },
          // Transform adult zombie to adult villager
          {
            "filters": { "test": "has_component", "subject": "other", "operator": "!=", "value": "minecraft:is_baby" },
            "add": { "component_groups": [ "adult" ] }
          },

          // Transform farmer zombie to farmer villager
          {
            "filters": { "test": "is_family", "subject": "other", "value": "farmer"},
            "add": { "component_groups": [ "farmer", "behavior_peasant" ] }
          },
          // Transform fisherman zombie to fisherman villager
          {
            "filters": { "test": "is_family", "subject": "other", "value": "fisherman"},
            "add": { "component_groups": [ "fisherman", "behavior_peasant" ] }
          },
          // Transform shepherd zombie to shepherd villager
          {
            "filters": { "test": "is_family", "subject": "other", "value": "shepherd" },
            "add": { "component_groups": [ "shepherd", "behavior_peasant" ] }
          },
          // Transform fletcher zombie to fletcher villager
          {
            "filters": { "test": "is_family", "subject": "other", "value": "fletcher" },
            "add": { "component_groups": [ "fletcher", "behavior_peasant" ] }
          },
          // Transform librarian zombie to librarian villager
          {
            "filters": { "test": "is_family", "subject": "other", "value": "librarian" },
            "add": { "component_groups": [ "librarian", "behavior_non_peasant" ] }
          },
          // Transform cartographer zombie to cartographer villager
          {
            "filters": { "test": "is_family", "subject": "other", "value": "cartographer" },
            "add": { "component_groups": [ "cartographer", "behavior_non_peasant" ] }
          },
          // Transform cleric zombie to cleric villager
          {
            "filters": { "test": "is_family", "subject": "other", "value": "cleric" },
            "add": { "component_groups": [ "cleric", "behavior_non_peasant" ] }
          },
          // Transform armorer zombie to armorer villager
          {
            "filters": { "test": "is_family", "subject": "other", "value": "armorer" },
            "add": { "component_groups": [ "armorer", "behavior_non_peasant" ] }
          },
          // Transform weaponsmith zombie to weaponsmith villager
          {
            "filters": { "test": "is_family", "subject": "other", "value": "weaponsmith" },
            "add": { "component_groups": [ "weaponsmith", "behavior_non_peasant" ] }
          },
          // Transform toolsmith zombie to toolsmith villager
          {
            "filters": { "test": "is_family", "subject": "other", "value": "toolsmith" },
            "add": { "component_groups": [ "toolsmith", "behavior_non_peasant" ] }
          },
          // Transform butcher zombie to butcher villager
          {
            "filters": { "test": "is_family", "subject": "other", "value": "butcher" },
            "add": { "component_groups": [ "butcher", "behavior_non_peasant" ] }
          },
          // Transform leatherworker zombie to leatherworker villager
          {
            "filters": { "test": "is_family", "subject": "other", "value": "leatherworker" },
            "add": { "component_groups": [ "leatherworker", "behavior_non_peasant" ] }
          }
        ]
      },

      "minecraft:entity_born": {
        "sequence": [
          {
            "add": { "component_groups": [ "baby" ] }
          },
          {
            "randomize": [
              {
                "weight": 5,
                "add": { "component_groups": [ "farmer", "behavior_peasant" ] }
              },
              {
                "weight": 5,
                "add": { "component_groups": [ "fisherman", "behavior_peasant" ] }
              },
              {
                "weight": 5,
                "add": { "component_groups": [ "shepherd", "behavior_peasant" ] }
              },
              {
                "weight": 5,
                "add": { "component_groups": [ "fletcher", "behavior_peasant" ] }
              },
              {
                "weight": 20,
                "add": { "component_groups": [ "librarian", "behavior_non_peasant" ] }
              },
              {
                "weight": 20,
                "add": { "component_groups": [ "cartographer", "behavior_non_peasant" ] }
              },
              {
                "weight": 20,
                "add": { "component_groups": [ "cleric", "behavior_non_peasant" ] }
              },
              {
                "weight": 6,
                "add": { "component_groups": [ "armorer", "behavior_non_peasant" ] }
              },
              {
                "weight": 6,
                "add": { "component_groups": [ "weaponsmith", "behavior_non_peasant" ] }
              },
              {
                "weight": 6,
                "add": { "component_groups": [ "toolsmith", "behavior_non_peasant" ] }
              },
              {
                "weight": 10,
                "add": { "component_groups": [ "butcher", "behavior_non_peasant" ] }
              },
              {
                "weight": 10,
                "add": { "component_groups": [ "leatherworker", "behavior_non_peasant" ] }
              }
            ]
          }
        ]
      },

      "minecraft:spawn_farmer": {
        "randomize": [
          {
            "weight": 5,
            "add": { "component_groups": [ "farmer", "adult", "behavior_peasant" ] },
            "remove": { "component_groups": [ "baby" ] }
          },
          {
            "weight": 5,
            "add": { "component_groups": [ "fisherman", "adult", "behavior_peasant" ] },
            "remove": { "component_groups": [ "baby" ] }
          },
          {
            "weight": 5,
            "add": { "component_groups": [ "shepherd", "adult", "behavior_peasant" ] },
            "remove": { "component_groups": [ "baby" ] }
          },
          {
            "weight": 5,
            "add": { "component_groups": [ "fletcher", "adult", "behavior_peasant" ] },
            "remove": { "component_groups": [ "baby" ] }
          }
        ]
      },

      "minecraft:spawn_librarian": {
        "randomize": [
          {
            "weight": 20,
            "add": { "component_groups": [ "librarian", "adult", "behavior_non_peasant" ] },
            "remove": { "component_groups": [ "baby" ] }
          },
          {
            "weight": 20,
            "add": { "component_groups": [ "cartographer", "behavior_non_peasant" ] },
            "remove": { "component_groups": [ "baby" ] }
          }
        ]
      },

      "minecraft:spawn_cleric": {
        "add": { "component_groups": [ "cleric", "adult", "behavior_non_peasant" ] },
        "remove": { "component_groups": [ "baby" ] }
      },

      "minecraft:spawn_armorer": {
        "randomize": [
          {
            "weight": 6,
            "add": { "component_groups": [ "armorer", "adult", "behavior_non_peasant" ] },
            "remove": { "component_groups": [ "baby" ] }
          },
          {
            "weight": 6,
            "add": { "component_groups": [ "weaponsmith", "adult", "behavior_non_peasant" ] },
            "remove": { "component_groups": [ "baby" ] }
          },
          {
            "weight": 6,
            "add": { "component_groups": [ "toolsmith", "adult", "behavior_non_peasant" ] },
            "remove": { "component_groups": [ "baby" ] }
          }
        ]
      },

      "minecraft:spawn_butcher": {
        "randomize": [
          {
            "weight": 10,
            "add": { "component_groups": [ "butcher", "adult", "behavior_non_peasant" ] },
            "remove": { "component_groups": [ "baby" ] }
          },
          {
            "weight": 10,
            "add": { "component_groups": [ "leatherworker", "adult", "behavior_non_peasant" ] },
            "remove": { "component_groups": [ "baby" ] }
          }
        ]
      },

      "minecraft:ageable_grow_up": {
        "sequence": [
          {
            "remove": { "component_groups": [ "baby" ] },
            "add": { "component_groups": [ "adult" ] }
          }
        ]
      },

      "minecraft:become_cleric": {
        "add": { "component_groups": [ "cleric", "adult", "behavior_non_peasant" ] },
        "remove": { "component_groups": [ "baby" ] }
      },
      
      "minecraft:start_celebrating": { // Event must be called exactly this for village to fire it when a raid is won
        "add": { "component_groups": [ "minecraft:celebrate"] }
      },
      
      "minecraft:stop_celebrating": {
        "remove": { "component_groups": [ "minecraft:celebrate" ] }
      }
    }
  }
}