
# -> If forging plate already has an item then return
execute if entity @s[tag=OverlyRealistic.Block.ForgingPlate_Status_Filled] run \
    return fail

# -> Attempt to remove player's item
execute on target run \
    item modify entity @s[gamemode=!creative] weapon.mainhand overly_realistic:multipurpose/remove_one_item

# -> Set tag
tag @s remove OverlyRealistic.Block.ForgingPlate_Status_Empty
tag @s add OverlyRealistic.Block.ForgingPlate_Status_Filled

# --> Add item

# -> Sound
playsound block.metal.place block @a ~ ~ ~ 0.4 2

# -> Create new item
execute summon item_display run \
    function overly_realistic:general/custom_blocks/forging_plate/interactions/displayed_item/create_displayed_item

# -> Advancements
scoreboard players set #or.advancement_requirement_forging_plate OverlyRealistic.General.ArbitraryData 0
execute if items entity 00000001-0000-002b-0000-00010000002b contents *[custom_data~{ForgingPlateItem_RequiresHotBlock:1b}] \
    if block ~ ~ ~ #overly_realistic:forging_plate/is_hot_block run \
        scoreboard players set #or.advancement_requirement_forging_plate OverlyRealistic.General.ArbitraryData 1
execute if items entity 00000001-0000-002b-0000-00010000002b contents *[custom_data~{ForgingPlateItem_RequiresHotBlock:1b}] \
    if block ~ ~-1 ~ #overly_realistic:forging_plate/is_hot_block run \
        scoreboard players set #or.advancement_requirement_forging_plate OverlyRealistic.General.ArbitraryData 1
execute if score #or.advancement_requirement_forging_plate OverlyRealistic.General.ArbitraryData matches 1 \
    on target run \
        advancement grant @s only overly_realistic:advancements/iron_age/forging/getting_hot

scoreboard players set #or.advancement_requirement_forging_plate OverlyRealistic.General.ArbitraryData 0
execute if items entity 00000001-0000-002b-0000-00010000002b contents *[custom_data~{ForgingPlateItem_RequiresCoolBlock:1b}] \
    if block ~ ~ ~ #overly_realistic:forging_plate/is_cool_block run \
        scoreboard players set #or.advancement_requirement_forging_plate OverlyRealistic.General.ArbitraryData 1
execute if score #or.advancement_requirement_forging_plate OverlyRealistic.General.ArbitraryData matches 1 \
    on target run \
        advancement grant @s only overly_realistic:advancements/iron_age/forging/getting_cold


# -> If item requires looping then add data
execute if items entity 00000001-0000-002b-0000-00010000002b contents *[custom_data~{ForgingPlateItem_RequiresLoopingLogic:1b}] run \
    tag @s add OverlyRealistic.Block.ForgingPlate_RequiresLoopingLogic
execute if items entity 00000001-0000-002b-0000-00010000002b contents *[custom_data~{ForgingPlateItem_RequiresHotBlock:1b}] run \
    tag @s add OverlyRealistic.Block.ForgingPlate_RequiresHotBlock
execute if items entity 00000001-0000-002b-0000-00010000002b contents *[custom_data~{ForgingPlateItem_RequiresCoolBlock:1b}] run \
    tag @s add OverlyRealistic.Block.ForgingPlate_RequiresCoolBlock
