-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_step.lua
71 lines (52 loc) · 2.07 KB
/
generate_step.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local directory = "./CraftBoyDatapack/data/craftboy/functions/step/"
os.execute("mkdir " .. directory)
command_step = {
"execute if score op craftboy matches ",
" run function craftboy:instructions/", "\n"
}
command_step_cb = {
"execute if score op_cb craftboy matches ",
" run function craftboy:instructions/", "\n"
}
local recursions = 0
function recursive(depth, prefix, min, max)
local len = math.floor((max - min) / 2)
if len * 2 >= 4 then
if prefix == "cb_" then
execute_if = "execute if score op_cb craftboy matches "
else
execute_if = "execute if score op craftboy matches "
end
local filename = prefix .. depth .. "_" .. recursions
local file = io.open(directory .. filename .. ".mcfunction", "w")
local child_filename = prefix .. (depth + 1) .. "_" .. recursions
file:write(execute_if .. min .. ".." .. (min + len) ..
" run function craftboy:step/" .. child_filename .. "\n")
file:close()
recursive(depth + 1, prefix, min, min + len)
file = io.open(directory .. filename .. ".mcfunction", "a")
child_filename = prefix .. (depth + 1) .. "_" .. recursions
file:write(execute_if .. (min + len + 1) .. ".." .. max ..
" run function craftboy:step/" .. child_filename .. "\n")
file:close()
recursive(depth + 1, prefix, min + len + 1, max)
else
print(depth .. ", " .. recursions .. ": " .. min .. ", " .. max)
local filename = prefix .. depth .. "_" .. recursions
local file = io.open(directory .. filename .. ".mcfunction", "w")
if prefix == "cb_" then
command = command_step_cb
else
command = command_step
end
for i = min, max do
file:write(command[1] .. i .. command[2] .. prefix .. i ..
command[3])
end
file:close()
recursions = recursions + 1
end
end
recursive(0, "", 0x0000, 0x00FF)
recursions = 0
recursive(0, "cb_", 0x0000, 0x00FF)