
# -> Debug
#particle flame ~ ~3 ~ 0 0 0 0.0001 100 force @a

#particle flame ^0 ^7 ^5 0 0 0 0.001 10 force @a
#particle flame ^-0.5 ^7 ^5 0 0 0 0.001 10 force @a
#particle flame ^0.5 ^7 ^5 0 0 0 0.001 10 force @a
#particle flame ^1 ^7 ^5 0 0 0 0.001 10 force @a
#particle flame ^1.5 ^7 ^5 0 0 0 0.001 10 force @a
#particle flame ^2 ^7 ^5 0 0 0 0.001 10 force @a
#particle flame ^2.5 ^7 ^5 0 0 0 0.001 10 force @a
#particle flame ^-1 ^7 ^5 0 0 0 0.001 10 force @a
#particle flame ^-1.5 ^7 ^5 0 0 0 0.001 10 force @a
#particle flame ^-2 ^7 ^5 0 0 0 0.001 10 force @a
#particle flame ^-2.5 ^7 ^5 0 0 0 0.001 10 force @a


# -> If there are no blocks below then apply gravity
execute if block ~ ~7 ~ #overly_realistic:large_ship_fall_cause \
    unless block ~ ~7 ~ #overly_realistic:large_ship_fall_cause[waterlogged=true] run \
        tp ~ ~-0.5 ~

# --> Set movement values

# -> Forward/backward velocity
execute if score @s OverlyRealistic.World.LargeShip_Velocity_Forward matches 1.. run \
    scoreboard players remove @s OverlyRealistic.World.LargeShip_Velocity_Forward 1
execute if score @s OverlyRealistic.World.LargeShip_Velocity_Forward matches ..-1 run \
    scoreboard players add @s OverlyRealistic.World.LargeShip_Velocity_Forward 1



# --> Operate velocity

# -> Forward velocity
execute if score @s OverlyRealistic.World.LargeShip_Velocity_Forward matches 1.. run \
    function overly_realistic:players/riding_entity/large_ship/ship_operations/move/move_forward

# -> Backward velocity
execute if score @s OverlyRealistic.World.LargeShip_Velocity_Forward matches ..-1 run \
    function overly_realistic:players/riding_entity/large_ship/ship_operations/move/move_backward



# --> Operate key presses

# -> If captain player is holding the forward key then move forward
execute if score #or.current_captain_keybind_down_w OverlyRealistic.General.ArbitraryData matches 1 \
    if score #or.current_captain_keybind_down_s OverlyRealistic.General.ArbitraryData matches 0 \
    unless score @s OverlyRealistic.World.LargeShip_Velocity_Forward matches 10.. run \
        scoreboard players add @s OverlyRealistic.World.LargeShip_Velocity_Forward 2

# -> If captain player is holding the left key then turn left
execute if score #or.current_captain_keybind_down_a OverlyRealistic.General.ArbitraryData matches 1 \
    if score #or.current_captain_keybind_down_d OverlyRealistic.General.ArbitraryData matches 0 run \
        function overly_realistic:players/riding_entity/large_ship/ship_operations/move/filter_turn_left

# -> If captain player is holding the right key then turn right
execute if score #or.current_captain_keybind_down_d OverlyRealistic.General.ArbitraryData matches 1 \
    if score #or.current_captain_keybind_down_a OverlyRealistic.General.ArbitraryData matches 0 run \
        function overly_realistic:players/riding_entity/large_ship/ship_operations/move/filter_turn_right

# -> If captain player is holding the backward key then move forward
execute if score #or.current_captain_keybind_down_s OverlyRealistic.General.ArbitraryData matches 1 \
    if score #or.current_captain_keybind_down_w OverlyRealistic.General.ArbitraryData matches 0 \
    unless score @s OverlyRealistic.World.LargeShip_Velocity_Forward matches ..-10 run \
        scoreboard players remove @s OverlyRealistic.World.LargeShip_Velocity_Forward 2

# -> Debug
#tellraw @a [{text:"velo: "},{score:{name:"@s",objective:"OverlyRealistic.World.LargeShip_Velocity_Forward"}}]
