Skip to content

Commit 602518f

Browse files
committed
Combine existing data from MCMaven and SL
1 parent 39dcff7 commit 602518f

File tree

8 files changed

+356
-4
lines changed

8 files changed

+356
-4
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) Forge Development LLC and contributors
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
package net.minecraftforge.util.data.json;
6+
7+
import java.util.Map;
8+
9+
public class AssetsIndex {
10+
public Map<String, Asset> objects;
11+
12+
public static class Asset {
13+
public String hash;
14+
public long size;
15+
}
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) Forge Development LLC and contributors
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
package net.minecraftforge.util.data.json;
7+
8+
public class Config {
9+
public int spec;
10+
}

json-data-utils/src/main/java/net/minecraftforge/util/data/json/JsonData.java

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,93 @@ public static MinecraftVersion minecraftVersion(byte[] data) {
4343
return fromJson(data, MinecraftVersion.class);
4444
}
4545

46-
private static <T> T fromJson(File file, Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
46+
public static AssetsIndex assetsIndex(File file) {
47+
return fromJson(file, AssetsIndex.class);
48+
}
49+
public static AssetsIndex assetsIndex(InputStream stream) {
50+
return fromJson(stream, AssetsIndex.class);
51+
}
52+
public static AssetsIndex assetsIndex(byte[] data) {
53+
return fromJson(data, AssetsIndex.class);
54+
}
55+
56+
public static int configSpec(File file) {
57+
return fromJson(file, Config.class).spec;
58+
}
59+
public static int configSpec(InputStream stream) {
60+
return fromJson(stream, Config.class).spec;
61+
}
62+
public static int configSpec(byte[] data) {
63+
return fromJson(data, Config.class).spec;
64+
}
65+
66+
public static PatcherConfig patcherConfig(File file) {
67+
return fromJson(file, PatcherConfig.class);
68+
}
69+
public static PatcherConfig patcherConfig(InputStream stream) {
70+
return fromJson(stream, PatcherConfig.class);
71+
}
72+
public static PatcherConfig patcherConfig(byte[] data) {
73+
return fromJson(data, PatcherConfig.class);
74+
}
75+
76+
public static PatcherConfig.V2 patcherConfigV2(File file) {
77+
return fromJson(file, PatcherConfig.V2.class);
78+
}
79+
public static PatcherConfig.V2 patcherConfigV2(InputStream stream) {
80+
return fromJson(stream, PatcherConfig.V2.class);
81+
}
82+
public static PatcherConfig.V2 patcherConfigV2(byte[] data) {
83+
return fromJson(data, PatcherConfig.V2.class);
84+
}
85+
86+
public static MCPConfig mcpConfig(File file) {
87+
return fromJson(file, MCPConfig.class);
88+
}
89+
public static MCPConfig mcpConfig(InputStream stream) {
90+
return fromJson(stream, MCPConfig.class);
91+
}
92+
public static MCPConfig mcpConfig(byte[] data) {
93+
return fromJson(data, MCPConfig.class);
94+
}
95+
96+
public static MCPConfig.V2 mcpConfigV2(File file) {
97+
return fromJson(file, MCPConfig.V2.class);
98+
}
99+
public static MCPConfig.V2 mcpConfigV2(InputStream stream) {
100+
return fromJson(stream, MCPConfig.V2.class);
101+
}
102+
public static MCPConfig.V2 mcpConfigV2(byte[] data) {
103+
return fromJson(data, MCPConfig.V2.class);
104+
}
105+
106+
public static PromosSlim promosSlim(File file) {
107+
return fromJson(file, PromosSlim.class);
108+
}
109+
public static PromosSlim promosSlim(InputStream stream) {
110+
return fromJson(stream, PromosSlim.class);
111+
}
112+
public static PromosSlim promosSlim(byte[] data) {
113+
return fromJson(data, PromosSlim.class);
114+
}
115+
public static PromosSlim promosSlim(String data) {
116+
return fromJson(data, PromosSlim.class);
117+
}
118+
119+
protected static <T> T fromJson(File file, Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
47120
try (FileInputStream stream = new FileInputStream(file)) {
48121
return fromJson(stream, classOfT);
49122
} catch (IOException e) {
50123
throw new JsonIOException(e);
51124
}
52125
}
53-
private static <T> T fromJson(byte[] data, Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
126+
protected static <T> T fromJson(byte[] data, Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
54127
return fromJson(new ByteArrayInputStream(data), classOfT);
55128
}
56-
private static <T> T fromJson(InputStream stream, Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
129+
protected static <T> T fromJson(InputStream stream, Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
57130
return GSON.fromJson(new InputStreamReader(stream), classOfT);
58131
}
59-
private static <T> T fromJson(String data, Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
132+
protected static <T> T fromJson(String data, Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
60133
return GSON.fromJson(data, classOfT);
61134
}
62135

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) Forge Development LLC and contributors
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
package net.minecraftforge.util.data.json;
6+
7+
import java.util.Collections;
8+
import java.util.HashMap;
9+
import java.util.List;
10+
import java.util.Map;
11+
12+
// TODO: [MCMaven][Documentation] Document from MinecraftForge/MCPConfig
13+
public class MCPConfig extends Config {
14+
public String version; // Minecraft version
15+
public Map<String, Object> data;
16+
public Map<String, List<Map<String, String>>> steps;
17+
public Map<String, Function> functions;
18+
public Map<String, List<String>> libraries;
19+
20+
public Map<String, String> getData(String side) {
21+
if (data == null)
22+
return Collections.emptyMap();
23+
Map<String, String> ret = new HashMap<>();
24+
data.forEach((k, v) -> ret.put(k, (String)(v instanceof Map ? ((Map) v).get(side) : v)));
25+
return ret;
26+
}
27+
28+
public List<String> getLibraries(String side) {
29+
if (libraries == null)
30+
return Collections.emptyList();
31+
return libraries.getOrDefault(side, Collections.emptyList());
32+
}
33+
34+
public Function getFunction(String name) {
35+
return functions == null ? null : functions.get(name);
36+
}
37+
38+
public List<Map<String, String>> getSteps(String side) {
39+
var ret = this.steps == null ? null : this.steps.get(side);
40+
return ret == null ? Collections.emptyList() : ret;
41+
}
42+
43+
public record Function(
44+
String version,
45+
String repo,
46+
List<String> args,
47+
List<String> jvmargs,
48+
Integer java_version
49+
) {
50+
public int getJavaVersion(V2 parent) {
51+
return java_version == null ? parent.java_target : java_version;
52+
}
53+
}
54+
55+
public static class V2 extends MCPConfig {
56+
public boolean official = false;
57+
public int java_target = 8;
58+
public String encoding = "UTF-8";
59+
60+
public V2(MCPConfig o) {
61+
this.version = o.version;
62+
this.data = o.data;
63+
this.steps = o.steps;
64+
this.functions = o.functions;
65+
this.libraries = o.libraries;
66+
}
67+
}
68+
}

json-data-utils/src/main/java/net/minecraftforge/util/data/json/MinecraftVersion.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class MinecraftVersion {
2121
public Map<String, Download> downloads;
2222
/** The required libraries. */
2323
public Library[] libraries;
24+
/** The asset index reference. */
25+
public AssetsIndexInfo assetIndex;
2426

2527
public List<Lib> getLibs() {
2628
List<Lib> libs = new ArrayList<>();
@@ -118,4 +120,12 @@ public net.minecraftforge.util.data.OS toOS() {
118120
public @Nullable Download getDownload(String key) {
119121
return this.downloads == null ? null : this.downloads.get(key);
120122
}
123+
124+
public static class AssetsIndexInfo {
125+
public String id;
126+
public String sha1;
127+
public int size;
128+
public int totalSize;
129+
public String url;
130+
}
121131
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright (c) Forge Development LLC and contributors
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
package net.minecraftforge.util.data.json;
6+
7+
import net.minecraftforge.mcmaven.impl.util.Artifact;
8+
9+
import java.util.Collections;
10+
import java.util.List;
11+
import java.util.Map;
12+
13+
// TODO: [MCMaven][Documentation] Document from MinecraftForge/MCPConfig
14+
public class PatcherConfig extends Config {
15+
public String mcp; // Do not specify this unless there is no parent.
16+
public String parent; // To fully resolve, we must walk the parents until we hit null, and that one must specify a MCP value.
17+
public List<String> ats;
18+
public List<String> sass;
19+
public List<String> srgs;
20+
public List<String> srg_lines;
21+
public String binpatches; //To be applied to joined.jar, remapped, and added to the classpath
22+
public Function binpatcher;
23+
public String patches;
24+
public String sources;
25+
public String universal; //Injected into the final jar, TODO: [MCMaven][PatcherConfig] Make Universal Jar separate from main jar
26+
public List<String> libraries; //Additional libraries.
27+
public String inject;
28+
public Map<String, RunConfig> runs;
29+
public String sourceCompatibility; // Default to 1.8
30+
public String targetCompatibility; // Default to 1.8
31+
32+
public String getParent() {
33+
return this.hasParent() ? this.parent : this.mcp;
34+
}
35+
36+
public boolean hasParent() {
37+
return this.parent != null;
38+
}
39+
40+
public List<String> getAts() {
41+
return this.ats == null ? Collections.emptyList() : this.ats;
42+
}
43+
public List<String> getSASs() {
44+
return this.sass == null ? Collections.emptyList() : this.sass;
45+
}
46+
47+
public List<String> getMappings() {
48+
return this.srgs == null ? Collections.emptyList() : this.srgs;
49+
}
50+
51+
public List<String> getMappingLines() {
52+
return this.srg_lines == null ? Collections.emptyList() : this.srg_lines;
53+
}
54+
55+
public List<String> libraries() {
56+
return libraries == null ? Collections.emptyList() : libraries;
57+
}
58+
59+
public static class Function {
60+
public String version; //Maven artifact for the jar to run
61+
public String repo; //Maven repo to download the jar from
62+
public List<String> args;
63+
public List<String> jvmargs;
64+
public Integer java_version;
65+
66+
public int getJavaVersion(MCPConfig.V2 mcp) {
67+
return java_version != null ? java_version : mcp.java_target;
68+
}
69+
70+
public List<String> getArgs() {
71+
return this.args == null ? Collections.emptyList() : this.args;
72+
}
73+
74+
public List<String> getJvmArgs() {
75+
return this.jvmargs == null ? Collections.emptyList() : this.jvmargs;
76+
}
77+
}
78+
79+
public static class V2 extends PatcherConfig {
80+
public DataFunction processor;
81+
public String patchesOriginalPrefix;
82+
public String patchesModifiedPrefix;
83+
public Boolean notchObf; //This is a Boolean so we can set to null and it won't be printed in the json.
84+
public List<String> universalFilters;
85+
public List<String> modules; // Modules passed to --module-path
86+
public String sourceFileCharset; // = StandardCharsets.UTF_8.name();
87+
88+
public V2(PatcherConfig o) {
89+
this.mcp = o.mcp;
90+
this.parent = o.parent;
91+
this.ats = o.ats;
92+
this.sass = o.sass;
93+
this.srgs = o.srgs;
94+
this.srg_lines = o.srg_lines;
95+
this.binpatches = o.binpatches;
96+
this.binpatcher = o.binpatcher;
97+
this.patches = o.patches;
98+
this.sources = o.sources;
99+
this.universal = o.universal;
100+
this.libraries = o.libraries;
101+
this.inject = o.inject;
102+
this.runs = o.runs;
103+
this.sourceCompatibility = o.sourceCompatibility;
104+
this.targetCompatibility = o.targetCompatibility;
105+
}
106+
107+
public static class DataFunction extends Function {
108+
public Map<String, String> data;
109+
}
110+
111+
public boolean notchObf() {
112+
return this.notchObf != null && this.notchObf;
113+
}
114+
}
115+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) Forge Development LLC and contributors
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
package net.minecraftforge.util.data.json;
6+
7+
import java.util.ArrayList;
8+
import java.util.Collections;
9+
import java.util.List;
10+
import java.util.Map;
11+
12+
// TODO: [MCMaven][Documentation] Document from MinecraftForge/MinecraftForge
13+
public class PromosSlim {
14+
private String homepage;
15+
private Map<String, String> promos;
16+
private transient List<String> versions;
17+
18+
public Map<String, String> promos() {
19+
return promos == null ? Collections.emptyMap() : promos;
20+
}
21+
22+
public String homepage() {
23+
return this.homepage;
24+
}
25+
26+
public List<String> versions() {
27+
if (this.versions == null) {
28+
if (this.promos == null) {
29+
this.versions = Collections.emptyList();
30+
} else {
31+
List<String> tmp = new ArrayList<>();
32+
for (String key : promos.keySet()) {
33+
int idx = key.indexOf('-');
34+
if (idx == -1)
35+
continue;
36+
String ver = key.substring(0, idx) + '-' + promos.get(key);
37+
tmp.add(ver);
38+
}
39+
this.versions = tmp;
40+
}
41+
}
42+
return this.versions;
43+
}
44+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package net.minecraftforge.util.data.json;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
public class RunConfig {
7+
public String name;
8+
public String main;
9+
public List<String> parents;
10+
public List<String> args;
11+
public List<String> jvmArgs;
12+
public boolean client;
13+
public boolean buildAllProjects;
14+
public Map<String, String> env;
15+
public Map<String, String> props;
16+
}

0 commit comments

Comments
 (0)