
# -> DEBUG (@NOTE: COMMENT OUT)
#data modify storage overly_realistic:player_general dead_player_data set from entity @s

# -> Get mainhand item
item replace entity 00000001-0000-002b-0000-00010000002b contents from entity @s weapon.mainhand

# -> Get player rotation
rotate 00000001-0000-002a-0000-00010000002a ~-180 ~

# -> Get player name
loot replace block -29999985 2 -29999985 container.0 loot overly_realistic:internal/get_player_head

# -> Get if current block is air
scoreboard players set #or.corpse_spawn_current_block_is_air OverlyRealistic.General.ArbitraryData 0
execute if block ~ ~ ~ #air run \
    scoreboard players set #or.corpse_spawn_current_block_is_air OverlyRealistic.General.ArbitraryData 1
execute if score #or.corpse_spawn_current_block_is_air OverlyRealistic.General.ArbitraryData matches 0 \
    if block ~ ~1 ~ #air run \
        scoreboard players set #or.corpse_spawn_current_block_is_air OverlyRealistic.General.ArbitraryData 2
execute if score #or.corpse_spawn_current_block_is_air OverlyRealistic.General.ArbitraryData matches 0 \
    if block ~ ~2 ~ #air \
    unless block ~ ~1 ~ #air run \
        scoreboard players set #or.corpse_spawn_current_block_is_air OverlyRealistic.General.ArbitraryData 3

# -> Create corpse entities
execute if score #or.corpse_spawn_current_block_is_air OverlyRealistic.General.ArbitraryData matches 0..1 run \
    summon mannequin ~ ~ ~ {Tags:["OverlyRealistic.Player.IsPlayerCorpse","OverlyRealistic.Entity.PlayerCorpseTemp","OverlyRealistic.Entity.IsPlayerCorpseEntity"],Invulnerable:1b,pose:"sleeping",Passengers:[{id:"interaction",Tags:["OverlyRealistic.Entity.PlayerCorpse_InteractionTop","OverlyRealistic.Entity.PlayerCorpseInteraction","OverlyRealistic.Entity.IsPlayerCorpseEntity"],width:1.0f,height:0.2f,response:1b},{id:"interaction",Tags:["OverlyRealistic.Entity.PlayerCorpse_InteractionBottom","OverlyRealistic.Entity.PlayerCorpseInteraction","OverlyRealistic.Entity.IsPlayerCorpseEntity"],width:1.0f,height:-0.2f,response:1b}]}
execute if score #or.corpse_spawn_current_block_is_air OverlyRealistic.General.ArbitraryData matches 2 run \
    summon mannequin ~ ~1 ~ {Tags:["OverlyRealistic.Player.IsPlayerCorpse","OverlyRealistic.Entity.PlayerCorpseTemp","OverlyRealistic.Entity.IsPlayerCorpseEntity"],Invulnerable:1b,pose:"sleeping",Passengers:[{id:"interaction",Tags:["OverlyRealistic.Entity.PlayerCorpse_InteractionTop","OverlyRealistic.Entity.PlayerCorpseInteraction","OverlyRealistic.Entity.IsPlayerCorpseEntity"],width:1.0f,height:0.2f,response:1b},{id:"interaction",Tags:["OverlyRealistic.Entity.PlayerCorpse_InteractionBottom","OverlyRealistic.Entity.PlayerCorpseInteraction","OverlyRealistic.Entity.IsPlayerCorpseEntity"],width:1.0f,height:-0.2f,response:1b}]}
execute if score #or.corpse_spawn_current_block_is_air OverlyRealistic.General.ArbitraryData matches 3 run \
    summon mannequin ~ ~2 ~ {Tags:["OverlyRealistic.Player.IsPlayerCorpse","OverlyRealistic.Entity.PlayerCorpseTemp","OverlyRealistic.Entity.IsPlayerCorpseEntity"],Invulnerable:1b,pose:"sleeping",Passengers:[{id:"interaction",Tags:["OverlyRealistic.Entity.PlayerCorpse_InteractionTop","OverlyRealistic.Entity.PlayerCorpseInteraction","OverlyRealistic.Entity.IsPlayerCorpseEntity"],width:1.0f,height:0.2f,response:1b},{id:"interaction",Tags:["OverlyRealistic.Entity.PlayerCorpse_InteractionBottom","OverlyRealistic.Entity.PlayerCorpseInteraction","OverlyRealistic.Entity.IsPlayerCorpseEntity"],width:1.0f,height:-0.2f,response:1b}]}

# -> Edit corpse entities
execute as @n[type=mannequin,tag=OverlyRealistic.Entity.PlayerCorpseTemp,dx=0,dy=2,dz=0] at @s run \
    function overly_realistic:general/downing/player_corpse/create_corpse/player_corpse_edit_mannequin
