
# -> Rotate fire starter
execute on passengers \
    as @s[tag=OverlyRealistic.Block.FireStarter_Part_0] \
    at @s run \
        rotate @s ~35 ~

# -> Value-dependent operations
execute if score @s OverlyRealistic.General.ArbitraryData matches 25.. run \
    function overly_realistic:general/custom_blocks/fire_starter/fire_starer_value_dependent/operation_0
execute if score @s OverlyRealistic.General.ArbitraryData matches 45.. run \
    function overly_realistic:general/custom_blocks/fire_starter/fire_starer_value_dependent/operation_1
execute if score @s OverlyRealistic.General.ArbitraryData matches 65.. run \
    function overly_realistic:general/custom_blocks/fire_starter/fire_starer_value_dependent/operation_2
execute if score @s OverlyRealistic.General.ArbitraryData matches 80.. run \
    function overly_realistic:general/custom_blocks/fire_starter/fire_starer_value_dependent/operation_3
execute if score @s OverlyRealistic.General.ArbitraryData matches 90.. run \
    function overly_realistic:general/custom_blocks/fire_starter/fire_starer_value_dependent/operation_4

# -> Add to fire starter value
scoreboard players add @s OverlyRealistic.General.ArbitraryData 2
#scoreboard players add @s[predicate=overly_realistic:items/fire_starter/fire_starter_extra_increase_chance] OverlyRealistic.General.ArbitraryData 1

# -> If player has vines/string/bows in their mainhand then add additional value to fire starter value
scoreboard players set #or.is_using_fire_drill_aid OverlyRealistic.General.ArbitraryData 0
execute on target \
    if items entity @s weapon.mainhand #overly_realistic:used_for_fire_drill run \
        scoreboard players set #or.is_using_fire_drill_aid OverlyRealistic.General.ArbitraryData 1
execute if score #or.is_using_fire_drill_aid OverlyRealistic.General.ArbitraryData matches 1 run \
    scoreboard players add @s OverlyRealistic.General.ArbitraryData 2

# -> Schedule value decrease loop
schedule function overly_realistic:general/custom_blocks/fire_starter/fire_starter_temp_loop 1t append

# -> Clamp value
scoreboard players set @s[scores={OverlyRealistic.General.ArbitraryData=101..}] OverlyRealistic.General.ArbitraryData 100

# -> Store value globally for the player
scoreboard players operation #or.fire_starter_value OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.General.ArbitraryData

# -> Show player the fire starter value
execute on target run \
    function overly_realistic:general/custom_blocks/fire_starter/fire_starter_player_interaction_operate

# -> If value is less than max then return
execute unless score @s OverlyRealistic.General.ArbitraryData matches 100.. run \
    return fail

# -> Reset player's fire starter time
execute on target run \
    scoreboard players set @s OverlyRealistic.World.FireStarterFireTime 0

# -> Set campfire
function overly_realistic:general/campfires/campfire_marker_create

# -> Particles
particle lava ~ ~ ~ 0.1 0.1 0.1 0.01 5 normal @a

# -> Set fire time
execute align xyz \
    positioned ~0.5 ~0.5 ~0.5 run \
        scoreboard players set @n[type=marker,tag=OverlyRealistic.CampfireBlock,distance=..0.1] OverlyRealistic.World.CampfireFireTime 20

# -> Advancement
execute on target run \
    advancement grant @s only overly_realistic:advancements/stone_age/let_there_be_light

# -> On RNG, break fire starter
execute if predicate overly_realistic:items/fire_starter/fire_starter_break_chance run \
    return run \
        function overly_realistic:general/custom_blocks/fire_starter/fire_starter_break_from_lit_fire

# -> Else, drop fire starter
function overly_realistic:general/custom_blocks/fire_starter/fire_starter_broken_by_player
