-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.js
83 lines (65 loc) · 1.82 KB
/
generate.js
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
72
73
74
75
76
77
78
79
80
81
82
83
// * Size of Square
let sizes = [];
// * By Test Result, above 512, the function starts to fail
for (let i = 1; i <= 9; i++) {
sizes.push(Math.pow(2, i));
if (i >= 2) {
let j = i;
let currsize = Math.pow(2, j);
while (j > 1) {
j--;
currsize += Math.pow(2, j);
sizes.push(currsize);
}
}
}
sizes = sizes.filter((s) => s <= 512);
console.log(sizes);
const fs = require("fs").promises;
async function generate(size, block = "barrier", maxheight = 255, suffix = "") {
// * Convert to radius
size /= 2;
let filecontent = "";
const bps = Math.floor(30000 / (maxheight + 1));
const bp = [];
let curr = -size;
while (curr < size) {
bp.push(curr);
curr += bps;
}
bp.push(size);
const commands = 4 * (bp.length - 1);
if (commands > 10000) {
console.log(
`Skipped barrier${
size * 2
} because it has ${commands} commands which exceeds limits of 10000`
);
return;
}
for (let i = 0; i < bp.length - 1; i++) {
filecontent += `fill ~${-size} 0 ~${bp[i]} ~${-size} ${maxheight} ~${
bp[i + 1]
} ${block}\n`;
filecontent += `fill ~${size} 0 ~${bp[i]} ~${size} ${maxheight} ~${
bp[i + 1]
} ${block}\n`;
filecontent += `fill ~${bp[i]} 0 ~${-size} ~${
bp[i + 1]
} ${maxheight} ~${-size} ${block}\n`;
filecontent += `fill ~${bp[i]} 0 ~${size} ~${
bp[i + 1]
} ${maxheight} ~${size} ${block}\n`;
}
const filename = `./functions/${block}${suffix}${size * 2}.mcfunction`;
console.log(`Writing ${filename} with ${commands} commands`);
await fs.writeFile(filename, filecontent);
}
(async () => {
for (const size of sizes) {
await generate(size);
await generate(size, "bedrock");
await generate(size, "barrier", 127, "nether");
await generate(size, "bedrock", 127, "nether");
}
})();