{
  "format_version": "1.10.0",
  "minecraft:attachable": {
    "description": {
      "identifier": "mnp_ci:super_rod",
      "materials": {
        "default": "entity_alphatest",
        "line": "mnp_ci_fishing_line",
        "bobber": "entity_alphatest_one_sided"
      },
      "textures": {
        "default": "textures/mnp/ci/entity/attachable/super_rod",
        "line": "textures/mnp/ci/entity/attachable/super_rod_line_001"
      },
      "geometry": {
        "default": "geometry.fp_super_rod.mnp_ci",
        "tp_base": "geometry.tp_super_rod.mnp_ci",
        "line": "geometry.super_rod_line.mnp_ci"
      },
      "scripts": {
        "initialize": [
          "v.is_first_person = c.is_first_person;", // Used in the RC

          "v.prev_time_stamp = q.time_stamp;", // time in tick of the last calculation of player variables gotten from queries
          "v.prev_p_3p.x = q.position(0); v.prev_p_3p.y = q.position(1); v.prev_p_3p.z = q.position(2);", // previous player feet location  (gotten from queries) (used for 3rd person)
          "v.p_v_3p.x = 0; v.p_v_3p.y = 0; v.p_v_3p.z = 0;", // player velocity       (calculated from queries)
          "v.p_v_3p_frame_alpha = 0;", // resets to 0 every time the related variables are updated. goes from 0 to 1 in the span of a tick (and continues), meant to interpolate velocity variables and such

          "v.casted_rot_y = q.body_y_rotation + q.target_y_rotation;", // player root Y rotation (in world space) to face direction they cast the rod in         (calculated from scripting)
          "v.yaw = 0;", // player head yaw    (calculated from scripting for first person / gotten from queries for third person)
          "v.prev_yaw = 0;", // previous player head yaw
          "v.yaw_delta = 0;", // player head yaw delta

          "v.smooth_yaw_speed = math.clamp(q.yaw_speed * 0.05, -10, 10) * 0.1;", //used for swaying the short fishing line (yaw speed gotten from query for 3rd person, calculated from temp leaking yaw for 1st person)
          "v.smooth_pitch_speed = 0;",

          "v.smooth_p_local_vel_forward = 0; v.smooth_p_local_vel_right = 0; v.sway_forward = 0;  v.sway_right = 0;",

          "v.player_x_rotation = 0;" // head pitch (head yaw is not available this way)
        ],
        "pre_animation": [
          // Position, velocity variables of the player feet
          "!q.is_in_ui && q.time_stamp > v.prev_time_stamp ? {v.p_v_3p.x = q.position(0) - v.prev_p_3p.x; v.prev_p_3p.x = q.position(0); v.p_v_3p.y = q.position(1) - v.prev_p_3p.y; v.prev_p_3p.y = q.position(1); v.p_v_3p.z = q.position(2) - v.prev_p_3p.z; v.prev_p_3p.z = q.position(2); v.p_v_3p_frame_alpha = 0;};",

          // incrementing "frame_alpha" variables
          "v.p_v_3p_frame_alpha = v.p_v_3p_frame_alpha + q.delta_time * 20;",

          // for the sway animations
          "t.yaw_speed = math.clamp(c.is_first_person ? v.yaw_delta : q.yaw_speed * 0.05, -10, 10) * 0.05; v.smooth_yaw_speed = math.lerp(t.yaw_speed, v.smooth_yaw_speed, math.exp((-5 + 4 * math.abs(t.yaw_speed)) * q.delta_time));",
          "q.time_stamp > v.prev_time_stamp ? {v.prev_pitch = (v.pitch ?? v.player_x_rotation); v.pitch = v.player_x_rotation;};",
          "t.pitch_coeff = -2 + math.sqrt(0.5 + math.clamp(v.smooth_pitch_speed * 0.4, -1, 1) * 0.5); v.smooth_pitch_speed = math.lerp(math.clamp(((v.pitch ?? v.player_x_rotation) - (v.prev_pitch ?? v.player_x_rotation)) * t.pitch_coeff * 0.3, -2, 1), v.smooth_pitch_speed, math.exp(-3 * q.delta_time));",

          // local player velocity
          "t.local_p_vel_forward = math.cos(c.is_first_person ? v.yaw : q.body_y_rotation + q.target_y_rotation) * v.p_v_3p.z - math.sin(c.is_first_person ? v.yaw : q.body_y_rotation + q.target_y_rotation) * v.p_v_3p.x; v.smooth_p_local_vel_forward = math.lerp(t.local_p_vel_forward * 0.2 - math.clamp(-v.p_v_3p.y * 0.15, 0, 0.3), v.smooth_p_local_vel_forward, math.exp(-3 * q.delta_time));", // Some downwards vertical velocity added a little bit to this with v.p_v_3p.y
          "t.local_p_vel_right = -math.cos(c.is_first_person ? v.yaw : q.body_y_rotation + q.target_y_rotation) * v.p_v_3p.x - math.sin(c.is_first_person ? v.yaw : q.body_y_rotation + q.target_y_rotation) * v.p_v_3p.z; v.smooth_p_local_vel_right = math.lerp(t.local_p_vel_right * 0.2, v.smooth_p_local_vel_right, math.exp(-3 * q.delta_time));",
          "v.sway_forward = math.clamp(math.lerp(v.smooth_pitch_speed / (1 + v.smooth_yaw_speed * 0.5), v.smooth_pitch_speed / (1 + v.smooth_yaw_speed * 0.5) * 0.5 + v.smooth_p_local_vel_forward * 3, math.min(math.abs(v.smooth_p_local_vel_forward) * 40, 1)), -1, 1);",
          "v.sway_right = math.clamp(math.lerp(v.smooth_yaw_speed / (1 + v.smooth_pitch_speed * 0.5 + math.abs(v.smooth_p_local_vel_forward) * 30), v.smooth_yaw_speed / (1 + v.smooth_pitch_speed * 0.5 + math.abs(v.smooth_p_local_vel_forward) * 30) * 0.5 + v.smooth_p_local_vel_right * 3, math.min(math.abs(v.smooth_p_local_vel_right) * 40, 1)), -1, 1);",

          "v.is_first_person = c.is_first_person;", // Used in the RC
          "v.prev_time_stamp = q.time_stamp;"
        ],
        "animate": [
          {
            "wield_first_person": "c.is_first_person"
          },
          {
            "wield_third_person": "!c.is_first_person"
          },
          "sway"
        ]
      },
      "animations": {
        "wield_first_person": "animation.super_rod.mnp_ci.wield_first_person",
        "wield_third_person": "animation.super_rod.mnp_ci.wield_third_person.not_player",

        "sway": "animation.super_rod.mnp_ci.sway"
      },
      "render_controllers": ["controller.render.super_rod.mnp_ci", "controller.render.super_rod_line.mnp_ci"]
    }
  }
}
