
# -> Sound
playsound minecraft:block.anvil.place block @a ~ ~ ~ 0.8 1.4

# -> On RNG, decrease stamina
execute if predicate overly_realistic:world/campfire/stamina_decrease_rng run \
    scoreboard players remove @s OverlyRealistic.Player.Stats.Stamina 1

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

# -> Particle
#particle item{item:flint} ~0.5 ~0.5 ~0.5 0.4 0.4 0.4 0.01 4 normal @a

# -> Particle
execute align xyz \
    positioned ~ ~1 ~ \
    as @n[type=item,dx=0,dy=0,dz=0] \
    if items entity @s contents #overly_realistic:iron_tools[custom_data~{current_process:"unheated"}] \
    at @s run \
        particle lava ~ ~0.3 ~ 0 0 0 0.1 1 normal @a

# -> Add anvil attempts
scoreboard players add @s OverlyRealistic.Player.AnvilForgingHammerHits 1

# -> On RNG fail, if player has less than max hammer hits, return
execute unless score @s[scores={OverlyRealistic.Player.WisdomStats.Blacksmithing=..3}] OverlyRealistic.Player.AnvilForgingHammerHits matches 150.. \
    unless predicate overly_realistic:world/forging/forge_tool_on_anvil_rng run \
        return fail
execute unless score @s[scores={OverlyRealistic.Player.WisdomStats.Blacksmithing=4..}] OverlyRealistic.Player.AnvilForgingHammerHits matches 10.. \
    unless predicate overly_realistic:world/forging/forge_tool_on_anvil_rng run \
        return fail

# -> Add blacksmithing XP
function overly_realistic:players/wisdom/blacksmithing/add_to_skill_xp_c_forge_tool_on_anvil

# -> Reset hammer hits
scoreboard players reset @s OverlyRealistic.Player.AnvilForgingHammerHits

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

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

# -> Forge tool
execute align xyz \
    positioned ~ ~1 ~ \
    as @n[type=item,dx=0,dy=0,dz=0,tag=!OverlyRealistic.IronToolItemAnvilComplete] \
    if items entity @s contents #overly_realistic:iron_tools[custom_data~{current_process:"unheated"}] run \
        function overly_realistic:general/forgery/iron_tools/set_iron_tool_new_process {process:"forged"}

# -> Particle
particle smoke ~0.5 ~0.5 ~0.5 0.05 0.05 0.05 0.01 10 normal @a
