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

# pct10 = floor(Increases * 1000 / Max)
scoreboard players operation #pc_work bc_tmp = Increases bc_border
scoreboard players set #pc_mul bc_tmp 1000
scoreboard players operation #pc_work bc_tmp *= #pc_mul bc_tmp
scoreboard players operation #pc_den bc_tmp = Max bc_border
execute if score #pc_den bc_tmp matches 1.. run scoreboard players operation #pc_work bc_tmp /= #pc_den bc_tmp

# int = floor(pct10 / 10)
scoreboard players operation #pc_int bc_tmp = #pc_work bc_tmp
scoreboard players set #pc_ten bc_tmp 10
scoreboard players operation #pc_int bc_tmp /= #pc_ten bc_tmp

# dec = pct10 - int*10
scoreboard players operation #pc_dec bc_tmp = #pc_work bc_tmp
scoreboard players operation #pc_tmp bc_tmp = #pc_int bc_tmp
scoreboard players operation #pc_tmp bc_tmp *= #pc_ten bc_tmp
scoreboard players operation #pc_dec bc_tmp -= #pc_tmp bc_tmp

# Output
execute if score #pc_den bc_tmp matches 1.. run tellraw @s ["",{"text":"Percent complete: ","color":"gold"},{"score":{"name":"#pc_int","objective":"bc_tmp"}},{"text":".","color":"gold"},{"score":{"name":"#pc_dec","objective":"bc_tmp"}},{"text":"%","color":"gold"},{"text":"  (","color":"gray"},{"score":{"name":"Increases","objective":"bc_border"}},{"text":" / ","color":"gray"},{"score":{"name":"Max","objective":"bc_border"}},{"text":")","color":"gray"}]
execute unless score #pc_den bc_tmp matches 1.. run tellraw @s [{"text":"Percent complete: N/A (Max is 0)","color":"red"}]
