-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
133 lines (99 loc) · 4.04 KB
/
index.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Welcome to hell 🔥🔥🔥🔥🔥🔥🔥
const fs = require("fs");
const SETTINGS = {
"North": "32.00 12.00 -3.00",
"South": "32.00 12.00 35.00",
"East": "51.00 12.00 16.00",
"West": "13.00 12.00 16.00",
"globalNBT": "Team: \"mobs\""
};
const log = console.log; // lazy lol
// Top level await wasn't working, didn't bother trying to figure out why :D
(async () => {
const csv = require("csvtojson");
// CONVERT MOBS.CSV TO JASON :D
const mobsArrayCsv = await csv().fromFile("./mobs.csv");
const mobsArrayParsed = {};
for (const mob of mobsArrayCsv) {
if (mob["Has baby"] === "true") {
const copy = Object.assign({}, mob);
copy.MobType = "baby_" + copy.MobType;
copy["Has baby"] = "false";
mobsArrayCsv.push(copy);
}
const mobLevel = mob.Level.slice(-1) !== "s" ? `_${mob.Level.slice(-1)}` : "";
const jockey = mob.Name.toLowerCase().match("jockey") ? "_jockey" : "";
const mobName = mob.MobType + jockey + mobLevel;
let mobNBT = SETTINGS.globalNBT + "," + mob.NBT;
if (mob.HP !== "") {
mobNBT = SETTINGS.globalNBT + "," + `Attributes:[{Name:"generic.max_health",Base:${mob.HP}}],Health:${mob.HP},` + mob.NBT;
}
mobsArrayParsed[mobName] = {
mobType: mob.MobType,
nbt: mobNBT
}
}
// CONVERT ROUNDS TO MCFUNCTION POGGERS
const roundsArrayCsv = await csv().fromFile("./rounds.csv");
for (const round of roundsArrayCsv) {
const commands = [];
let count = 0;
["North", "South", "East", "West"].forEach(v => {
if (round[v] === '') return;
const coords = SETTINGS[v];
const mobsToSpawn = round[v].split("\n")
mobsToSpawn.forEach(mob => {
const amount = mob.match(/\d* /)?.[0].replace(" ", "") ?? 1;
count += +amount;
if (mob.match(/bat|jockey/g)) count++;
const mobName = mob.replace(/\d* /, "");
if (!mobName) return;
// ALL MOBS
if (mobName === "all_mobs") {
count = 0;
let coords = SETTINGS.North
Object.keys(mobsArrayParsed).forEach(mob => {
const amount = mob.match(/\d* /)?.[0].replace(" ", "") ?? 1;
count += amount;
const mobbie = mobsArrayParsed[mob];
if (mobbie.mobType === "wither") return;
if (mobbie.mobType.match("baby")) {
mobbie.mobType = mobbie.mobType.replace("baby_", "");
mobbie.nbt = mobbie.nbt + ",IsBaby:true";
}
mobbie.nbt = mobbie.nbt.replace(/,+/g, ",");
commands.push(`execute as @e[limit=${amount}] run summon minecraft:${mobbie.mobType} ${coords} {${mobbie.nbt}}`);
coords = coords == SETTINGS.North ? SETTINGS.South : coords == SETTINGS.South ? SETTINGS.East : coords == SETTINGS.East ? SETTINGS.West : coords == SETTINGS.West ? SETTINGS.North : "lol";
})
return;
}
// BATS
if (mobName.match("bat")) {
const mobbie = mobsArrayParsed[mobName.replace("bat_", "")]
if (mobbie.mobType.match("baby")) {
mobbie.mobType = mobbie.mobType.replace("baby_", "");
mobbie.nbt = mobbie.nbt + ",IsBaby:true";
}
mobbie.nbt = mobbie.nbt.replace(/,+/g, ",");
commands.push(`execute as @e[limit=${amount}] run summon minecraft:bat ${coords} {Passengers:[{id:"minecraft:${mobbie.mobType}",${mobbie.nbt}}]}`)
return;
};
const mobbie = mobsArrayParsed[mobName];
if (mobbie.mobType.match("baby")) {
mobbie.mobType = mobbie.mobType.replace("baby_", "");
mobbie.nbt = mobbie.nbt + ",IsBaby:true";
}
mobbie.nbt = mobbie.nbt.replace(/,+/g, ",");
let fixWeirdBug = mobbie.nbt.replace(/(Passengers:\[\{id: \"\w*\",)/g, `$1${SETTINGS.globalNBT},`); // genuinely no idea
commands.push(`execute as @e[limit=${amount}] run summon minecraft:${mobbie.mobType} ${coords} {${fixWeirdBug}}`);
})
})
commands.push(`scoreboard players set dt max_mobs ${count}`);
commands.push(`function cd:round/loadvalues`);
const tellraw = `tellraw @a {"text":"Round {{round}} started with {{mobs}} mobs, good luck!","color":"#99DAAC"}`
.replace("{{round}}", round.Round)
.replace("{{mobs}}", count);
commands.unshift(tellraw);
fs.writeFileSync(`./functions/${round.Round}.mcfunction`, commands.join("\r\n"))
}
})()