Skip to content

Commit 139d16e

Browse files
committed
- Initial commit (wip)
0 parents  commit 139d16e

15 files changed

+344
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.exe

Datapack Generator 1.4.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import os
2+
import time
3+
4+
# Rng import, mostly just writing large strings to a few files with the namespace filled in
5+
def import_rng(ver):
6+
7+
print(" Importing rng...")
8+
os.makedirs(f"./{pack_name}/data/{pack_namespace}/functions/rng/")
9+
10+
with open(f"{pack_name}/data/{pack_namespace}/functions/rng/lcg.mcfunction", "w") as f:
11+
12+
f.write(f"""# LCG Seed implementation
13+
#
14+
# x_(n+1) = x_(n)*a + c
15+
#
16+
# a = 1103515245, c = 12345
17+
18+
scoreboard players operation #lcg {pack_namespace}.rng *= #lcg_constant {pack_namespace}.rng
19+
scoreboard players add #lcg {pack_namespace}.rng 12345
20+
scoreboard players operation out {pack_namespace}.rng = #lcg {pack_namespace}.rng""")
21+
22+
with open(f"{pack_name}/data/{pack_namespace}/functions/rng/next_int_lcg.mcfunction", "w") as f:
23+
24+
f.write(f"""###
25+
# public int nextInt(int bound) {{
26+
# if (bound <= 0)
27+
# throw new IllegalArgumentException(BadBound);
28+
#
29+
# int r = next(31);
30+
# int m = bound - 1;
31+
# if ((bound & m) == 0) // i.e., bound is a power of 2
32+
# r = (int)((bound * (long)r) >> 31);
33+
# else {{
34+
# for (int u = r; u - (r = u % bound) + m < 0; u = next(31));
35+
# }}
36+
# return r;
37+
# }}
38+
39+
function {pack_namespace}:rng/lcg
40+
41+
scoreboard players operation #temp {pack_namespace}.rng = out {pack_namespace}.rng
42+
scoreboard players operation out {pack_namespace}.rng %= #range {pack_namespace}.rng
43+
scoreboard players operation #temp {pack_namespace}.rng -= out {pack_namespace}.rng
44+
scoreboard players operation #temp {pack_namespace}.rng += #m1 {pack_namespace}.rng
45+
execute if score #temp {pack_namespace}.rng matches ..-1 run function {pack_namespace}:rng/next_int_lcg""")
46+
47+
with open(f"{pack_name}/data/{pack_namespace}/functions/rng/range_lcg.mcfunction", "w") as f:
48+
49+
f.write(f"""scoreboard players add in1 {pack_namespace}.rng 1
50+
scoreboard players operation #range {pack_namespace}.rng = in1 {pack_namespace}.rng
51+
scoreboard players operation #range {pack_namespace}.rng -= in {pack_namespace}.rng
52+
53+
scoreboard players operation #m1 {pack_namespace}.rng = #range {pack_namespace}.rng
54+
scoreboard players remove #m1 {pack_namespace}.rng 1
55+
function {pack_namespace}:rng/next_int_lcg
56+
scoreboard players operation out {pack_namespace}.rng += in {pack_namespace}.rng
57+
58+
scoreboard players reset #m1 {pack_namespace}.rng
59+
scoreboard players remove in1 {pack_namespace}.rng 1""")
60+
61+
with open(f"{pack_name}/data/{pack_namespace}/functions/rng/setup.mcfunction", "w") as f:
62+
63+
f.write(f"""scoreboard objectives add {pack_namespace}.rng dummy
64+
65+
scoreboard players set in {pack_namespace}.rng -100
66+
scoreboard players set in1 {pack_namespace}.rng 100
67+
68+
scoreboard players set #lcg_constant {pack_namespace}.rng 1103515245
69+
execute unless score #lcg {pack_namespace}.rng matches ..0 unless score #lcg {pack_namespace}.rng matches 1.. run function {pack_namespace}:rng/uuid_reset""")
70+
71+
with open(f"{pack_name}/data/{pack_namespace}/functions/rng/uuid_reset.mcfunction", "w") as f:
72+
73+
# UUID data storage changed in 1.16+
74+
insert = "UUID[0] 1"
75+
if ver < 6 :
76+
insert = "UUIDMost 0.00000000023283064365386962890625"
77+
78+
f.write(f"""summon area_effect_cloud ~ ~ ~ {{Tags:["get_uuid"]}}
79+
execute store result score #lcg {pack_namespace}.rng run data get entity @e[tag=get_uuid,limit=1] {insert}
80+
kill @e[tag=get_uuid]""")
81+
82+
with open(f"{pack_name}/data/{pack_namespace}/functions/load.mcfunction", "r") as f:
83+
84+
f_remp = f.read()
85+
86+
with open(f"{pack_name}/data/{pack_namespace}/functions/load.mcfunction", "w") as f:
87+
88+
f.write(f"{f_remp}\n\nfunction {pack_namespace}:rng/setup")
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
print("\n -- Thank you for using Datapack Generator by RoarkCats --\n")
102+
pack_name = input(" Datapack Name: ")
103+
pack_namespace = input(" Datapack Namespace: ")
104+
pack_author = input(" Datapack Author: ")
105+
pack_ver = input(" Datapack Version: ")
106+
pack_rng = input(" Import Rng? (y/n) ")
107+
108+
try :
109+
pack_ver = int(pack_ver)
110+
except :
111+
pack_ver = 10
112+
113+
proc_time_start = time.process_time()
114+
115+
print("\n Generating folders...")
116+
os.makedirs(f"./{pack_name}/data/minecraft/tags/functions/")
117+
os.makedirs(f"./{pack_name}/data/{pack_namespace}/functions/")
118+
119+
print(" Generating files...")
120+
with open(f"{pack_name}/pack.mcmeta", "w") as f:
121+
122+
f.write(f"""{{
123+
\"pack\": {{
124+
\"pack_format\": {pack_ver},
125+
\"description\": \"{pack_name} by {pack_author}\"
126+
}}
127+
}}""")
128+
129+
with open(f"{pack_name}/data/minecraft/tags/functions/tick.json", "w") as f:
130+
131+
f.write(f"""{{
132+
\"values\":[
133+
\"{pack_namespace}:main\"
134+
]
135+
}}""")
136+
137+
with open(f"{pack_name}/data/minecraft/tags/functions/load.json", "w") as f:
138+
139+
f.write(f"""{{
140+
\"values\":[
141+
\"{pack_namespace}:load\"
142+
]
143+
}}""")
144+
145+
with open(f"{pack_name}/data/{pack_namespace}/functions/main.mcfunction", "w") as f:
146+
147+
f.write("")
148+
149+
with open(f"{pack_name}/data/{pack_namespace}/functions/load.mcfunction", "w") as f:
150+
151+
f.write(f"tellraw @a {{\"text\":\"Thank you for downloading {pack_name} by {pack_author}!\",\"color\":\"gold\"}}")
152+
153+
if pack_rng == "y":
154+
import_rng(pack_ver)
155+
156+
proc_time_end = time.process_time()
157+
print(f" Done! ({(proc_time_end - proc_time_start)*1000} ms)")
158+
input()

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module datapack_generator
2+
3+
go 1.24.5

