
# -> If player is a ghost then return
execute if entity @s[tag=OverlyRealistic.Player.IsGhost] run \
    return run \
        effect give @s blindness 7 0 true

# -> If player is a level 5 blacksmith then speed up furnaces
execute if score @s OverlyRealistic.Player.WisdomStats.Blacksmithing matches 5 run \
    function overly_realistic:players/wisdom/blacksmithing/actions/detect_furnaces

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

# --> Thirst operations

# -> Increase base thirst timer
scoreboard players add @s OverlyRealistic.Player.ThirstTimer 1

# -> If player is running then increase thirst timer
execute if score @s OverlyRealistic.PredicateValue.IsSprinting matches 1 run \
    scoreboard players add @s OverlyRealistic.Player.ThirstTimer 1

# -> If player is low on stamina then increase thirst timer
execute if score @s OverlyRealistic.Player.Stats.Stamina matches 0..4 run \
    scoreboard players add @s OverlyRealistic.Player.ThirstTimer 1

# -> If player has high body temperature then increase thirst timer
execute if score @s OverlyRealistic.Player.Stats.Temperature matches 78.. run \
    scoreboard players add @s OverlyRealistic.Player.ThirstTimer 2

# -> If player is ill then increase thirst timer
execute if entity @s[tag=OverlyRealistic.Player.IsSick] run \
    scoreboard players add @s OverlyRealistic.Player.ThirstTimer 2

# -> If player is bleeding then increase thirst timer
execute if score @s OverlyRealistic.Player.BleedingTimer matches 1.. run \
    scoreboard players add @s OverlyRealistic.Player.ThirstTimer 1

# -> If player is exposed to the sun then increase thirst timer
execute if score @s OverlyRealistic.PredicateValue.IsExposedToSkyLight matches 1.. \
    unless score #or.WorldTime OverlyRealistic.General.ArbitraryData matches 13000..23460 \
    unless items entity @s armor.head * run \
        scoreboard players add @s OverlyRealistic.Player.ThirstTimer 2

# -> If timer hasnt reached its maximum then return
execute unless score @s OverlyRealistic.Player.ThirstTimer matches 210.. run \
    return fail

# -> Reset timer for new calculation
scoreboard players set @s OverlyRealistic.Player.ThirstTimer 1

# ----> Decrease thirst

# -> If player is running then increase new value
execute if score @s OverlyRealistic.PredicateValue.IsSprinting matches 1 run \
    scoreboard players add @s OverlyRealistic.Player.ThirstTimer 2

# -> If player is low on stamina then increase new value
execute if score @s OverlyRealistic.Player.Stats.Stamina matches 0..5 run \
    scoreboard players add @s OverlyRealistic.Player.ThirstTimer 1

# -> If player has high body temperature then increase new value
execute if score @s OverlyRealistic.Player.Stats.Temperature matches 70.. run \
    scoreboard players add @s OverlyRealistic.Player.ThirstTimer 3

# -> If player is ill then increase new value
execute if entity @s[tag=OverlyRealistic.Player.IsSick] run \
    scoreboard players add @s OverlyRealistic.Player.ThirstTimer 2

# -> If player is bleeding then increase new value
execute if score @s OverlyRealistic.Player.BleedingTimer matches 1.. run \
    scoreboard players add @s OverlyRealistic.Player.ThirstTimer 1

# -> If player is exposed to the sun then increase new value
execute if score @s OverlyRealistic.PredicateValue.IsExposedToSkyLight matches 1.. \
    unless score #or.WorldTime OverlyRealistic.General.ArbitraryData matches 13000..23460 run \
        scoreboard players add @s OverlyRealistic.Player.ThirstTimer 1

# -> If player is in a hot biome then increase new value
execute if biome ~ ~ ~ #overly_realistic:temperature_modifying/hot_biome run \
    scoreboard players add @s OverlyRealistic.Player.ThirstTimer 2

# -> Decrease thirst
scoreboard players operation @s OverlyRealistic.Player.Stats.Thirst -= @s OverlyRealistic.Player.ThirstTimer

# -> Function tag
function #overly_realistic:mechanics/player_thirst_value_operate

# -> Clamp
execute if score @s OverlyRealistic.Player.Stats.Thirst matches ..-1 run \
    scoreboard players set @s OverlyRealistic.Player.Stats.Thirst 0

# -> Reset timer
scoreboard players set @s OverlyRealistic.Player.ThirstTimer 0