# Reload/normalize Nether border to match Overworld border (1:1).
# Works in existing worlds without macros by computing the difference and applying worldborder add steps.

# Read current diameters
execute in minecraft:overworld store result score OW bc_tmp run worldborder get
execute in minecraft:the_nether store result score NE bc_tmp run worldborder get

# DIFF = OW - NE
scoreboard players operation DIFF bc_tmp = OW bc_tmp
scoreboard players operation DIFF bc_tmp -= NE bc_tmp

# If DIFF positive => expand nether. If negative => shrink nether.
execute if score DIFF bc_tmp matches 2.. run function bordercraft:reloadborder/step_pos
execute if score DIFF bc_tmp matches ..-2 run function bordercraft:reloadborder/step_neg
execute if score DIFF bc_tmp matches 1 run function bordercraft:reloadborder/step_pos1
execute if score DIFF bc_tmp matches -1 run function bordercraft:reloadborder/step_neg1

# Finished (DIFF == 0): message
execute if score DIFF bc_tmp matches 0 run tellraw @a ["",{"text":"Bordercraft: Nether border reloaded to match the Overworld (1:1).","color":"green"},{"text":" (Size: ","color":"gray"},{"score":{"name":"OW","objective":"bc_tmp"},"color":"white"},{"text":")","color":"gray"}]
