
# --> Get respawnable positions

# -> Get worldborder size
execute store result score #or.respawnable_position OverlyRealistic.General.ArbitraryData run \
    worldborder get

# -> (Worldborder size / 2) - 64      ///     [The 64 decrease is only added if the worldborder is 200+ blocks in each direction]
scoreboard players operation #or.respawnable_position OverlyRealistic.General.ArbitraryData /= #or.static_num_2 OverlyRealistic.General.ArbitraryData
execute if score #or.respawnable_position OverlyRealistic.General.ArbitraryData matches 200.. \
    store result storage overly_realistic:randomized_respawning random_pos_xz int 1 run \
        scoreboard players operation #or.respawnable_position OverlyRealistic.General.ArbitraryData -= #or.static_num_64 OverlyRealistic.General.ArbitraryData

# -> Randomize X & Z positions
function overly_realistic:players/revive/randomized_respawning/get_respawnable_position with storage overly_realistic:randomized_respawning

# -> Debug
#data modify storage overly_realistic:randomized_respawning respawn_pos_x set value 19
#data modify storage overly_realistic:randomized_respawning respawn_pos_z set value 76

# -> If player is a ghost then set gamemode
gamemode survival @s[gamemode=spectator]

# -> Move player
function overly_realistic:players/revive/randomized_respawning/move_player with storage overly_realistic:randomized_respawning

# -> Set effects
effect give @s slow_falling 1 0 true

# -> Tag player for surface move
tag @s add OverlyRealistic.Player.PlayerMustMoveToSurface

# -> Move player to surface with delay
schedule function overly_realistic:players/revive/randomized_respawning/set_position_surface_0 10t append


# function overly_realistic:players/revive/randomized_respawning/respawn_player
