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

# -> Set spawn, if settings allow it
execute unless score #or.setting.do_normal_respawning OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
    spawnpoint @s ~ ~ ~

# -> Reset var
scoreboard players set @s OverlyRealistic.Player.Deaths 0

# -> Debug MSG
#tellraw @a {entity:"@s",nbt:"attributes"}

# -> Save attribute data
item replace entity 00000001-0000-002b-0000-00010000002b contents from entity @s armor.body
data modify entity 00000001-0000-002b-0000-00010000002b item.components.minecraft:custom_data.attribute_modifiers_on_death set from entity @s attributes
item replace entity @s armor.body from entity 00000001-0000-002b-0000-00010000002b contents

# -> If player hasnt been downed before, and if settings allow it, then down them
execute unless entity @s[tag=OverlyRealistic.Player.HasBeenDownedBefore] \
    unless score #or.setting.do_normal_respawning OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
        return run \
            function overly_realistic:general/downing/downing_start

# -> Decrease nearby players' mental health
execute as @a[distance=..16] run \
    function overly_realistic:players/mental_health/edit_mental_health {type:"remove",value:35}

# -> Decrease attacker's mental health
execute on attacker run \
    function overly_realistic:players/mental_health/edit_mental_health {type:"remove",value:5}

# -> Set ghost, if settings allow it
execute unless score #or.setting.do_normal_respawning OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
    function overly_realistic:players/custom_data/spawn_as_ghost
