# Called in an execute-positioned context at the chosen start location.
# Sets border/spawn, teleports players, and creates a persistent anchor.

# Keep the start chunk loaded so the anchor exists for future joins.
forceload add ~ ~

# Recreate anchor at start
kill @e[tag=bc_anchor]
summon marker ~ 0 ~ {Tags:["bc_anchor"]}

# Set initial world borders (each dimension has its own worldborder)
execute in minecraft:overworld run worldborder center ~ ~
execute in minecraft:overworld run worldborder set 1

# Start locations are already aligned to .5 coordinates (see find_start sampling),
# so centering directly on ~ ~ preserves the half-block offset without shifting
# the border by a full block.
# Snap to full blocks, then offset by +0.5 so the border always lines up with block edges
execute in minecraft:the_nether align xz positioned ~0.5 ~ ~0.5 run worldborder center ~ ~
execute in minecraft:the_nether run worldborder set 1

# The End entrance platform is offset from the fountain (0,0).
# Center the End border on the obsidian spawn platform so players don't clip the border on entry.
execute in minecraft:the_end run worldborder center 100 0
execute in minecraft:the_end run worldborder set 1

# Set world spawn to the start
setworldspawn ~ ~ ~

# Ensure players always respawn within the border (in the air, then they fall)
spawnpoint @a ~ 257 ~

# Teleport all current players to the start and give Resistance until landing
tp @a ~ 257 ~
tag @a add bc_joined
effect give @a resistance infinite 255 true

# Initialize death trackers for current players
execute as @a run scoreboard players operation @s bc_deaths_last = @s bc_deaths
