
# -> Check if wood items are in the player's offhand
execute if items entity @s weapon.mainhand #overly_realistic:tanning_rack_wood_interactions run \
    return run \
        function overly_realistic:general/custom_blocks/tanning_rack/interact_with_tanning_rack_with_wood

# -> If player has hide then set value
scoreboard players set #or.global OverlyRealistic.General.ArbitraryData 0
execute if items entity @s weapon.* rabbit_hide run \
    scoreboard players set #or.global OverlyRealistic.General.ArbitraryData 1

# -> Check if hide is in the player's offhand
execute if items entity @s weapon.offhand rabbit_hide \
    unless items entity @s weapon.mainhand rabbit_hide run \
        scoreboard players set #or.global OverlyRealistic.General.ArbitraryData 2

# -> Tag player
tag @s add OverlyRealistic.Player.TempPlayer

# -> Operate on interacted-with racks
execute as @n[type=interaction,tag=OverlyRealistic.Block.TanningRack,distance=..64,nbt={interaction:{}}] at @s \
    align xyz \
    positioned ~0.5 ~0.5 ~0.5 run \
        function overly_realistic:general/custom_blocks/tanning_rack/tanning_rack_operate_interacted

# -> Untag player
tag @s remove OverlyRealistic.Player.TempPlayer

# -> If ArbitraryValue != 3 then return
execute unless score #or.global OverlyRealistic.General.ArbitraryData matches 3 run \
    return fail

# -> Grant advancement
advancement grant @s only overly_realistic:advancements/stone_age/hide_tanning

# -> If player is in creative then return
execute if entity @s[gamemode=creative] run \
    return fail

# -> Remove hide item
execute if items entity @s weapon.offhand rabbit_hide \
    unless items entity @s weapon.mainhand rabbit_hide run \
        return run \
            item modify entity @s weapon.offhand overly_realistic:multipurpose/remove_one_item
item modify entity @s weapon.mainhand overly_realistic:multipurpose/remove_one_item
