{
	"format_version": "1.19.0",
	"minecraft:entity": {
		"description": {
			"identifier": "ldz:ender_troll",
			"is_spawnable": true,
			"is_summonable": true,
			"is_experimental": false,
			"properties": {
				"ldz:in_player_proximity": {
					"type": "bool",
					"default": false,
					"client_sync": true
				},
				"ldz:is_roaring": {
					"type": "bool",
					"default": false,
					"client_sync": true
				},
				"ldz:ice_overlay": {
					"type": "bool",
					"client_sync": true,
					"default": false
				}
			},
			"animations": {
				"summon_end_force_power_5": "animation.generic.summon_end_force_power_5",
				"ice_timer": "animation.vanilla.ice_timer",
				"ice_damage": "animation.vanilla.ice_damage",
				"roar": "animation.ender_troll.roar",
				
				"ctrl.state":"controller.animation.ender_troll.state",
				"ctrl.ice_timer": "controller.animation.vanilla.ice_timer"
			},
			"scripts": {
				"animate": [
					"ctrl.state",
					"ctrl.ice_timer",
					{ "summon_end_force_power_5": "!q.is_alive" }
				]
			}
		},
		"component_groups": {
			"ice_overlay": {
				"minecraft:is_shaking": {}
			},
			"instant_despawn": {
				"minecraft:instant_despawn": {}
			},
			"not_roaring": {
				"minecraft:movement": {
					"value": 0.2
				}
			},
			"roaring": {
				"minecraft:movement": {
					"value": 0
				},
				"minecraft:spawn_entity": {
					"entities": {
						"spawn_entity": "ldz:troll_knockback",
						"single_use": true,
						"max_wait_time": 0,
						"min_wait_time": 0,
						"num_to_spawn": 1,
						"spawn_event": "add_troll_spawned"
					}
				},
				"minecraft:timer": {
					"time": 3,
					"looping": false,
					"time_down_event": {
						"event": "remove_roar",
						"target": "self"
					}
				}
			}
		},
		"components": {
			"minecraft:despawn": {
				"despawn_from_distance": {}
			},
			//ATTRIBUTES
			"minecraft:type_family": {
				"family": [
					"ldz",
					"ender",
					"ender_troll",
					"monster",
					"mob"
				]
			},
			"minecraft:loot": {
				"table": "loot_tables/entities/ender_troll.json"
			},
			"minecraft:health": {
				"max": 40,
				"value": 40
			},
			//COMBAT
			"minecraft:behavior.nearest_attackable_target": {
				"priority": 1,
				"must_reach": false,
				"must_see": true,
				"within_radius": 64,
				"reselect_targets": true,
				"entity_types": [
					{
						"filters": {
							"all_of": [
								{
									"test": "is_family",
									"subject": "other",
									"value": "player"
								}
							]
						}
					}
				]
			},
			"minecraft:behavior.delayed_attack": {
				"priority": 0,
				"attack_duration": 1,
				"attack_once": false,
				"hit_delay_pct": 1,
				"random_stop_interval": 0,
				"reach_multiplier": 4,
				"require_complete_path": false,
				"track_target": false,
				"melee_fov": 120,
				"cooldown_time": 4
			},
			"minecraft:behavior.hurt_by_target": {
				"priority": 1
			},
			"minecraft:attack": {
				"damage": 0
			},
			//SENSORS
			"minecraft:environment_sensor": {
				"triggers": [
					{
						"filters": [
							{
								"all_of": [
									{ "test": "actor_health", "operator": ">", "value": 0 },
									{ "test": "bool_property", "domain": "ldz:in_player_proximity", "value": false },
									{ "test": "distance_to_nearest_player", "operator": "<=", "value": 12 }
								]
							}
						],
						"event": "set_in_player_proximity_to_true"
					},
					{
						"filters": [
							{
								"any_of": [
									{
										"all_of": [
											{ "test": "bool_property", "domain": "ldz:in_player_proximity", "value": true },
											{ "test": "distance_to_nearest_player", "operator": ">", "value": 12 }
										]
									},
									{
										"all_of": [
											{ "test": "actor_health", "operator": "==", "value": 0 },
											{ "test": "bool_property", "domain": "ldz:in_player_proximity", "value": true }
										]
									}
								]
							}							
						],
						"event": "set_in_player_proximity_to_false"
					},
					{
						"filters": [
							{
								"test": "is_difficulty",
								"value": "peaceful"
							}
						],
						"event": "despawn",
						"target": "self"
					},
					{
						"filters": [
							{
								"test": "distance_to_nearest_player",
								"operator": ">",
								"value": 70
							}
						],
						"event": "despawn",
						"target": "self"
					}
				]
			},
			"minecraft:damage_sensor": {
				"triggers": [
					{
						"on_damage": {
							"filters": {
								"test": "has_damage",
								"value": "void"
							},
							"event": "despawn"
						},
						"deals_damage": false
					},
					{
						"on_damage": {
							"filters": {
								"any_of":[
									{ "test": "has_equipment", "subject": "other", "domain": "hand", "value": "minecraft:iron_axe" },
									{ "test": "has_equipment", "subject": "other", "domain": "hand", "value": "minecraft:iron_sword" },
									{ "test": "has_equipment", "subject": "other", "domain": "hand", "value": "minecraft:gold_sword" },
									{ "test": "has_equipment", "subject": "other", "domain": "hand", "value": "minecraft:diamond_sword" },
									{ "test": "has_equipment", "subject": "other", "domain": "hand", "value": "minecraft:netherite_sword" }
								]
							}
						},
						"damage_multiplier": 0.75
					},
					{
						"on_damage": {
							"filters": {
								"test": "is_family",
								"subject": "other",
								"value": "player_lord_wisp"
							},
							"target": "other",
							"event": "add_1_to_hits"
						}
					}
				]
			},
			//MOVEMENT
			"minecraft:movement": {
				"value": 0.2
			},
			"minecraft:navigation.generic": {
				"avoid_damage_blocks": true,
				"can_pass_doors": true,
				"can_jump": true
			},
			"minecraft:movement.basic": {},
			"minecraft:behavior.random_stroll": {
				"priority": 6
			},
			"minecraft:behavior.look_at_player": {
				"priority": 8,
				"look_distance": 16,
				"probability": 1
			},
			"minecraft:follow_range": {
				"value": 64
			},
			"minecraft:jump.static": {},
			"minecraft:nameable": {},
			//PHYSICS
			"minecraft:physics": {},
			"minecraft:collision_box": {
				"height": 3.0,
				"width": 0.7
			},
			"minecraft:behavior.look_at_target": {
				"priority": 2,
				"look_distance": 16,
				"probability": 1
			}
		},
		"events": {
			"despawn"							: { "add": {"component_groups": [ "instant_despawn" ] } },
			
			"add_roar"							: { "filters": {
													"test": "actor_health", "operator": "==", "value": 0 },
													"remove": { "component_groups": [ "not_roaring" ] },
													"add": {"component_groups": [ "roaring" ] },
													"set_property": {"ldz:is_roaring": true } },
			"remove_roar"						: { "remove": {"component_groups": [ "roaring" ] },
													"add": {"component_groups": ["not_roaring"]},
													"set_property": {"ldz:is_roaring": false}},

			"set_ice_overlay_to_true"			: { "set_property": {"ldz:ice_overlay": true	},
													"add": { "component_groups": ["ice_overlay"]}},
			"set_ice_overlay_to_false"			: { "set_property": {"ldz:ice_overlay": false},
													"remove": {"component_groups": ["ice_overlay"]}},

			"set_in_player_proximity_to_true"	: { "set_property": {"ldz:in_player_proximity": true  }},
			"set_in_player_proximity_to_false"	: { "set_property": {"ldz:in_player_proximity": false }}
		}
	}
}