forked from IrisShaders/Iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FmjVersionFixer.java
40 lines (34 loc) · 1.3 KB
/
FmjVersionFixer.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
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import io.github.coolcrabs.brachyura.processing.ProcessingEntry;
import io.github.coolcrabs.brachyura.processing.ProcessingSink;
import io.github.coolcrabs.brachyura.processing.Processor;
import io.github.coolcrabs.brachyura.util.GsonUtil;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
public class FmjVersionFixer implements Processor {
private final Buildscript parent;
public FmjVersionFixer(Buildscript parent) {
this.parent = parent;
}
@Override
public void process(Collection<ProcessingEntry> inputs, ProcessingSink sink) throws IOException {
for (ProcessingEntry e : inputs) {
if ("fabric.mod.json".equals(e.id.path)) {
Gson gson = new GsonBuilder().setPrettyPrinting().setLenient().create();
JsonObject fabricModJson;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(e.in.get(), StandardCharsets.UTF_8))) {
fabricModJson = gson.fromJson(reader, JsonObject.class);
}
fabricModJson.addProperty("version", parent.getVersion());
sink.sink(() -> GsonUtil.toIs(fabricModJson, gson), e.id);
} else {
sink.sink(e.in, e.id);
}
}
}
}