
# -> Tag spear
tag @s add OverlyRealistic.TempEntSpear

# -> Globalize ID
scoreboard players operation #or.current_spear_id OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.Player.UsingSpearID

# -> Get player who owns the spear
execute as @a[x=0,distance=..1024] \
    if score @s OverlyRealistic.Player.UsingSpearID = #or.current_spear_id OverlyRealistic.General.ArbitraryData run \
        tag @s add OverlyRealistic.Player.TempPlayerThrewSpear

# -> Untag spear
tag @s remove OverlyRealistic.TempEntSpear

# -> Attempt to damage the entity
execute store success score #or.spear_hit_success OverlyRealistic.General.ArbitraryData \
    positioned ~-1.5 ~-1.5 ~-1.5 run \
        damage @n[type=!#overly_realistic:spear_cant_damage,tag=!OverlyRealistic.Player.TempPlayerThrewSpear,dx=2,dz=2,dy=2] 15.0 player_attack by @p[tag=OverlyRealistic.Player.TempPlayerThrewSpear] from @s

# -> Untag player
tag @p[tag=OverlyRealistic.Player.TempPlayerThrewSpear] remove OverlyRealistic.Player.TempPlayerThrewSpear
