
# -> Sound
playsound minecraft:block.grindstone.use block @a ~ ~ ~ 1 1.2

# -> Decrease stamina
scoreboard players remove @s OverlyRealistic.Player.Stats.Stamina 1

# -> Particle
execute at @s \
    anchored eyes run \
        particle item{item:"iron_sword"} ^ ^ ^0.7 0.1 0.1 0.1 0.01 1 normal @a
particle smoke ~ ~ ~ 0.3 0.3 0.3 0.01 5 normal @a

# -> Add to usage value
scoreboard players add @s OverlyRealistic.Player.GrindstoneSharpenToolUsage 1
scoreboard players add @s[scores={OverlyRealistic.Player.WisdomStats.Blacksmithing=2..}] OverlyRealistic.Player.GrindstoneSharpenToolUsage 1

# -> Cap usage
execute if score @s OverlyRealistic.Player.GrindstoneSharpenToolUsage matches 101.. run \
    scoreboard players set @s OverlyRealistic.Player.GrindstoneSharpenToolUsage 100

# -> Display usage
title @s title ""
title @s times 0 40 40
title @s subtitle [{atlas:"blocks",sprite:"block/grindstone_side",color:"white",shadow_color:0},{text:" "},{score:{name:"@s",objective:"OverlyRealistic.Player.GrindstoneSharpenToolUsage"},color:"#ffffff",shadow_color:-10395295},{text:"%",color:"#ffffff",shadow_color:-10395295}]

# -> If cap hasnt been reached then return
execute unless score @s OverlyRealistic.Player.GrindstoneSharpenToolUsage matches 100.. run \
    return fail

# -> Reset value
scoreboard players reset @s OverlyRealistic.Player.GrindstoneSharpenToolUsage

# -> Advancement
advancement grant @s only overly_realistic:advancements/iron_age/it_keeps_getting_sharper

# -> Intelligence gain RNG
execute if predicate overly_realistic:player/misc/intelligence_gain_general_rng run \
    function overly_realistic:players/intelligence/add_1_intelligence

# -> Increase blacksmithing XP
function overly_realistic:players/wisdom/blacksmithing/add_to_skill_xp_c_sharpen_equipment

# -> Sound
playsound minecraft:block.grindstone.use block @a ~ ~ ~ 0.7 2

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

# -> Sharpen tool
execute if items entity 00000001-0000-002b-0000-00010000002b contents iron_sword[custom_data~{current_process:"forged"}] run \
    return run \
        function overly_realistic:players/items/iron_tool_forge_forged/tool_sharpen/iron_sword
execute if items entity 00000001-0000-002b-0000-00010000002b contents *[custom_data~{or_tool_type:"axe",current_process:"forged"}] run \
    return run \
        function overly_realistic:players/items/iron_tool_forge_forged/tool_sharpen/iron_axe
execute if items entity 00000001-0000-002b-0000-00010000002b contents iron_pickaxe[custom_data~{current_process:"forged"}] run \
    return run \
        function overly_realistic:players/items/iron_tool_forge_forged/tool_sharpen/iron_pickaxe
execute if items entity 00000001-0000-002b-0000-00010000002b contents iron_shovel[custom_data~{current_process:"forged"}] run \
    return run \
        function overly_realistic:players/items/iron_tool_forge_forged/tool_sharpen/iron_shovel
execute if items entity 00000001-0000-002b-0000-00010000002b contents iron_hoe[custom_data~{current_process:"forged"}] run \
    return run \
        function overly_realistic:players/items/iron_tool_forge_forged/tool_sharpen/iron_hoe