input.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func InputType[T any](prefix string, vartype string) (out T) {
6+
7+
fmt.Print(prefix)
8+
9+
_, err := fmt.Scanf(vartype+"\n", &out)
10+
if err != nil && err.Error() != "unexpected newline" {
11+
panic(err)
12+
}
13+
return out
14+
}
15+
16+
func Input(prefix string) (out string) {
17+
18+
return fmt.Sprint(InputType[string](prefix, "%s"))
19+
}

main.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package main
2+
3+
import (
4+
"embed"
5+
"fmt"
6+
"os"
7+
s "strings"
8+
)
9+
10+
//go:embed templates/*
11+
var templates embed.FS
12+
13+
var version = "2.0.0"
14+
15+
func main() {
16+
fmt.Printf("\n -- Welcome to Datapack Generator %s by RoarkCats --\n", version)
17+
18+
pack_name := Input(" Datapack Name: ")
19+
pack_namespace := Input(" Datapack Namespace: ")
20+
pack_author := Input(" Datapack Author: ")
21+
pack_ver := getVer()
22+
if pack_ver < 18 && s.ToLower(Input(" Import Rng? (y/n) ")) == "y" {
23+
// make rng
24+
}
25+
fmt.Printf("%s %s %s %d", pack_name, pack_namespace, pack_author, pack_ver)
26+
27+
dat, err := os.ReadFile("./wah.txt")
28+
if err != nil {
29+
// panic(err)
30+
} else {
31+
fmt.Println(string(dat))
32+
}
33+
34+
// for compilation
35+
// fmt.Scanf("%s")
36+
}
37+
38+
// Get pack format from "version" (MC or format)
39+
func getVer() (version int) {
40+
ver := Input(" Version: ")
41+
42+
// basic format number
43+
_, err := fmt.Sscanf(ver, "%d ", &version)
44+
if err == nil {
45+
return version
46+
}
47+
48+
var minor, patch int
49+
50+
// '1.x' version
51+
_, err = fmt.Sscanf(ver, "1.%d ", &minor)
52+
if err == nil {
53+
version = map[int]int{
54+
13: 4, 14: 4,
55+
15: 5, 16: 5,
56+
17: 7,
57+
18: 8,
58+
19: 10,
59+
20: 15,
60+
21: 48,
61+
}[minor]
62+
return version
63+
}
64+
65+
// 1.x.y version
66+
_, err = fmt.Sscanf(ver, "1.%d.%d ", &minor, &patch)
67+
if err == nil {
68+
version = map[int]int{
69+
1301: 4, 1302: 4, 1401: 4, 1402: 4, 1403: 4, 1404: 4,
70+
1501: 5, 1502: 5, 1601: 5,
71+
1602: 6, 1603: 6, 1604: 6, 1605: 6,
72+
1701: 7,
73+
1801: 8,
74+
1802: 9,
75+
1901: 10, 1902: 10, 1903: 10,
76+
1904: 12,
77+
2001: 15,
78+
2002: 18,
79+
2003: 26, 2004: 26,
80+
2005: 41, 2006: 41,
81+
2101: 48,
82+
2102: 57, 2103: 57,
83+
2104: 61,
84+
2105: 71,
85+
2106: 80,
86+
2107: 81, 2108: 81,
87+
}[minor*100+patch]
88+
return version
89+
}
90+
91+
return 81
92+
}

templates/load.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"values":[
3+
"%namespace%:load"
4+
]
5+
}

templates/load.mcfunction

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tellraw @a {"text":"Thank you for downloading %packname% by %author%!","color":"gold"}
2+
3+
function %namespace%:rng/setup

templates/main.mcfunction

Whitespace-only changes.

templates/pack.mcmeta

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"pack": {
3+
"pack_format": %format%,
4+
"description": "%packname% by %author%"
5+
}
6+
}

templates/rng/lcg.mcfunction

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# LCG Seed implementation
2+
#
3+
# x_(n+1) = x_(n)*a + c
4+
#
5+
# a = 1103515245, c = 12345
6+
7+
scoreboard players operation #lcg %namespace%.rng *= #lcg_constant %namespace%.rng
8+
scoreboard players add #lcg %namespace%.rng 12345
9+
scoreboard players operation out %namespace%.rng = #lcg %namespace%.rng

0 commit comments

Comments
 (0)