
function snapgrave:get/pid
function snapgrave:get/name
function snapgrave:get/day/is_dead/init

execute if score #immediate_respawn sgrave.rulesCheck matches 0 run function snapgrave:grave_count/run with storage sgrave:temp

scoreboard players add #grave.id sgrave 1
execute store result storage sgrave:temp gid int 1 run scoreboard players get #grave.id sgrave

function snapgrave:summon/grave with storage sgrave:temp
function snapgrave:summon/interaction
function snapgrave:summon/marker
setblock ~ ~ ~ light[level=5]

function snapgrave:get/day/is_dead/renew with storage sgrave:temp

execute store result score @e[tag=sgrave,tag=!sgrave.verified,distance=..1] sgrave run scoreboard players get #grave.id sgrave
tag @e[tag=sgrave,tag=!sgrave.verified,distance=..1] add sgrave.verified


data merge storage sgrave:temp {pos:{list:[0d,0d,0d],int_array:[I;0,0,0]}}
data modify storage sgrave:temp pos.int_array set from entity @s LastDeathLocation.pos
execute store result storage sgrave:temp pos.list[0] double 1 run data get storage sgrave:temp pos.int_array[0]
execute store result storage sgrave:temp pos.list[1] double 1 run data get storage sgrave:temp pos.int_array[1]
execute store result storage sgrave:temp pos.list[2] double 1 run data get storage sgrave:temp pos.int_array[2]

data modify storage sgrave:temp dimension set from entity @s LastDeathLocation.dimension

data merge storage sgrave:temp {grave:{gid:0,dimension:"",pos:[]}}
data modify storage sgrave:temp grave.gid set from storage sgrave:temp gid
data modify storage sgrave:temp grave.dimension set from storage sgrave:temp dimension
data modify storage sgrave:temp grave.pos set from storage sgrave:temp pos.list
function snapgrave:store/grave with storage sgrave:temp





function snapgrave:store/pid
function snapgrave:store/equipment
function snapgrave:store/inventory
function snapgrave:store/xp/run
clear @s
xp set @s 0 levels
xp set @s 0 points

data modify storage sgrave:temp x set from storage sgrave:temp grave.pos[0]
data modify storage sgrave:temp y set from storage sgrave:temp grave.pos[1]
data modify storage sgrave:temp z set from storage sgrave:temp grave.pos[2]

function snapgrave:tellraw with storage sgrave:temp
execute at @s run playsound block.respawn_anchor.set_spawn master @s ~ ~ ~ 0.2 1

data remove storage sgrave:temp pid
data remove storage sgrave:temp player_name
data remove storage sgrave:temp day_start
data remove storage sgrave:temp day_end
data remove storage sgrave:temp gid
data remove storage sgrave:temp dimension
data remove storage sgrave:temp pos
data remove storage sgrave:temp grave
data remove storage sgrave:temp x
data remove storage sgrave:temp y
data remove storage sgrave:temp z

advancement revoke @s only snapgrave:is_dead