
# -> Add to lifetime
scoreboard players add @s OverlyRealistic.General.ArbitraryData 1

# -> Set spear hit success
scoreboard players set #or.spear_hit_success OverlyRealistic.General.ArbitraryData 0

# -> Set spear existence
scoreboard players set #or.thrown_spear_exists OverlyRealistic.General.ArbitraryData 1

# -> If lifetime is maxxed then return and destroy self
#execute if score @s OverlyRealistic.General.ArbitraryData matches 1 run \
    function overly_realistic:general/spears/spear_operate_lifetime_1

# -> Debug particles
#particle flame ~ ~ ~ 0 0 0 0.001 1 force @a
#particle soul_fire_flame ^ ^ ^1 0 0 0 0.001 1 force @a

# -> If lifetime is maxxed then return and destroy self
execute if score @s OverlyRealistic.General.ArbitraryData matches 3600.. run \
    return run \
        function overly_realistic:general/spears/spear_remove

# -> Set existence
#scoreboard players set #or.spears_exist OverlyRealistic.General.ArbitraryData 1

# -> If spear has hit an entity then return
#execute if score #or.spear_hit_success OverlyRealistic.General.ArbitraryData matches 1.. run \
    return fail

# -> If spear does not have base ent then return and operate accordingly
scoreboard players set #or.spear_has_base_ent OverlyRealistic.General.ArbitraryData 0
execute on vehicle run \
    scoreboard players set #or.spear_has_base_ent OverlyRealistic.General.ArbitraryData 1
execute if score #or.spear_has_base_ent OverlyRealistic.General.ArbitraryData matches 0 run \
    return run \
        function overly_realistic:general/spears/spear_remove_from_noveh

# -> If spear hit an entity then operate accordingly
#execute positioned ~-1.5 ~-1.5 ~-1.5 \
    unless score #or.spear_hit_success OverlyRealistic.General.ArbitraryData matches 1.. \
    if entity @n[type=!#overly_realistic:spear_cant_damage,tag=!OverlyRealistic.Player.TempPlayerThrewSpear,dx=2,dz=2,dy=2] \
    at @s run \
        function overly_realistic:general/spears/spear_hit_entity

#execute positioned ^ ^ ^1 \
    positioned ~-1.5 ~-1.5 ~-1.5 \
    unless score #or.spear_hit_success OverlyRealistic.General.ArbitraryData matches 1.. \
    if entity @n[type=!#overly_realistic:spear_cant_damage,tag=!OverlyRealistic.Player.TempPlayerThrewSpear,dx=2,dz=2,dy=2] \
    at @s run \
        function overly_realistic:general/spears/spear_hit_entity

# -> If spear has hit an entity then return
#execute if score #or.spear_hit_success OverlyRealistic.General.ArbitraryData matches 1.. run \
    return fail

# -> Check if spear hit a block
#execute unless block ^ ^ ^0.5 #overly_realistic:spear_can_passthrough run \
    return run \
        function overly_realistic:general/spears/spear_remove

# -> If spear is going downwards then rotate model down
execute on vehicle \
    at @s \
    if predicate overly_realistic:global/entity_downward_velocity_motion \
    on passengers \
    at @s run \
        rotate @s ~ ~3
