
# -> If player is not using a forging hammer then return
execute unless items entity @s weapon.mainhand *[custom_data~{or_tool_type:"forging_hammer"}] run \
    return run \
        scoreboard players set #or.player_didnt_use_forging_hammer_hwi_int OverlyRealistic.General.ArbitraryData 1

# -> Hit wrought iron
execute if score @s OverlyRealistic.World.HeatedWroughtIron_Player_SelectedMethod = @s OverlyRealistic.World.HeatedWroughtIron_Player_LastSelectedMethod run \
    function overly_realistic:general/custom_blocks/hwi_interaction_indicator/player_operations/player_hammer_indicator
execute unless score @s OverlyRealistic.World.HeatedWroughtIron_Player_SelectedMethod = @s OverlyRealistic.World.HeatedWroughtIron_Player_LastSelectedMethod run \
    function overly_realistic:general/custom_blocks/heated_wrought_iron/loop_operations/player_specific/player_choose_new_select_method

scoreboard players operation @s OverlyRealistic.World.HeatedWroughtIron_Player_LastSelectedMethod = @s OverlyRealistic.World.HeatedWroughtIron_Player_SelectedMethod

# -> Reset selected method
#scoreboard players set @s OverlyRealistic.World.HeatedWroughtIron_Player_SelectedMethod 1

# -> Reset shown methods
#title @s times 0 40 40
#title @s title ""
#title @s subtitle [{text:"[",color:"#b1b1b1"},{text:" ✔ ",color:"#e78a3e"},{text:"❌",color:"#b1b1b1"},{text:" ↑↓ ",color:"#b1b1b1"},{text:"←→",color:"#b1b1b1"},{text:" ▼ ",color:"#b1b1b1"},{text:"]",color:"#b1b1b1"},{text:" [",color:"#b1b1b1"},{score:{name:"@s",objective:"OverlyRealistic.World.HeatedWroughtIron_Player_ForgePercent"},color:"#b1b1b1"},{text:"%",color:"#b1b1b1"},{text:"]",color:"#b1b1b1"}]

# -> Display methods
title @s times 0 40 40
title @s title ""

title @s[scores={OverlyRealistic.World.HeatedWroughtIron_Player_SelectedMethod=1}] subtitle [{text:"",extra:[{text:"\u0011",font:"overlyrealistic:hud/hud_wrought_iron_forging",shadow_color:0},{text:"\u0111",font:"overlyrealistic:hud/hud_wrought_iron_forging"},{score:{name:"@s",objective:"OverlyRealistic.World.HeatedWroughtIron_Player_ForgePercent"},font:"overlyrealistic:hud/hud_wrought_iron_forging"},{text:"%",font:"overlyrealistic:hud/hud_wrought_iron_forging"}]}]
title @s[scores={OverlyRealistic.World.HeatedWroughtIron_Player_SelectedMethod=2}] subtitle [{text:"",extra:[{text:"\u0012",font:"overlyrealistic:hud/hud_wrought_iron_forging",shadow_color:0},{text:"\u0111",font:"overlyrealistic:hud/hud_wrought_iron_forging"},{score:{name:"@s",objective:"OverlyRealistic.World.HeatedWroughtIron_Player_ForgePercent"},font:"overlyrealistic:hud/hud_wrought_iron_forging"},{text:"%",font:"overlyrealistic:hud/hud_wrought_iron_forging"}]}]
title @s[scores={OverlyRealistic.World.HeatedWroughtIron_Player_SelectedMethod=3}] subtitle [{text:"",extra:[{text:"\u0013",font:"overlyrealistic:hud/hud_wrought_iron_forging",shadow_color:0},{text:"\u0111",font:"overlyrealistic:hud/hud_wrought_iron_forging"},{score:{name:"@s",objective:"OverlyRealistic.World.HeatedWroughtIron_Player_ForgePercent"},font:"overlyrealistic:hud/hud_wrought_iron_forging"},{text:"%",font:"overlyrealistic:hud/hud_wrought_iron_forging"}]}]
title @s[scores={OverlyRealistic.World.HeatedWroughtIron_Player_SelectedMethod=4}] subtitle [{text:"",extra:[{text:"\u0014",font:"overlyrealistic:hud/hud_wrought_iron_forging",shadow_color:0},{text:"\u0111",font:"overlyrealistic:hud/hud_wrought_iron_forging"},{score:{name:"@s",objective:"OverlyRealistic.World.HeatedWroughtIron_Player_ForgePercent"},font:"overlyrealistic:hud/hud_wrought_iron_forging"},{text:"%",font:"overlyrealistic:hud/hud_wrought_iron_forging"}]}]
title @s[scores={OverlyRealistic.World.HeatedWroughtIron_Player_SelectedMethod=5}] subtitle [{text:"",extra:[{text:"\u0015",font:"overlyrealistic:hud/hud_wrought_iron_forging",shadow_color:0},{text:"\u0111",font:"overlyrealistic:hud/hud_wrought_iron_forging"},{score:{name:"@s",objective:"OverlyRealistic.World.HeatedWroughtIron_Player_ForgePercent"},font:"overlyrealistic:hud/hud_wrought_iron_forging"},{text:"%",font:"overlyrealistic:hud/hud_wrought_iron_forging"}]}]

# -> If 'instant HWI' is turned on then set forge percent to 100
execute if score #or.setting.debug.instant_hwi OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
    scoreboard players set @s OverlyRealistic.World.HeatedWroughtIron_Player_ForgePercent 100

# -> If forge value < max then return
execute unless score @s OverlyRealistic.World.HeatedWroughtIron_Player_ForgePercent matches 100.. run \
    return fail

# -> Reset forge value
scoreboard players set @s OverlyRealistic.World.HeatedWroughtIron_Player_ForgePercent 0

# --> Methods

# -> Set completion status to current method selected
scoreboard players operation #or.heated_wrought_iron_completion_status OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.World.HeatedWroughtIron_Player_LastSelectedMethod
