# /function bordercraft:percentcomplete
# Shows percent of unique expansions completed (Increases / Max) with 1 decimal place.

execute unless data storage bordercraft:state {active:1b} run tellraw @s [{"text":"Bordercraft is not active in this world yet.","color":"red"},{"text":"  Run ","color":"gray"},{"text":"/function bordercraft:activate","color":"yellow"},{"text":" first.","color":"gray"}]
execute unless data storage bordercraft:state {active:1b} run return 0

# Ensure helper constants
scoreboard players set Ten bc_tmp 10
scoreboard players set Thousand bc_tmp 1000

# pct_x10 = floor(Increases * 1000 / Max)
scoreboard players operation Pct_x10 bc_tmp = Increases bc_border
scoreboard players operation Pct_x10 bc_tmp *= Thousand bc_tmp
scoreboard players operation Pct_x10 bc_tmp /= Max bc_border

# int = floor(pct_x10 / 10)
scoreboard players operation Pct_int bc_tmp = Pct_x10 bc_tmp
scoreboard players operation Pct_int bc_tmp /= Ten bc_tmp

# dec = pct_x10 % 10
scoreboard players operation Pct_dec bc_tmp = Pct_x10 bc_tmp
scoreboard players operation Pct_dec bc_tmp %= Ten bc_tmp

# Output
# Example: 12.3% (256 / 2080)

tellraw @s ["",{"text":"Bordercraft Progress: ","color":"gold"},{"score":{"name":"Pct_int","objective":"bc_tmp"}},{"text":".","color":"white"},{"score":{"name":"Pct_dec","objective":"bc_tmp"}},{"text":"% ","color":"white"},{"text":"(","color":"gray"},{"score":{"name":"Increases","objective":"bc_border"}},{"text":" / ","color":"gray"},{"score":{"name":"Max","objective":"bc_border"}},{"text":")","color":"gray"}]
