
# -> Do spear-dependent-operations
function overly_realistic:general/spears/spear_dependent_operations/get_spear_type

# -> Destroy destructibles
execute positioned ^ ^ ^1 \
    if block ~ ~ ~ #overly_realistic:spears_can_destroy run \
        setblock ~ ~ ~ air destroy
execute positioned ^ ^ ^1.5 \
    if block ~ ~ ~ #overly_realistic:spears_can_destroy run \
        setblock ~ ~ ~ air destroy
execute if block ~ ~ ~ #overly_realistic:spears_can_destroy run \
    setblock ~ ~ ~ air destroy

# -> Damage spear
execute store result score #or.global OverlyRealistic.General.ArbitraryData run \
    data get entity @s item.components.minecraft:damage
execute store result entity @s item.components.minecraft:damage int 1 run \
    scoreboard players add #or.global OverlyRealistic.General.ArbitraryData 1

# -> Break spear if its damage is over its max_damage
execute store result score #or.equation_part_1 OverlyRealistic.General.ArbitraryData run \
    data get entity @s item.components.minecraft:max_damage
execute if score #or.global OverlyRealistic.General.ArbitraryData >= #or.equation_part_1 OverlyRealistic.General.ArbitraryData run \
    return run \
        function overly_realistic:general/spears/spear_remove_self

# -> Drop itself
#loot spawn ~ ~ ~ loot overly_realistic:items/wooden_spear
summon item ~ ~ ~ {Tags:["OverlyRealistic.TempEnt"],Item:{id:"stick",count:1}}
item replace entity @n[type=item,tag=OverlyRealistic.TempEnt,distance=..1] contents from entity @s contents
tag @n[type=item,tag=OverlyRealistic.TempEnt,distance=..1] remove OverlyRealistic.TempEnt
#tellraw @a {entity:"@s",nbt:"item"}

# -> Remove self
execute on vehicle run \
    kill @s
kill @s