
# -> Reset adv trigger
advancement revoke @s only overly_realistic:items/use_wooden_bucket_empty

# -> Add to usage time
scoreboard players add @s OverlyRealistic.Player.UseItem_WoodenBucket 1

# -> If shear time < max then return
execute unless score @s OverlyRealistic.Player.UseItem_WoodenBucket matches 20.. run \
    return fail

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

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

# WATER TYPES:
# 1 = dirty
# 2 = clean
# 3 = sea

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

# -> Raycast
execute anchored eyes \
    positioned ^ ^ ^ \
    anchored feet run \
        function overly_realistic:players/items/wooden_bucket/empty_bucket_use/raycast_travel

# -> If failure then return
execute if score #or.wooden_water_bucket_success OverlyRealistic.General.ArbitraryData matches 0 run \
    return fail

# -> Sound
playsound item.bucket.fill player @a ~ ~ ~ 0.4 1

# -> If item is used from the offhand then set contents
execute if items entity @s weapon.offhand *[custom_data~{or_bucket_specific:"wooden_bucket",or_bucket_contents:"empty"}] run \
    return run \
        function overly_realistic:players/items/wooden_bucket/empty_bucket_use/set_offhand_water_bucket

# --> Set contents

# -> Dirty water
execute if score #or.wooden_bucket_acquire_water_type OverlyRealistic.General.ArbitraryData matches 1 run \
    return run \
        loot replace entity @s weapon.mainhand loot overly_realistic:items/wooden_bucket_dirty_water

# -> Sea water
execute if score #or.wooden_bucket_acquire_water_type OverlyRealistic.General.ArbitraryData matches 3 run \
    return run \
        loot replace entity @s weapon.mainhand loot overly_realistic:items/wooden_bucket_sea_water
