
# -> Untag player
tag @s remove OverlyRealistic.Player.IsUsingSpear

# -> Reset spear time old
scoreboard players set @s OverlyRealistic.Player.UsingSpearTime_Old 0

# -> If player hasn't been holding down the spear for long enough then return
execute unless score @s OverlyRealistic.Player.UsingSpearTime_New matches 15.. run \
    return run \
        scoreboard players set @s OverlyRealistic.Player.UsingSpearTime_New 0

# -> If player is not holding a spear then return
execute unless items entity @s weapon.mainhand poisonous_potato[custom_data~{IsSpear:1b}] run \
    return run \
        scoreboard players set @s OverlyRealistic.Player.UsingSpearTime_New 0

# -> Store spear item
item replace entity 00000001-0000-002b-0000-00010000002b contents from entity @s weapon.mainhand

# -> Remove spear from player
item replace entity @s[gamemode=!creative] weapon.mainhand with air

# -> Sound
playsound entity.arrow.shoot player @a ~ ~ ~ 0.6 1.3
playsound minecraft:entity.breeze.jump player @a ~ ~ ~ 0.15 1.8

# -> Remove spear time new
scoreboard players set @s OverlyRealistic.Player.UsingSpearTime_New 0

# -> Tag player
tag @s add OverlyRealistic.Player.TempPlayerThrewSpear

# -> Create ID if player does not have one already
execute unless score @s OverlyRealistic.Player.UsingSpearID matches -2147483648..2147483647 \
    store result score @s OverlyRealistic.Player.UsingSpearID run \
        scoreboard players add #or.global OverlyRealistic.Player.UsingSpearID 1

# -> Create spear entity ( cant use exec summon here because it would be visible for a couple of ms :pensive: )
execute anchored eyes \
    positioned ^ ^ ^ \
    anchored feet run \
        summon armor_stand ^ ^ ^ {DisabledSlots:4144959,Silent:1b,Small:1b,Invisible:1b,PersistenceRequired:1b,Tags:["OverlyRealistic.Item.SpearBaseEnt","OverlyRealistic.Item.TempSpearEnt"],attributes:[{id:"minecraft:gravity",base:0.06},{id:"minecraft:scale",base:0.0625}]}
execute as @n[type=armor_stand,tag=OverlyRealistic.Item.TempSpearEnt,distance=..10] at @s run \
    function overly_realistic:players/misc/spear/spear_create_entity

# -> Untag player
tag @s remove OverlyRealistic.Player.TempPlayerThrewSpear