{
  "format_version": "1.26.0",
  "use_beta_features": true,
  "minecraft:entity": {
    "description": {
      "identifier": "minecraft:creaking",
      "is_summonable": true,
      "is_spawnable": true,
      "properties": {
        "minecraft:creaking_swaying_ticks": {
          "client_sync": true,
          "default": 0,
          "range": [
            0,
            6
          ],
          "type": "int"
        },
        "minecraft:creaking_state": {
          "client_sync": true,
          "default": "neutral",
          "type": "enum",
          "values": [
            "neutral",
            "hostile_observed",
            "hostile_unobserved",
            "twitching",
            "crumbling"
          ]
        }
      },
      "spawn_category": "monster"
    },
    "components": {
      "minecraft:attack": {
        "damage": 3
      },
      "minecraft:can_climb": {},
      "minecraft:collision_box": {
        "height": 2.7,
        "width": 0.9
      },
      "minecraft:despawn": {
        "despawn_from_distance": {}
      },
      "minecraft:follow_range": {
        "max": 32,
        "value": 32
      },
      "minecraft:health": {
        "max": 1,
        "value": 1
      },
      "minecraft:is_hidden_when_invisible": {},
      "minecraft:jump.static": {},
      "minecraft:movement.basic": {},
      "minecraft:nameable": {},
      "minecraft:physics": {},
      "minecraft:renders_when_invisible": {},
      "minecraft:type_family": {
        "family": [
          "creaking",
          "monster",
          "mob"
        ]
      },
      "minecraft:variable_max_auto_step": {
        "base_value": 1.0625, // 1 block + 1 pixel
        "jump_prevented_value": 0.5625 // 0.5 blocks + 1 pixel
      }
    },
    "component_groups": {
      "minecraft:crumbling": {
        "minecraft:instant_despawn": {}
      },
      "minecraft:neutral": {
        "minecraft:ambient_sound_interval": {},
        "minecraft:behavior.random_stroll": {
          "priority": 7,
          "speed_multiplier": 0.3
        },
        "minecraft:looked_at": {
          "scale_fov_by_distance": false,
          "line_of_sight_obstruction_type": "collision_for_camera",
          "field_of_view": 120,
          "filters": {
            "operator": ">",
            "test": "actor_health",
            "subject": "other",
            "value": 0
          },
          "looked_at_event": {
            "event": "minecraft:become_hostile",
            "filter": "self"
          },
          "find_players_only": true,
          "look_at_locations": [
            {
              "location": "head"
            },
            {
              "location": "body"
            },
            {
              "location": "feet",
              "vertical_offset": 0.5
            }
          ],
          "looked_at_cooldown": 0.1,
          "search_radius": 12,
          "set_target": "once_and_keep_scanning"
        }
      },
      "minecraft:hostile": {
        "minecraft:ambient_sound_interval": {
          // We need to override the ambient sound to be something else or it will play even after the component is removed.
          "event_name": "undefined"
        },
        "minecraft:looked_at": {
          "line_of_sight_obstruction_type": "collision_for_camera",
          "field_of_view": 120,
          "not_looked_at_event": {
            "event": "minecraft:on_target_stop_looking",
            "filter": "self"
          },
          "filters": {
            "none_of": [
              {
                "subject": "target",
                "test": "actor_health",
                "value": 0
              },
              {
                "domain": "head",
                "subject": "other",
                "test": "has_equipment",
                "value": "carved_pumpkin"
              }
            ]
          },
          "looked_at_event": {
            "event": "minecraft:on_target_start_looking",
            "filter": "self"
          },
          "find_players_only": true,
          "look_at_locations": [
            {
              "location": "head"
            },
            {
              "location": "body"
            },
            {
              "location": "feet",
              "vertical_offset": 0.5
            }
          ],
          "looked_at_cooldown": 0.1,
          "scale_fov_by_distance": false,
          "search_radius": 24,
          "set_target": "never"
        }
      },
      "minecraft:mobile": {
        "minecraft:behavior.float": {
          "priority": 0
        },
        "minecraft:knockback_resistance": {
          "value": 0
        },
        "minecraft:movement": {
          "value": 0.4
        },
        "minecraft:pushable": {
          "is_pushable": true,
          "is_pushable_by_piston": true
        }
      },
      "minecraft:spawned_by_player": {
        "minecraft:environment_sensor": {
          "triggers": [
            // This trigger needs to be aligned with the analogous one defined in "minecraft:spawned_by_creaking_heart".
            {
              "event": "minecraft:become_neutral",
              "filters": {
                "all_of": [
                  {
                    "any_of": [
                      {
                        "domain": "minecraft:creaking_state",
                        "test": "enum_property",
                        "value": "hostile_observed"
                      },
                      {
                        "domain": "minecraft:creaking_state",
                        "test": "enum_property",
                        "value": "hostile_unobserved"
                      }
                    ]
                  },
                  {
                    "any_of": [
                      {
                        "test": "has_target",
                        "value": false
                      },
                      {
                        "subject": "target",
                        "test": "actor_health",
                        "value": 0
                      },
                      {
                        "operator": ">",
                        "test": "target_distance",
                        "value": 24
                      }
                    ]
                  }
                ]
              }
            }
          ]
        },
        "minecraft:hurt_on_condition": {
          "damage_conditions": [
            {
              "cause": "lava",
              "damage_per_tick": 4,
              "filters": {
                "test": "in_lava"
              }
            }
          ]
        },
        "minecraft:navigation.walk": {
          "avoid_damage_blocks": true,
          "can_path_over_lava": false,
          "can_path_over_water": true
        }
      },
      "minecraft:hostile_unobserved": {
        "minecraft:behavior.melee_box_attack": {
          "cooldown_time": 2,
          "priority": 2
        }
      },
      "minecraft:immobile": {
        "minecraft:body_rotation_blocked": {},
        "minecraft:knockback_resistance": {
          "value": 1
        },
        "minecraft:movement": {
          "value": 0
        },
        "minecraft:pushable": {
          "is_pushable": false,
          "is_pushable_by_piston": false
        }
      },
      "minecraft:spawned_by_creaking_heart": {
        "minecraft:damage_sensor": {
          "triggers": [
            {
              "cause": "void",
              "deals_damage": "yes"
            },
            {
              "cause": "all",
              "on_damage": {
                "event": "minecraft:damaged_by_player",
                "filters": {
                  "subject": "other",
                  "test": "is_family",
                  "value": "player"
                }
              },
              "deals_damage": "no_but_side_effects_apply"
            },
            {
              "cause": "all",
              "on_damage": {
                "event": "minecraft:damaged_by_entity",
                "filters": {
                  "subject": "other",
                  "test": "is_family",
                  "value": "mob"
                }
              },
              "deals_damage": "no_but_side_effects_apply"
            },
            {
              "cause": "projectile",
              "on_damage": {
                "event": "minecraft:damaged_by_entity"
              },
              "deals_damage": "no_but_side_effects_apply"
            },
            {
              "cause": "all",
              "deals_damage": "no_but_side_effects_apply"
            }
          ]
        },
        "minecraft:dimension_bound": {},
        "minecraft:environment_sensor": {
          "triggers": [
            // This trigger needs to be aligned with the analogous one defined in "minecraft:spawned_by_player".
            {
              "event": "minecraft:become_neutral",
              "filters": {
                "all_of": [
                  {
                    "any_of": [
                      {
                        "domain": "minecraft:creaking_state",
                        "test": "enum_property",
                        "value": "hostile_observed"
                      },
                      {
                        "domain": "minecraft:creaking_state",
                        "test": "enum_property",
                        "value": "hostile_unobserved"
                      }
                    ]
                  },
                  {
                    "any_of": [
                      {
                        "test": "has_target",
                        "value": false
                      },
                      {
                        "subject": "target",
                        "test": "actor_health",
                        "value": 0
                      },
                      {
                        "operator": ">",
                        "test": "target_distance",
                        "value": 24
                      }
                    ]
                  }
                ]
              }
            },
            // Force the Creaking to despawn if the conditions for it being spawned are no longer met.
            {
              "event": "minecraft:crumble_and_notify_creaking_heart",
              "filters": {
                "all_of": [
                  {
                    "none_of": [
                      {
                        "domain": "minecraft:creaking_state",
                        "test": "enum_property",
                        "value": "twitching"
                      },
                      {
                        "test": "has_nametag"
                      }
                    ]
                  },
                  {
                    "any_of": [
                      {
                        "operator": ">",
                        "test": "home_distance",
                        "value": 34
                      },
                      // These values correspond to the rising and setting times of the moon, as in Dimension::isMoonVisible
                      {
                        "operator": ">",
                        "test": "hourly_clock_time",
                        "value": 23400
                      },
                      {
                        "operator": "<=",
                        "test": "hourly_clock_time",
                        "value": 12600
                      }
                    ]
                  }
                ]
              }
            },
            {
              "event": "minecraft:crumble",
              "filters": {
                "all_of": [
                  {
                    "domain": "minecraft:creaking_state",
                    "operator": "not",
                    "test": "enum_property",
                    "value": "twitching"
                  },
                  {
                    "domain": "minecraft:creaking_state",
                    "operator": "not",
                    "test": "enum_property",
                    "value": "crumbling"
                  },
                  {
                    "test": "is_bound_to_creaking_heart",
                    "value": false
                  }
                ]
              }
            },
            // Make sure that the Creaking sways for exactly 5 ticks.
            {
              "event": "minecraft:increment_swaying_ticks",
              "filters": {
                "all_of": [
                  {
                    "domain": "minecraft:creaking_swaying_ticks",
                    "operator": ">",
                    "test": "int_property",
                    "value": 0
                  },
                  {
                    "domain": "minecraft:creaking_swaying_ticks",
                    "operator": "<=",
                    "test": "int_property",
                    "value": 5
                  }
                ]
              }
            },
            {
              "event": "minecraft:reset_swaying_ticks",
              "filters": {
                "domain": "minecraft:creaking_swaying_ticks",
                "operator": ">",
                "test": "int_property",
                "value": 5
              }
            }
          ]
        },
        "minecraft:fire_immune": {},
        "minecraft:home": {
          "restriction_radius": 32,
          "restriction_type": "all_movement"
        },
        "minecraft:navigation.walk": {
          "avoid_damage_blocks": false,
          "can_path_over_lava": true,
          "can_path_over_water": true
        }
      },
      "minecraft:twitching": {
        "minecraft:behavior.timer_flag_1": {
          "duration_range": {
            "min": 2.25,
            "max": 2.25
          },
          "on_end": {
            "event": "minecraft:crumble"
          }
        }
      }
    },
    "events": {
      "minecraft:crumble": {
        "filters": {
          "domain": "minecraft:creaking_state",
          "test": "enum_property",
          "operator": "not",
          "value": "crumbling"
        },
        "add": {
          "component_groups": [
            "minecraft:immobile",
            "minecraft:crumbling"
          ]
        },
        "emit_particle": {
          "particle": "creakingcrumble"
        },
        "play_sound": {
          "sound": "death"
        },
        "emit_vibration": {
          "vibration": "entity_die"
        },
        "set_property": {
          "minecraft:creaking_state": "crumbling"
        },
        "remove": {
          "component_groups": [
            "minecraft:neutral",
            "minecraft:hostile",
            "minecraft:hostile_unobserved",
            "minecraft:twitching",
            "minecraft:mobile"
          ]
        }
      },
      "minecraft:become_hostile": {
        "filters": {
          "domain": "minecraft:creaking_state",
          "test": "enum_property",
          "value": "neutral"
        },
        "add": {
          "component_groups": [
            "minecraft:hostile",
            "minecraft:immobile"
          ]
        },
        "play_sound": {
          "sound": "activate"
        },
        "emit_vibration": {
          "vibration": "entity_act"
        },
        "set_property": {
          "minecraft:creaking_state": "hostile_observed"
        },
        "remove": {
          "component_groups": [
            "minecraft:neutral",
            "minecraft:hostile_unobserved",
            "minecraft:mobile"
          ]
        }
      },
      "minecraft:become_neutral": {
        "filters": {
          "domain": "minecraft:creaking_state",
          "test": "enum_property",
          "operator": "not",
          "value": "neutral"
        },
        "add": {
          "component_groups": [
            "minecraft:neutral",
            "minecraft:mobile"
          ]
        },
        "play_sound": {
          "sound": "deactivate"
        },
        "emit_vibration": {
          "vibration": "entity_act"
        },
        "set_property": {
          "minecraft:creaking_state": "neutral"
        },
        "remove": {
          "component_groups": [
            "minecraft:hostile",
            "minecraft:hostile_unobserved",
            "minecraft:immobile"
          ]
        },
        "reset_target": {}
      },
      "minecraft:entity_spawned_by_creaking_heart": {
        "add": {
          "component_groups": [
            "minecraft:spawned_by_creaking_heart",
            "minecraft:neutral",
            "minecraft:mobile"
          ]
        }
      },
      "minecraft:crumble_and_notify_creaking_heart": {
        "trigger": "minecraft:crumble",
        "execute_event_on_home_block": {
          "event": "minecraft:on_spawned_creaking_crumbling"
        }
      },
      "minecraft:damaged_by_entity": {
        "trigger": "minecraft:increment_swaying_ticks",
        "emit_vibration": {
          "vibration": "entity_act"
        }
      },
      "minecraft:damaged_by_player": {
        "trigger": "minecraft:increment_swaying_ticks",
        "execute_event_on_home_block": {
          "event": "minecraft:on_spawned_creaking_damaged_by_player"
        },
        "emit_vibration": {
          "vibration": "entity_act"
        }
      },
      "minecraft:entity_spawned": {
        "add": {
          "component_groups": [
            "minecraft:spawned_by_player",
            "minecraft:neutral",
            "minecraft:mobile"
          ]
        }
      },
      "minecraft:increment_swaying_ticks": {
        "set_property": {
          "minecraft:creaking_swaying_ticks": "math.clamp(query.property('minecraft:creaking_swaying_ticks') + 1, 0, 6)"
        }
      },
      "minecraft:on_target_start_looking": {
        "filters": {
          "domain": "minecraft:creaking_state",
          "test": "enum_property",
          "value": "hostile_unobserved"
        },
        "add": {
          "component_groups": [
            "minecraft:hostile",
            "minecraft:immobile"
          ]
        },
        "play_sound": {
          "sound": "freeze"
        },
        "emit_vibration": {
          "vibration": "entity_act"
        },
        "set_property": {
          "minecraft:creaking_state": "hostile_observed"
        },
        "remove": {
          "component_groups": [
            "minecraft:neutral",
            "minecraft:hostile_unobserved",
            "minecraft:mobile"
          ]
        }
      },
      "minecraft:on_target_stop_looking": {
        "filters": {
          "domain": "minecraft:creaking_state",
          "test": "enum_property",
          "value": "hostile_observed"
        },
        "add": {
          "component_groups": [
            "minecraft:hostile",
            "minecraft:hostile_unobserved",
            "minecraft:mobile"
          ]
        },
        "play_sound": {
          "sound": "unfreeze"
        },
        "emit_vibration": {
          "vibration": "entity_act"
        },
        "set_property": {
          "minecraft:creaking_state": "hostile_unobserved"
        },
        "remove": {
          "component_groups": [
            "minecraft:neutral",
            "minecraft:immobile"
          ]
        }
      },
      "minecraft:reset_swaying_ticks": {
        "set_property": {
          "minecraft:creaking_swaying_ticks": "0"
        }
      },
      "minecraft:start_twitching": {
        "filters": {
          "domain": "minecraft:creaking_state",
          "test": "enum_property",
          "operator": "not",
          "value": "twitching"
        },
        "add": {
          "component_groups": [
            "minecraft:immobile",
            "minecraft:twitching"
          ]
        },
        "set_property": {
          "minecraft:creaking_state": "twitching"
        },
        "remove": {
          "component_groups": [
            "minecraft:neutral",
            "minecraft:hostile",
            "minecraft:hostile_unobserved",
            "minecraft:mobile"
          ]
        }
      }
    }
  }
}