
# -> Attach new display
execute align xyz run \
    summon minecraft:item_display ~0.5 ~0.5 ~0.5 {Tags:["OverlyRealistic.TempEnt_HandleComponent_ProperTool","OverlyRealistic.Block.ToolHandle_ProperTool"], transformation: {left_rotation: [-0.6532815f, -0.2705981f, -0.2705981f, 0.6532815f], right_rotation: [0.0f, 0.0f, 0.0f, 1.0f], scale: [0.9409168f, 0.94091624f, 0.94091547f], translation: [0.047045812f, -0.17f, -0.05f]}}
execute align xyz run \
    ride @n[type=item_display,tag=OverlyRealistic.TempEnt_HandleComponent_ProperTool,dx=0,dy=0,dz=0] mount @s
execute on passengers run \
    tag @s remove OverlyRealistic.TempEnt_HandleComponent_ProperTool

# -> Rotate new display
execute on passengers \
    if entity @s[tag=OverlyRealistic.Block.ToolHandle_ProperTool] \
    store result entity @s Rotation[0] float 1 \
    on vehicle run \
        data get entity @s data.display_rotation

# -> Get crafted item result
execute on passengers \
    if entity @s[tag=OverlyRealistic.Block.ToolHandle_ToolHead] run \
        data modify storage overly_realistic:items current_item_craft_result set from entity @s item.components."minecraft:custom_data".tool_craftable

# -> Get crafted item material
execute on passengers \
    if entity @s[tag=OverlyRealistic.Block.ToolHandle_ToolHead] run \
        data modify storage overly_realistic:items current_item_craft_material set from entity @s item.components."minecraft:custom_data".ToolPartMaterial

# -> Set display item
execute on passengers \
    if entity @s[tag=OverlyRealistic.Block.ToolHandle_ProperTool] run \
        function overly_realistic:general/custom_blocks/tool_handle/interaction_events/progress_3/set_item with storage overly_realistic:items

# -> Remove unneeded displays
execute on passengers \
    if entity @s[tag=!OverlyRealistic.Block.ToolHandle_ProperTool] run \
        kill @s

# -> Add data to item
execute on passengers run \
    function overly_realistic:general/items/edit_item_general_from_display

# -> Sound
playsound entity.item.pickup block @a ~ ~ ~ 0.5 2
playsound minecraft:block.spawner.place block @a ~ ~ ~ 0.6 2
playsound minecraft:block.spawner.break block @a ~ ~ ~ 0.3 2

# -> Set completion
tag @s add OverlyRealistic.Block.ToolHandle_IsComplete

# -> Add baseline for max durability based on material
execute if data storage overly_realistic:items {current_item_craft_material:"copper"} run \
    scoreboard players add @s OverlyRealistic.World.ToolHandleModifier_MaxDurability 190
execute if data storage overly_realistic:items {current_item_craft_material:"iron"} run \
    scoreboard players add @s OverlyRealistic.World.ToolHandleModifier_MaxDurability 250
execute if data storage overly_realistic:items {current_item_craft_material:"stone"} run \
    scoreboard players add @s OverlyRealistic.World.ToolHandleModifier_MaxDurability 131

# -> Get player's wisdom stats for max durability increase
execute on target run \
    function overly_realistic:general/custom_blocks/tool_handle/interaction_events/progress_3/get_player_wisdom_stats

# -> Add durability depending on player's wisdom stats
scoreboard players operation @s OverlyRealistic.World.ToolHandleModifier_MaxDurability += #or.wisdom_stat_max_dura_buff OverlyRealistic.General.ArbitraryData

# -> Get max durability
execute store result storage overly_realistic:items crafted_tool_modifier_max_durability int 1 run \
    scoreboard players get @s OverlyRealistic.World.ToolHandleModifier_MaxDurability

# -> Set max durability of tool
execute on passengers run \
    function overly_realistic:general/custom_blocks/tool_handle/interaction_events/progress_3/add_modifier_max_durability with storage overly_realistic:items

# -> Globalize type values
scoreboard players operation #or.tool_handle_property_handle_type OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.World.ToolHandle_ToolProperty_HandleType
scoreboard players operation #or.tool_handle_property_cordage_type OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.World.ToolHandle_ToolProperty_CordageType
scoreboard players operation #or.tool_handle_property_adhesive_type OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.World.ToolHandle_ToolProperty_AdhesiveType

# -> Set texture data
execute on passengers run \
    function overly_realistic:general/custom_blocks/tool_handle/interaction_events/progress_3/set_texture_data
