-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
118 lines (103 loc) · 3.25 KB
/
build.ts
File metadata and controls
118 lines (103 loc) · 3.25 KB
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
import fs from "fs";
const INPUT_FILE_PATH = "default/player.json";
const OUTPUT_FILE_PATH = "entities/player.json";
const WARNING_TEXT = `/**
* Warning: This file is auto-generated. Do not edit it directly.
* Instead, edit the default/player.json file and run the script again.
*/\n`;
const isEmpty = process.argv[2] === "empty";
const file = fs.readFileSync(INPUT_FILE_PATH, "utf-8");
if (!file) throw new Error("File not found");
const json = JSON.parse(file);
if (!json) throw new Error("File is empty");
if (isEmpty) {
const string = JSON.stringify(json, null, 4);
fs.writeFileSync(OUTPUT_FILE_PATH, WARNING_TEXT.concat(string), "utf-8");
console.log("File written successfully.");
process.exit(0);
}
const description = json["minecraft:entity"].description;
if (!description) throw new Error("Description not found");
const componentGroups = json["minecraft:entity"].component_groups;
if (!componentGroups) throw new Error("Component groups not found");
const components = json["minecraft:entity"].components;
if (!components) throw new Error("Components not found");
const events = json["minecraft:entity"].events;
if (!events) throw new Error("Events not found");
description["properties"] = {
"capi:team": {
type: "int",
default: 0,
range: [0, 40],
},
};
components["minecraft:damage_sensor"] = {
triggers: [],
};
for (let i = 0.0; Math.round(i * 100) / 100 <= 10.0; i += 0.01) {
i = Math.round(i * 100) / 100; // Round to 2 decimal places
componentGroups[`capi:size_${i}`] = {
"minecraft:scale": {
value: i,
},
};
events[`capi:size_${i}`] = {
add: {
component_groups: [`capi:size_${i}`],
},
};
}
for (let i = 1; i <= 200; i += 1) {
i = Math.round(i * 10) / 10; // Round to 1 decimal place
componentGroups[`capi:health_${i}`] = {
"minecraft:health": {
max: i,
},
};
events[`capi:health_${i}`] = {
add: {
component_groups: [`capi:health_${i}`],
},
};
}
for (let i = 0; i <= 200; i++) {
componentGroups[`capi:attack_${i}`] = {
"minecraft:attack": {
damage: i,
},
};
events[`capi:attack_${i}`] = {
add: {
component_groups: [`capi:attack_${i}`],
},
};
}
for (let i = 1; i <= 40; i++) {
components["minecraft:damage_sensor"].triggers.push({
on_damage: {
filters: {
all_of: [
{
test: "int_property",
subject: "self",
domain: "capi:team",
value: i,
},
{
test: "int_property",
subject: "other",
domain: "capi:team",
value: i,
},
],
},
},
deals_damage: false,
});
}
json["minecraft:entity"].component_groups = componentGroups;
json["minecraft:entity"].components = components;
json["minecraft:entity"].events = events;
const string = JSON.stringify(json, null, 4);
fs.writeFileSync(OUTPUT_FILE_PATH, WARNING_TEXT.concat(string), "utf-8");
console.log("File written successfully.");