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

# -> Get player who owns the spear
execute as @a[x=0] \
    if score @s OverlyRealistic.Player.UsingSpearID = @n[type=item_display,tag=OverlyRealistic.TempEntSpear] OverlyRealistic.Player.UsingSpearID run \
        tag @s add OverlyRealistic.Player.TempPlayerThrewSpear

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

# -> Attempt to damage the entity
scoreboard players set #or.global OverlyRealistic.General.ArbitraryData 0
execute store success score #or.global OverlyRealistic.General.ArbitraryData \
    positioned ~-1 ~-1 ~-1 run \
        damage @n[type=!#overly_realistic:spear_cant_damage,tag=!OverlyRealistic.Player.TempPlayerThrewSpear,dx=1,dz=1,dy=1] 7.25 player_attack by @p[tag=OverlyRealistic.Player.TempPlayerThrewSpear] from @s

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

# -> If attempt was unsuccessful then return
execute if score #or.global OverlyRealistic.General.ArbitraryData matches 0 run \
    return fail

# -> Remove spear
function overly_realistic:general/spears/spear_remove
