
# --> Interaction checks

# -> If player does not have any items on him then return
execute unless items entity @s weapon.mainhand #overly_realistic:crafting_table_setup_materials run \
    return fail

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

# -> Reset score
scoreboard players set #or.item_success OverlyRealistic.General.ArbitraryData 0

# -> Add material
execute as @n[type=interaction,tag=OverlyRealistic.Block.SetupInteractedWith,tag=OverlyRealistic.Block.CraftingTableSetup,distance=..64] \
    at @s \
    align xyz \
    positioned ~0.5 ~0.5 ~0.5 run \
        function overly_realistic:general/custom_blocks/crafting_table_setup/setup_add_material

# -> Decrease item amount if possible
execute if score #or.item_success OverlyRealistic.General.ArbitraryData matches 1 run \
    item modify entity @s[gamemode=!creative] weapon.mainhand overly_realistic:multipurpose/remove_one_item
