{
  "format_version": "1.21.90",
  "minecraft:entity": {
    "description": {
      "identifier": "ship:mount",
      "spawn_category": "creature",
      "is_spawnable": true,
      "is_summonable": true
    },

    "component_groups": {
      "despawn": {
        "minecraft:instant_despawn": {}
      },
      "main_steer": {
        "minecraft:item_controllable": {
          "control_items": "ship:control"
        }
      },
      "secondary_steer": {
        "minecraft:item_controllable": {
          "control_items": [
            "ship:control",
            "ship:primary_weapon",
            "ship:secondary_weapon",
            "ship:antiair_weapon",
            "ship:torpedo_weapon"
            ]
        }
      },
      "mount": {
        "minecraft:rideable": {
          "seat_count": 1,
          "dismount_mode": "on_top_center",
          "interact_text": "action.interact.ride.horse",
          "family_types": [
            "player"
          ],
          "seats": {
            "position": [ 0.0, 0.5, 0.0 ],
            "lock_rider_rotation": 135.0
          }
        },
        "minecraft:behavior.controlled_by_player": {
          "priority": 0,
          "fractional_rotation": 0.90,
          "fractional_rotation_limit": 5.0
        }
      }
    },

    "components": {
      "minecraft:buoyant": {
        "base_buoyancy": 1.0,
        "apply_gravity": true,
        "simulate_waves": true,
        "big_wave_probability": 0.03,
        "big_wave_speed": 10.0,
        "liquid_blocks": [
          "minecraft:water",
          "minecraft:flowing_water"
        ]
      },
      "minecraft:entity_sensor": {
        "relative_range": false,
        "subsensors": [
          {
            "cooldown": 1.0,
            "range": [1, 1],
            "event": "despawn",
            "event_filters": [
              {
                "test": "is_family",
                "operator": "!=",
                "subject": "other",
                "value": "player"
              }
              ]
          },
          {
            "cooldown": 1.0,
            "range": [1, 1],
            "event": "checkDespawn",
            "event_filters": [
              {
                "test": "in_contact_with_water",
                "subject": "self",
                "operator": "!=",
                "value": true
              }
              ]
          },
          {
            "cooldown": 0.1,
            "range": [1, 1],
            "event": "movement:engage",
            "event_filters": [
              {
                "test": "has_equipment",
                "domain": "hand",
                "operator": "!=",
                "subject": "self",
                "value": "bedrock"
              }
              ]
          },
          {
            "cooldown": 0.5,
            "range": [1, 1],
            "event": "movement:increase",
            "event_filters": [
              {
                "test": "has_equipment",
                "domain": "hand",
                "operator": "==",
                "subject": "other",
                "value": "ship:control"
              },
              {
                "test": "has_tag",
                "operator": "==",
                "subject": "other",
                "value": "head:ceiling"
              },
              {
                "test": "has_tag",
                "operator": "==",
                "subject": "other",
                "value": "throttle:unlock"
              }
              ]
          },
          {
            "cooldown": 0.5,
            "range": [1, 1],
            "event": "movement:decrease",
            "event_filters": [
              {
                "test": "has_equipment",
                "domain": "hand",
                "operator": "==",
                "subject": "other",
                "value": "ship:control"
              },
              {
                "test": "has_tag",
                "operator": "==",
                "subject": "other",
                "value": "head:floor"
              },
              {
                "test": "has_tag",
                "operator": "==",
                "subject": "other",
                "value": "throttle:unlock"
              }
              ]
          }
          ]
        },
      "minecraft:is_hidden_when_invisible": {
      },
      "minecraft:damage_sensor": {
        "triggers": {
          "on_damage": {
            "filters": [
              { "test": "has_tag", "subject": "other", "operator": "!=", "value": "hswowhs" }
              ]
          },
          "deals_damage": "no"
        }
      },
      "minecraft:type_family": {
        "family": [ "custom_mob", "misc" ]
      },
      "minecraft:breathable": {
        "total_supply": 1500,
        "suffocate_time": 0
      },
      "minecraft:nameable": {
      },
      "minecraft:health": {
        "value": 1000,
        "max": 1000,
        "min": 1
      },
      "minecraft:movement": {
        "value": 0.25
      },
      "minecraft:navigation.walk": {
        "can_path_over_water": true,
        "avoid_water": true,
        "is_amphibious": true,
        "avoid_damage_blocks": true
      },
      "minecraft:movement.basic": {

      },
      "minecraft:jump.static": {
      },
      "minecraft:can_climb": {
      },
      "minecraft:collision_box": {
        "width": 0.1,
        "height": 1.0
      },
      "minecraft:despawn": {
        "despawn_from_distance": {}
      },
      "minecraft:behavior.mount_pathing": {
        "priority": 1,
        "speed_multiplier": 1.25,
        "target_dist": 0.0,
        "track_target": true
      },
      "minecraft:behavior.float": {
        "priority": 2
      },
	    "minecraft:physics": {
      },
      "minecraft:pushable": {
        "is_pushable": false,
        "is_pushable_by_piston": true
      },
      "minecraft:conditional_bandwidth_optimization": {
      }
    },

    "events": {
      "steer_primary": {
        "add": {
          "component_groups": [
            "main_steer"
            ]
        },
        "remove": {
          "component_groups": [
            "secondary_steer"
            ]
        }
      },
      "steer_secondary": {
        "remove": {
          "component_groups": [
            "main_steer"
            ]
        },
        "add": {
          "component_groups": [
            "secondary_steer"
            ]
        }
      },
      "dismounted": {
        "queue_command": {
          "command": [
            "tp @e[c=1,type=!ship:mount,r=1] ^^1.5^1.5"
            ]
        }
      },
      "checkDespawn": {
        "queue_command": {
          "command": [
            "execute as @s unless block ~~-0.25~ water run event entity @s despawn"
            ]
        }
      },
      "despawn": {
        "add": {
          "component_groups": [
            "despawn"
            ]
        }
      },
      "movement:engage": {
        "queue_command": {
          "command": [
            "execute as @s[scores={kbHori=1..4}] run event entity @p[r=1,hasitem={item=ship:control,location=slot.weapon.mainhand}] ship_state:gliding",
            "execute as @s[scores={kbHori=5..}] run event entity @p[r=1,hasitem={item=ship:control,location=slot.weapon.mainhand}] ship_state:jet",
            "execute as @s[scores={kbHori=..-1}] run event entity @p[r=1,hasitem={item=ship:control,location=slot.weapon.mainhand}] ship_state:idle",
            "execute as @s[scores={kbHori=1..}] run event entity @p[r=1,hasitem={item=ship:control,location=slot.weapon.mainhand,quantity=0}] ship_state:gliding",
            "execute as @s[scores={kbHori=..-1}] run event entity @p[r=1,hasitem={item=ship:control,location=slot.weapon.mainhand,quantity=0}] ship_state:idle",
            "execute as @s[scores={kbHori=0}] run event entity @p[r=1] ship_state:idle",
            "execute as @s[scores={kbHori=5..}] run particle ship:trail ~~0.1~",
            "execute as @s[scores={kbHori=1..}] run scriptevent dash:front",
            "execute as @s[scores={kbHori=..-1}] run scriptevent dash:front"
            ]
        }
      },
      "movement:increase": {
        "queue_command": {
          "command": [
            "scoreboard players add @s[scores={kbHori=..15}] kbHori 1",
            "execute as @p[r=1] run titleraw @s actionbar {\"rawtext\":[{\"text\":\"Speed has §aIncreased§r to §a\"},{\"score\":{\"name\":\"@e[c=1,type=!player,r=1]\",\"objective\":\"kbHori\"}}]}"
            ]
        }
      },
      "movement:decrease": {
        "queue_command": {
          "command": [
            "scoreboard players remove @s[scores={kbHori=-5..}] kbHori 1",
            "execute as @p[r=1] run titleraw @s actionbar {\"rawtext\":[{\"text\":\"Speed has §cDecreased§r to §c\"},{\"score\":{\"name\":\"@e[c=1,type=!player,r=1]\",\"objective\":\"kbHori\"}}]}"
            ]
        }
      },
      "minecraft:entity_spawned": {
        "sequence": [
          {
            "add": {
              "component_groups": [
                "mount",
                "main_steer"
                ]
            }
          },
          {
            "queue_command": {
              "command": [
                "scoreboard players set @s kbHori 1",
                "ride @p start_riding @e[c=1,type=ship:mount] teleport_rider until_full"
                ]
            }
          }
        ]
      }
    }
  }
}
