
# -> Reset shear time
scoreboard players reset @s OverlyRealistic.Player.UseItem_Shears

# -> Reset vars
scoreboard players set #or.Raycast.RayRange OverlyRealistic.General.ArbitraryData 0
scoreboard players set #or.player_sheared_block OverlyRealistic.General.ArbitraryData 0

# -> Get player block interaction range
execute store result score #or.Raycast.RayRangeMax OverlyRealistic.General.ArbitraryData run \
    attribute @s block_interaction_range get 5

# -> Raycast
execute anchored eyes positioned ^ ^ ^ anchored feet run \
    function overly_realistic:players/items/shears/non_entity_interactions/shears_raycast_travel

# -> Sound
playsound item.shears.snip player @a ~ ~ ~ 0.5 1

# -> If shearing was not successful then return
execute unless score #or.player_sheared_block OverlyRealistic.General.ArbitraryData matches 1 run \
    return fail

# -> Damage shears (offhand)
execute unless items entity @s weapon.mainhand *[custom_data~{IsShears:1b}] \
    if items entity @s weapon.offhand *[custom_data~{IsShears:1b}] run \
        return run \
            function overly_realistic:players/items/shears/damage_shears_from_offhand

# -> Damage shears (mainhand)
item replace entity 00000001-0000-002b-0000-00010000002b contents from entity @s weapon.mainhand
scoreboard players set #or.shears_damage_from_shearing OverlyRealistic.General.ArbitraryData 0
execute store result score #or.shears_damage_from_shearing OverlyRealistic.General.ArbitraryData run \
    data get entity 00000001-0000-002b-0000-00010000002b item.components."minecraft:damage"
execute if score #or.shears_damage_from_shearing OverlyRealistic.General.ArbitraryData matches 238.. run \
    return run \
        item replace entity @s weapon.mainhand with air
execute if score #or.player_using_iron_shears OverlyRealistic.General.ArbitraryData matches 0 \
    if score #or.shears_damage_from_shearing OverlyRealistic.General.ArbitraryData matches 138.. run \
        return run \
            item replace entity @s weapon.mainhand with air
scoreboard players add #or.shears_damage_from_shearing OverlyRealistic.General.ArbitraryData 1
execute store result entity 00000001-0000-002b-0000-00010000002b item.components."minecraft:damage" int 1 run \
    scoreboard players get #or.shears_damage_from_shearing OverlyRealistic.General.ArbitraryData
item replace entity @s weapon.mainhand from entity 00000001-0000-002b-0000-00010000002b contents
