
# -> Temp tag
tag @s add OverlyRealistic.Player.TempPlayer

# -> Globalize death ID
scoreboard players operation #or.current_death_id OverlyRealistic.Player.DeathID = @s OverlyRealistic.Player.DeathID

# -> Remove downed player parent ent
execute as @e[type=armor_stand,tag=OverlyRealistic.Entity.IsDowningEntity] \
    if score @s OverlyRealistic.Player.DeathID = #or.current_death_id OverlyRealistic.Player.DeathID \
    at @s run \
        function overly_realistic:general/downing/downing_parent_ent_remove

# -> Remove attributes
#attribute @s movement_speed modifier remove overly_realistic:downed_player_movement_speed
#attribute @s jump_strength modifier remove overly_realistic:downed_player_jump_strength
#attribute @s gravity base reset

# -> Remove tag
tag @s remove OverlyRealistic.Player.TempPlayer

# -> If the 'Restorable Deaths' setting is enabled then store player data
execute if score #or.setting.restorable_deaths OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
    function overly_realistic:main/debug/death_inventories/data_store

# -> If the 'Restorable Deaths' setting is enabled then return and operate accordingly
execute if score #or.setting.restorable_deaths OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
    return run \
        function overly_realistic:main/debug/death_inventories/player_die_final_death

# -> Cache player data
data modify storage overly_realistic:player_general dead_player_data set from entity @s

# -> Drop inventory
execute if score #or.setting.player_corpses OverlyRealistic.Settings.ArbitrarySetting matches 0 run \
    function overly_realistic:general/downing/death_item_drop/item_drop_start

# -> Create corpse
execute if score #or.setting.player_corpses OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
    function overly_realistic:general/downing/player_corpse/create_corpse/player_create_corpse

# -> Set spawn
spawnpoint @s ~ ~ ~

# -> Kill player
scoreboard players set @s OverlyRealistic.Player.HasDiedPostDowning 1
kill @s
