Skip to content

Commit

Permalink
Add magic digit helper data pack
Browse files Browse the repository at this point in the history
By loading the pack as a data pack it is possible to access functions to convert a width to the magic digits needed. Big thanks to vdvman1 for helping with these!
  • Loading branch information
AmberWat committed Mar 6, 2023
1 parent ec1f8cd commit cbd3886
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 0 deletions.
6 changes: 6 additions & 0 deletions data/minecraft/tags/functions/load.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"spacefont:load"
]
}
3 changes: 3 additions & 0 deletions data/spacefont/functions/load.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Create scoreboard and intiialize values:
scoreboard objectives add spacefont dummy
scoreboard players set #-1 spacefont -1
38 changes: 38 additions & 0 deletions data/spacefont/functions/magic_digits.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -----------------------
# Magic Digits Calculator
# -----------------------
#
# This function will convert a width in the range -6764 .. 6764 to a set of digits.
# When displayed in the extended negative space font, these digits will form a space with the input width.
#
# Input score: width spacefont
# Output score: spacer spacefont
#
# Example usage:
# /scoreboard players set width spacefont -42
# /function spacefont:magic_digits
# /tellraw @a ["Hello ", {"font": "space:default", "score": {"name": "spacer","objective": "spacefont"}}, " There"]
#
# Example result: "Hello -1123466899 There" but with the score turning into a space of width -42.
#
# Digit sizes (just for reference):
# 9 = 1
# 8 = 3
# 7 = 8
# 6 = 21
# 5 = 55
# 4 = 144
# 3 = 377
# 2 = 987
# 1 = 2584
# - = -6765
#
# What is this sequence? It is every other Fibonacci number.
# If F(n) is the nth term, all terms before it add up to F(n+1).
# With 9 digits and 10 places to put them we can duplicate one digit.
# This extra capacity means we can skip every other term.
# Does it produce the largest range? No, but it eases scoreboard calculations.

execute if score width spacefont matches 6765.. run scoreboard players set spacer spacefont 1123456789
execute if score width spacefont matches ..-6765 run scoreboard players set spacer spacefont -9
execute if score width spacefont matches -6764..6764 run function spacefont:magic_digits/in_range
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/1_10.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 1000000000
scoreboard players remove width spacefont 2584
execute if score width spacefont matches 2584.. run function spacefont:magic_digits/1_9
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/1_9.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 100000000
scoreboard players remove width spacefont 2584
execute if score width spacefont matches 987.. run function spacefont:magic_digits/2_8
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/2_8.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 20000000
scoreboard players remove width spacefont 987
execute if score width spacefont matches 377.. run function spacefont:magic_digits/3_7
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/2_9.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 200000000
scoreboard players remove width spacefont 987
execute if score width spacefont matches 987.. run function spacefont:magic_digits/2_8
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/3_7.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 3000000
scoreboard players remove width spacefont 377
execute if score width spacefont matches 144.. run function spacefont:magic_digits/4_6
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/3_8.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 30000000
scoreboard players remove width spacefont 377
execute if score width spacefont matches 377.. run function spacefont:magic_digits/3_7
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/4_6.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 400000
scoreboard players remove width spacefont 144
execute if score width spacefont matches 55.. run function spacefont:magic_digits/5_5
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/4_7.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 4000000
scoreboard players remove width spacefont 144
execute if score width spacefont matches 144.. run function spacefont:magic_digits/4_6
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/5_5.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 50000
scoreboard players remove width spacefont 55
execute if score width spacefont matches 21.. run function spacefont:magic_digits/6_4
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/5_6.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 500000
scoreboard players remove width spacefont 55
execute if score width spacefont matches 55.. run function spacefont:magic_digits/5_5
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/6_4.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 6000
scoreboard players remove width spacefont 21
execute if score width spacefont matches 8.. run function spacefont:magic_digits/7_3
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/6_5.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 60000
scoreboard players remove width spacefont 21
execute if score width spacefont matches 21.. run function spacefont:magic_digits/6_4
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/7_3.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 700
scoreboard players remove width spacefont 8
execute if score width spacefont matches 3.. run function spacefont:magic_digits/8_2
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/7_4.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 7000
scoreboard players remove width spacefont 8
execute if score width spacefont matches 8.. run function spacefont:magic_digits/7_3
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/8_2.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 80
scoreboard players remove width spacefont 3
execute if score width spacefont matches 1 run function spacefont:magic_digits/9_1
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/8_3.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 800
scoreboard players remove width spacefont 3
execute if score width spacefont matches 3.. run function spacefont:magic_digits/8_2
2 changes: 2 additions & 0 deletions data/spacefont/functions/magic_digits/9_1.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scoreboard players add spacer spacefont 9
scoreboard players remove width spacefont 1
3 changes: 3 additions & 0 deletions data/spacefont/functions/magic_digits/9_2.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard players add spacer spacefont 90
scoreboard players remove width spacefont 1
execute if score width spacefont matches 1 run function spacefont:magic_digits/9_1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tellraw @s [[{"text":"width: ","color":"gold"},{"score":{"name":"width","objective":"spacefont"}}], [{"text":"\nspacer: ","color":"dark_green"}, {"score":{"name":"spacer","objective":"spacefont"}}], [{"text":"\n#is_neg: ","color":"gray"}, {"score":{"name":"#is_neg","objective":"spacefont"}}], [{"text":"\n#-1: ","color":"gray"}, {"score":{"name":"#-1","objective":"spacefont"}}]]
16 changes: 16 additions & 0 deletions data/spacefont/functions/magic_digits/in_range.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
scoreboard players set spacer spacefont 0

execute store result score #is_neg spacefont if score width spacefont matches ..-1
execute if score width spacefont matches ..-1 run scoreboard players add width spacefont 6765

execute if score width spacefont matches 2584..6764 run function spacefont:magic_digits/1_10
execute if score width spacefont matches 987..2583 run function spacefont:magic_digits/2_9
execute if score width spacefont matches 377..986 run function spacefont:magic_digits/3_8
execute if score width spacefont matches 144..376 run function spacefont:magic_digits/4_7
execute if score width spacefont matches 55..143 run function spacefont:magic_digits/5_6
execute if score width spacefont matches 21..54 run function spacefont:magic_digits/6_5
execute if score width spacefont matches 8..20 run function spacefont:magic_digits/7_4
execute if score width spacefont matches 3..7 run function spacefont:magic_digits/8_3
execute if score width spacefont matches 1..2 run function spacefont:magic_digits/9_2

execute if score #is_neg spacefont matches 1.. run scoreboard players operation spacer spacefont *= #-1 spacefont

0 comments on commit cbd3886

Please sign in to comment.