
# -> Reset adv trigger
advancement revoke @s only overly_realistic:player/player_get_hurt_direct

# -> Particles
particle minecraft:block{block_state:"minecraft:redstone_block"} ~ ~ ~ 0 0.8 0 0.001 10 normal @a

# -> Bleeding RNG
execute if predicate overly_realistic:player/damage/direct_damage_bleeding_rng_small run \
    function overly_realistic:players/bleeding/start_bleeding

# -> Mental health decrease RNG
execute unless score @s OverlyRealistic.Player.WisdomStats.Combat matches 1.. \
    if predicate overly_realistic:player/damage/potent_direct_damage_rng run \
        function overly_realistic:players/mental_health/decrease_mental_health_by_1

# -> If player is on ground then create blood splatter
execute if score @s OverlyRealistic.PredicateValue.IsOnGround matches 1 \
    if score #or.setting.generate_blood_splatters OverlyRealistic.Settings.ArbitrarySetting matches 1 \
    unless block ~ ~-0.1 ~ #overly_realistic:ground_markings_cant_generate_on run \
        function overly_realistic:players/misc/ground_markings/blood/create_blood_splatter

# -> If player is wearing metal armor then play sound
execute if items entity @s armor.* #overly_realistic:non_leather_armor run \
    playsound minecraft:item.mace.smash_ground player @a ~ ~ ~ 0.3 2

# -> Get if attacker was using a tool
scoreboard players set #or.was_attacker_using_tool OverlyRealistic.General.ArbitraryData 0
execute on attacker \
    if items entity @s weapon.mainhand #overly_realistic:armor_damage_sound_tools run \
        scoreboard players set #or.was_attacker_using_tool OverlyRealistic.General.ArbitraryData 1

# -> If player is wearing metal armor then play sounds
execute if items entity @s armor.* #overly_realistic:non_leather_armor run \
    playsound minecraft:item.mace.smash_ground player @a ~ ~ ~ 0.3 2

# -> If player is wearing metal armor and the attacker was using a metal tool then play extra sound
execute if items entity @s armor.* #overly_realistic:iron_armor \
    if score #or.was_attacker_using_tool OverlyRealistic.General.ArbitraryData matches 1 run \
        playsound minecraft:entity.zombie.attack_iron_door player @a ~ ~ ~ 1 2

# -> Breaking bone sound
execute if predicate overly_realistic:player/damage/breaking_bone_sound_rng run \
    playsound minecraft:entity.player.big_fall player @a ~ ~ ~ 0.85 0

# ---> Body damage

# -> If setting is disabled then return
execute if score #or.setting.body_part_damage OverlyRealistic.Settings.ArbitrarySetting matches 0 run \
    return fail

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

# -> If attacker was the same player then return
execute on attacker \
    if entity @s[tag=OverlyRealistic.Player.TempPlayerHurt] run \
        return run \
            tag @s remove OverlyRealistic.Player.TempPlayerHurt

# -> Create a marker on the head
execute anchored eyes \
    positioned ^ ^ ^ \
    anchored feet run \
        summon marker ~ ~ ~ {Tags:["OverlyRealistic.Player.BodyMarker","OverlyRealistic.Player.BodyPartHead"]}

# -> Get scale
execute store result score #or.player_scale OverlyRealistic.General.ArbitraryData run \
    attribute @s scale get 100

# -> Create a marker on the torso and legs, then continue operations
execute if score #or.player_scale OverlyRealistic.General.ArbitraryData matches ..60 run \
    return run \
        function overly_realistic:players/body_damage/torso_legs_markers/create_markers_0
execute if score #or.player_scale OverlyRealistic.General.ArbitraryData matches 61..90 run \
    return run \
        function overly_realistic:players/body_damage/torso_legs_markers/create_markers_1
execute if score #or.player_scale OverlyRealistic.General.ArbitraryData matches 91..130 run \
    return run \
        function overly_realistic:players/body_damage/torso_legs_markers/create_markers_2
execute if score #or.player_scale OverlyRealistic.General.ArbitraryData matches 140.. run \
    function overly_realistic:players/body_damage/torso_legs_markers/create_markers_3

# -> Remove nearby body markers
kill @e[type=marker,tag=OverlyRealistic.Player.BodyMarker,distance=..8]

# -> Remove temp tag
tag @s remove OverlyRealistic.Player.TempPlayerHurt