2022-09-04 21:21:24 +02:00
|
|
|
package io.gitlab.jfronny.inceptum.launcher.api;
|
2021-10-30 14:22:07 +02:00
|
|
|
|
2022-11-24 21:11:07 +01:00
|
|
|
import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.fabric.FabricVersionLoaderInfo.GC_FabricVersionLoaderInfo;
|
2022-11-02 00:38:04 +01:00
|
|
|
import io.gitlab.jfronny.gson.compile.util.GList;
|
|
|
|
import io.gitlab.jfronny.gson.stream.JsonReader;
|
2022-09-04 21:21:24 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.common.Net;
|
2022-11-04 12:41:41 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.common.model.maven.ArtifactMeta;
|
2022-11-02 00:38:04 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.model.fabric.*;
|
2022-11-18 21:58:40 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.model.fabric.FabricVersionLoaderInfo.WithMeta.LauncherMeta.Libraries.Library;
|
2022-09-04 21:21:24 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.model.mojang.*;
|
2022-10-27 20:54:55 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.util.GameVersionParser;
|
2021-10-30 14:22:07 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2022-11-02 00:38:04 +01:00
|
|
|
import java.io.StringReader;
|
2022-09-04 21:21:24 +02:00
|
|
|
import java.util.*;
|
2021-10-30 14:22:07 +02:00
|
|
|
|
|
|
|
public class FabricMetaApi {
|
|
|
|
private static final String META_URL = "https://meta.fabricmc.net/";
|
|
|
|
|
|
|
|
public static List<FabricVersionLoaderInfo> getLoaderVersions(VersionsListInfo version) {
|
|
|
|
try {
|
2022-11-02 00:38:04 +01:00
|
|
|
return Net.downloadObject(META_URL + "v2/versions/loader/" + version.id, s -> {
|
|
|
|
try (JsonReader r = new JsonReader(new StringReader(s))) {
|
|
|
|
return GList.read(r, GC_FabricVersionLoaderInfo::read);
|
|
|
|
}
|
|
|
|
});
|
2021-10-30 14:22:07 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException("Could not get fabric loader versions", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-06 14:16:12 +01:00
|
|
|
public static FabricVersionLoaderInfo getLoaderVersion(String gameVersion, String fabricVersion) throws IOException {
|
2022-11-24 21:11:07 +01:00
|
|
|
return Net.downloadObject(META_URL + "v2/versions/loader/" + gameVersion + "/" + fabricVersion, GC_FabricVersionLoaderInfo.WithMeta::read);
|
2021-10-30 14:22:07 +02:00
|
|
|
}
|
|
|
|
|
2022-02-06 15:17:15 +01:00
|
|
|
public static VersionInfo addFabric(VersionInfo version, String fabricVersion, FabricVersionInfoType type) throws IOException {
|
2022-09-04 21:21:24 +02:00
|
|
|
VersionInfo result = version.clone();
|
2022-02-06 14:16:12 +01:00
|
|
|
FabricVersionLoaderInfo ver = getLoaderVersion(version.id, fabricVersion);
|
2022-09-04 21:21:24 +02:00
|
|
|
if (!(ver instanceof FabricVersionLoaderInfo.WithMeta verWithMeta))
|
|
|
|
throw new IOException("Doesn't hold metadata");
|
2021-10-30 14:22:07 +02:00
|
|
|
FabricVersionLoaderInfo.WithMeta.LauncherMeta meta = verWithMeta.launcherMeta;
|
|
|
|
if (meta.version != 1) throw new IOException("Unsupported fabric launcherMeta version: " + meta.version);
|
2022-02-06 15:17:15 +01:00
|
|
|
result.mainClass = type == FabricVersionInfoType.Server ? meta.mainClass.server : meta.mainClass.client;
|
2021-10-30 14:22:07 +02:00
|
|
|
List<VersionInfo.Library> libs = new ArrayList<>(version.libraries);
|
2022-11-18 21:58:40 +01:00
|
|
|
for (Library library : meta.libraries.common)
|
2021-10-30 14:22:07 +02:00
|
|
|
libs.add(convertLib(library));
|
2021-10-30 22:05:24 +02:00
|
|
|
if (type == FabricVersionInfoType.Client || type == FabricVersionInfoType.Both) {
|
2022-11-18 21:58:40 +01:00
|
|
|
for (Library library : meta.libraries.client)
|
2021-10-30 22:05:24 +02:00
|
|
|
libs.add(convertLib(library));
|
|
|
|
}
|
|
|
|
if (type == FabricVersionInfoType.Server || type == FabricVersionInfoType.Both) {
|
2022-11-18 21:58:40 +01:00
|
|
|
for (Library library : meta.libraries.server)
|
2021-10-30 22:05:24 +02:00
|
|
|
libs.add(convertLib(library));
|
|
|
|
}
|
2022-11-18 21:58:40 +01:00
|
|
|
libs.add(convertLib(new Library(
|
|
|
|
"net.fabricmc:fabric-loader:" + fabricVersion,
|
|
|
|
"https://maven.fabricmc.net/"
|
|
|
|
)));
|
|
|
|
libs.add(convertLib(new Library(
|
|
|
|
ver.intermediary.maven,
|
|
|
|
"https://maven.fabricmc.net/"
|
|
|
|
)));
|
2022-02-06 15:17:15 +01:00
|
|
|
result.libraries = List.copyOf(libs);
|
2022-10-28 14:56:44 +02:00
|
|
|
result.id = GameVersionParser.createVersionWithFabric(version.id, fabricVersion);
|
2022-02-06 15:17:15 +01:00
|
|
|
return result;
|
2021-10-30 14:22:07 +02:00
|
|
|
}
|
|
|
|
|
2022-11-18 21:58:40 +01:00
|
|
|
private static VersionInfo.Library convertLib(Library library) {
|
|
|
|
String path = ArtifactMeta.parse(library.name).getJarPath(true);
|
|
|
|
return new VersionInfo.Library(
|
|
|
|
new VersionInfo.Library.Downloads(
|
|
|
|
new VersionInfo.Library.Downloads.Artifact(
|
|
|
|
path,
|
|
|
|
-1,
|
|
|
|
null,
|
|
|
|
library.url + path
|
|
|
|
),
|
|
|
|
null
|
|
|
|
),
|
|
|
|
library.name,
|
|
|
|
new HashMap<>(),
|
|
|
|
new Rules(true)
|
|
|
|
);
|
2021-10-30 14:22:07 +02:00
|
|
|
}
|
2021-10-30 22:05:24 +02:00
|
|
|
|
|
|
|
public enum FabricVersionInfoType {
|
|
|
|
Client, Server, Both
|
|
|
|
}
|
2021-10-30 14:22:07 +02:00
|
|
|
}
|