
# -> Particle
particle falling_lava ~ ~-0.3 ~ 0.1 0.1 0.1 0.01 1 normal @s

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

# -> Sound
playsound minecraft:block.calcite.break block @a ~ ~ ~ 0.4 2
playsound minecraft:block.iron.break block @a ~ ~ ~ 1 2
playsound minecraft:block.iron.break block @a ~ ~ ~ 1 2

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

# -> Set time
scoreboard players set @s OverlyRealistic.World.HeatedWroughtIron_Player_UsageTime 0

# -> Stamina cost
scoreboard players remove @s OverlyRealistic.Player.Stats.Stamina 2

# -> Altitude checks
scoreboard players remove @s[y=150,dy=9999] OverlyRealistic.Player.Stats.Stamina 1
scoreboard players remove @s[y=250,dy=9999] OverlyRealistic.Player.Stats.Stamina 1

# -> If player does not have any selected methods then return and set selected method
execute unless score @s OverlyRealistic.World.HeatedWroughtIron_Player_SelectedMethod matches 1.. run \
    return run \
        function overly_realistic:general/custom_blocks/heated_wrought_iron/loop_operations/player_specific/player_start_interaction

# -> If player is shifting then select next method
execute if score @s OverlyRealistic.PredicateValue.IsSneaking matches 1 run \
    return run \
        function overly_realistic:general/custom_blocks/heated_wrought_iron/player_select_next_method

# -> 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/heated_wrought_iron/loop_operations/player_specific/player_hit_heated_wrought_iron
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 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
