
# -> Sound
playsound block.stone.hit block @a ~ ~ ~ 0.85 1.3

# -> Add onto pestle usage
scoreboard players add @s OverlyRealistic.World.PestleUsage 2

# -> If player is using a bone then add extra usage
#execute if items entity 00000001-0000-002b-0000-00010000002b contents bone run \
    scoreboard players add @s OverlyRealistic.World.PestleUsage 2

# -> Set percentage globally
scoreboard players operation #or.pestle_usage_percent OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.World.PestleUsage

# -> Show player the percentage
execute on target run \
    function overly_realistic:general/custom_blocks/mortar/interactions/int_pestle_use_from_player

# -> If pestle usage < max then return
execute unless score @s OverlyRealistic.World.PestleUsage matches 100.. run \
    return fail

# -> Cache items data into storage
data modify storage overly_realistic:temp_values temp_mortar_items set from entity @s data.MortarItems

# -> Reset progress
scoreboard players reset @s OverlyRealistic.World.PestleUsage

# --> Check recipes

# -> Wood scraps
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:poisonous_potato",components:{"minecraft:custom_data":{or_is_bark:1b}}},\
            {id:"minecraft:poisonous_potato",components:{"minecraft:custom_data":{or_is_bark:1b}}},\
            {id:"minecraft:poisonous_potato",components:{"minecraft:custom_data":{or_is_bark:1b}}},\
            {id:"minecraft:poisonous_potato",components:{"minecraft:custom_data":{or_is_bark:1b}}}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_wood_scraps

# -> Wheat flour
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:wheat"},\
            {id:"minecraft:wheat"},\
            {id:"minecraft:wheat"},\
            {id:"minecraft:wheat"}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_wheat_flour

# -> Redstone dust
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:poisonous_potato",components:{"minecraft:custom_data":{or_is_redstone_gem:1b}}},\
            {id:"minecraft:poisonous_potato",components:{"minecraft:custom_data":{or_is_redstone_gem:1b}}},\
            {id:"minecraft:poisonous_potato",components:{"minecraft:custom_data":{or_is_redstone_gem:1b}}},\
            {id:"minecraft:poisonous_potato",components:{"minecraft:custom_data":{or_is_redstone_gem:1b}}}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_redstone_dust

# -> Bone meal
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:bone"},{id:"minecraft:bone"},{id:"minecraft:bone"},{id:"minecraft:bone"}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_bone_meal

# -> Gunpowder
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:charcoal"},{id:"minecraft:redstone"},{id:"minecraft:raw_copper"},{id:"minecraft:poisonous_potato",components:{"minecraft:custom_data":{or_is_sulfur:1b}}}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_gunpowder

# -> Ore fragments from poor quality raw ores
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {components:{"minecraft:custom_data":{or_raw_ore_alternative_item_with_quality:1b}}},\
            {components:{"minecraft:custom_data":{or_raw_ore_alternative_item_with_quality:1b}}},\
            {components:{"minecraft:custom_data":{or_raw_ore_alternative_item_with_quality:1b}}},\
            {components:{"minecraft:custom_data":{or_raw_ore_alternative_item_with_quality:1b}}}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_ore_fragment_poor_qual

# -> Copper fragments
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:raw_copper"},{id:"minecraft:raw_copper"},{id:"minecraft:raw_copper"},{id:"minecraft:raw_copper"}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_copper_fragments

# -> Iron fragments
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:raw_iron"},{id:"minecraft:raw_iron"},{id:"minecraft:raw_iron"},{id:"minecraft:raw_iron"}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_iron_fragments

# -> Gold fragments
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:raw_gold"},{id:"minecraft:raw_gold"},{id:"minecraft:raw_gold"},{id:"minecraft:raw_gold"}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_gold_fragments

# -> Flint
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:gravel"},{id:"minecraft:gravel"},{id:"minecraft:gravel"},{id:"minecraft:gravel"}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_flint

# -> Sugar
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:sugar_cane"},{id:"minecraft:sugar_cane"},{id:"minecraft:sugar_cane"},{id:"minecraft:sugar_cane"}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_sugar

# -> Fish scraps
scoreboard players set #or.fish_amount_mortar OverlyRealistic.General.ArbitraryData 0
execute on passengers \
    if items entity @s contents #fishes run \
        scoreboard players add #or.fish_amount_mortar OverlyRealistic.General.ArbitraryData 1
execute if score #or.fish_amount_mortar OverlyRealistic.General.ArbitraryData matches 4.. run \
    function overly_realistic:general/custom_blocks/mortar/interactions/misc_specific_crafting/int_use_pestle_fish_scraps

# -> Red dye from sweet berries
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:sweet_berries"},{id:"minecraft:sweet_berries"},{id:"minecraft:sweet_berries"},{id:"minecraft:sweet_berries"}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_red_dye

# -> Black dye from charcoal
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:charcoal"},{id:"minecraft:charcoal"},{id:"minecraft:charcoal"},{id:"minecraft:charcoal"}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_black_dye_from_charcoal

# -> Black dye from coal
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:coal"},{id:"minecraft:coal"},{id:"minecraft:coal"},{id:"minecraft:coal"}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_black_dye_from_coal

# -> White dye
execute if data storage overly_realistic:temp_values \
    {temp_mortar_items:\
        [\
            {id:"minecraft:poisonous_potato",components:{"minecraft:item_name":{"translate":"item.minecraft.bone_meal"}}},\
            {id:"minecraft:poisonous_potato",components:{"minecraft:item_name":{"translate":"item.minecraft.bone_meal"}}},\
            {id:"minecraft:poisonous_potato",components:{"minecraft:item_name":{"translate":"item.minecraft.bone_meal"}}},\
            {id:"minecraft:poisonous_potato",components:{"minecraft:item_name":{"translate":"item.minecraft.bone_meal"}}}\
        ]\
    } run \
        return run \
            function overly_realistic:general/custom_blocks/mortar/interactions/pestle_interactions/create_white_dye

# -> Dyes
execute on passengers \
    unless items entity @s contents #overly_realistic:mortar_dye_ingredients run \
        return fail
execute on passengers \
    if items entity @s contents #overly_realistic:mortar_dye_ingredients run \
        function overly_realistic:general/custom_blocks/mortar/interactions/dye_crafting/int_use_pestle_dye
function overly_realistic:general/custom_blocks/mortar/interactions/int_remove_all_items
