-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PatchConfigCategory.java
128 lines (104 loc) · 2.84 KB
/
PatchConfigCategory.java
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
package me.nallar.patched.forge;
import java.io.BufferedWriter;
import java.io.IOException;
import com.google.common.base.Splitter;
import net.minecraftforge.common.ConfigCategory;
import net.minecraftforge.common.Property;
import static net.minecraftforge.common.Configuration.allowedProperties;
public abstract class PatchConfigCategory extends ConfigCategory {
private static final Splitter splitter = Splitter.onPattern("\r?\n");
;
public PatchConfigCategory(String name) {
super(name);
}
@Override
public void write(BufferedWriter out, int indent) throws IOException {
String pad = getIndent(indent);
out.write(pad);
out.write("####################");
out.newLine();
out.write(pad);
out.write("# ");
out.write(name);
out.newLine();
if (comment != null) {
out.write(pad);
out.write("#===================");
out.newLine();
Splitter splitter = Splitter.onPattern("\r?\n");
for (String line : splitter.split(comment)) {
out.write(pad);
out.write("# ");
out.write(line);
out.newLine();
}
}
out.write(pad);
out.write("####################");
out.newLine();
out.newLine();
if (!allowedProperties.matchesAllOf(name)) {
name = '"' + name + '"';
}
out.write(pad);
out.write(name);
out.write(" {");
out.newLine();
pad = getIndent(indent + 1);
Property[] props = properties.values().toArray(new Property[properties.size()]);
for (int x = 0; x < props.length; x++) {
Property prop = props[x];
if (prop.comment != null) {
if (x != 0) {
out.newLine();
}
for (String commentLine : splitter.split(prop.comment)) {
out.write(pad);
out.write("# ");
out.write(commentLine);
out.newLine();
}
}
String propName = prop.getName();
propName = !allowedProperties.matchesAllOf(propName) ? '"' + propName + '"' : propName;
if (prop.isList()) {
out.write(pad);
out.write(prop.getType().getID());
out.write(':');
out.write(propName);
out.write(" <");
out.newLine();
pad = getIndent(indent + 2);
for (String line : prop.valueList) {
out.write(pad);
out.write(line);
out.newLine();
}
out.write(getIndent(indent + 1));
out.write(" >");
out.newLine();
pad = getIndent(indent + 1);
} else if (prop.getType() == null) {
out.write(pad);
out.write(propName);
out.write('=');
out.write(prop.value);
} else {
out.write(pad);
out.write(prop.getType().getID());
out.write(':');
out.write(propName);
out.write('=');
out.write(prop.value);
out.newLine();
}
}
for (ConfigCategory child : children) {
child.write(out, indent + 1);
}
out.write(getIndent(indent));
out.write('}');
out.newLine();
out.newLine();
}
}