
# -> Reset ShouldReturn
scoreboard players set #or.campfire_operation_should_return OverlyRealistic.General.ArbitraryData 0

# -> If current block is not a campfire then operate
execute unless block ~ ~ ~ #campfires[lit=true,signal_fire=true] run \
    return run \
        function overly_realistic:general/campfires/campfire_marker_remove

# -> If ShouldReturn = 1 then return
execute if score #or.campfire_operation_should_return OverlyRealistic.General.ArbitraryData matches 1 run \
    return fail

# -> If there are flammable items above the campfire then add to fire
execute align xyz \
    as @n[type=item,dx=0,dy=0,dz=0] \
    if items entity @s contents #overly_realistic:adds_to_campfires_all run \
        function overly_realistic:general/campfires/fuel_add_to_campfire

# -> If it is raining and the campfire is exposed then extinguish
#execute if score @s OverlyRealistic.World.CampfireFireTime matches 1.. \
    if predicate overly_realistic:world/weather/is_raining_thundering \
    if predicate overly_realistic:player/temperature/is_outside run \
        function overly_realistic:general/campfires/campfire_extinguish

# -> If there is no fire time left then set lit to false
execute if score @s OverlyRealistic.World.CampfireFireTime matches ..0 run \
    return run \
        function overly_realistic:general/campfires/campfire_extinguish

# -> Add to PlayerNearbyTime
scoreboard players add @s OverlyRealistic.World.PlayerNearbyTime 1

# -> If PlayerNearbyTime >= max then affect players
execute if score @s OverlyRealistic.World.PlayerNearbyTime matches 4.. run \
    function overly_realistic:general/campfires/campfire_affect_near_players

# -> Particles
particle minecraft:campfire_signal_smoke ~ ~ ~ 0 1 0 0.1 0 force @a
particle minecraft:campfire_signal_smoke ~ ~ ~ 0 1 0 0.1 0 force @a

# -> Extended particles
execute if score @s OverlyRealistic.World.CampfireFireTime matches 500.. run \
    particle minecraft:campfire_signal_smoke ~ ~1 ~ 0 3 0 0.1 0 force @a
execute if score @s OverlyRealistic.World.CampfireFireTime matches 1500.. run \
    particle minecraft:campfire_signal_smoke ~ ~1 ~ 0 4 0 0.1 0 force @a
execute if score @s OverlyRealistic.World.CampfireFireTime matches 3000.. run \
    particle minecraft:campfire_signal_smoke ~ ~1 ~ 0 5 0 0.1 0 force @a

# -> Low lifetime particles
execute if score @s OverlyRealistic.World.CampfireFireTime matches ..100 run \
    particle large_smoke ~ ~0 ~ 0 0 0 0.01 2 normal @a

# -> High lifetime particles
execute if score @s OverlyRealistic.World.CampfireFireTime matches 600.. run \
    particle small_flame ~ ~ ~ 0.2 0.1 0.2 0.01 2 normal @a

# -> Progress fire time
scoreboard players remove @s OverlyRealistic.World.CampfireFireTime 1

# -> Progress flammable check time
scoreboard players add @s OverlyRealistic.World.CampfireFlammableTime 1

# -> Run fire RNG
execute unless score @s OverlyRealistic.World.CampfireFlammableTime matches 100.. run \
    return fail

# -> Reset flammable check
scoreboard players set @s OverlyRealistic.World.CampfireFlammableTime 0

# -> Check for flammable blocks around
execute positioned ~ ~ ~1 run \
    function overly_realistic:general/torches/torch_burn_attempt
execute positioned ~1 ~ ~ run \
    function overly_realistic:general/torches/torch_burn_attempt
execute positioned ~ ~ ~-1 run \
    function overly_realistic:general/torches/torch_burn_attempt
execute positioned ~-1 ~ ~ run \
    function overly_realistic:general/torches/torch_burn_attempt
