
# -> If mortar is full then return
execute if score @s OverlyRealistic.World.BlockItemAmount matches 4.. run \
    return fail

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

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

# -> Add and store new item amount
scoreboard players add @s OverlyRealistic.World.BlockItemAmount 1

# -> Tag mortar
tag @s add OverlyRealistic.Block.Mortar_Status_Filled
tag @s remove OverlyRealistic.Block.Mortar_Status_Empty

# --> Add item

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

# -> Create new item depending on item amount
execute if score @s OverlyRealistic.World.BlockItemAmount matches 1 run \
    function overly_realistic:general/custom_blocks/mortar/interactions/create_displayed_item/item_1
execute if score @s OverlyRealistic.World.BlockItemAmount matches 2 run \
    function overly_realistic:general/custom_blocks/mortar/interactions/create_displayed_item/item_2
execute if score @s OverlyRealistic.World.BlockItemAmount matches 3 run \
    function overly_realistic:general/custom_blocks/mortar/interactions/create_displayed_item/item_3
execute if score @s OverlyRealistic.World.BlockItemAmount matches 4 run \
    function overly_realistic:general/custom_blocks/mortar/interactions/create_displayed_item/item_4

# -> Attach to display
ride @n[type=item_display,tag=OverlyRealistic.Block.BlockItemNotAttached,distance=..1] mount @s

# -> Set data for item
execute on passengers \
    if entity @s[type=item_display,tag=OverlyRealistic.Block.BlockItemNotAttached] run \
        function overly_realistic:general/custom_blocks/mortar/interactions/int_add_item_general_item_data

# -> Append new item data
data modify entity @s data.MortarItems append from entity 00000001-0000-002b-0000-00010000002b item
