Fallback to fabric's experimental version manifest for versions that are not in the launchermeta.

This commit is contained in:
modmuss50
2021-07-16 23:22:03 +01:00
parent d271dfadd0
commit 69caaccb07
3 changed files with 92 additions and 1 deletions

View File

@@ -58,6 +58,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
private File minecraftServerJar;
private File minecraftMergedJar;
private File versionManifestJson;
private File experimentalVersionsJson;
public MinecraftProviderImpl(Project project) {
super(project);
@@ -116,6 +117,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
minecraftServerJar = new File(getDirectories().getUserCache(), "minecraft-" + minecraftVersion + "-server.jar");
minecraftMergedJar = new File(getDirectories().getUserCache(), "minecraft-" + minecraftVersion + "-merged.jar");
versionManifestJson = new File(getDirectories().getUserCache(), "version_manifest.json");
experimentalVersionsJson = new File(getDirectories().getUserCache(), "experimental_version_manifest.json");
}
private void downloadMcJson(boolean offline) throws IOException {
@@ -151,8 +153,12 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
getProject().getLogger().lifecycle("Using custom minecraft manifest");
}
if (!optionalVersion.isPresent()) {
if (optionalVersion.isEmpty()) {
optionalVersion = mcManifest.versions().stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst();
if (optionalVersion.isEmpty()) {
optionalVersion = findExperimentalVersion(offline);
}
}
if (optionalVersion.isPresent()) {
@@ -182,6 +188,29 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
}
}
// This attempts to find the version from fabric's own fallback version manifest json.
private Optional<ManifestVersion.Versions> findExperimentalVersion(boolean offline) throws IOException {
if (offline) {
if (!experimentalVersionsJson.exists()) {
getProject().getLogger().warn("Skipping download of experimental versions jsons due to being offline.");
return Optional.empty();
}
} else {
DownloadUtil.downloadIfChanged(new URL(Constants.EXPERIMENTAL_VERSIONS), experimentalVersionsJson, getProject().getLogger());
}
String expVersionManifest = Files.asCharSource(experimentalVersionsJson, StandardCharsets.UTF_8).read();
ManifestVersion expManifest = LoomGradlePlugin.OBJECT_MAPPER.readValue(expVersionManifest, ManifestVersion.class);
var result = expManifest.versions().stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst();
if (result.isPresent()) {
getProject().getLogger().lifecycle("Using fallback experimental version {}", minecraftVersion);
}
return result;
}
private boolean hasRecentValidManifest() throws IOException {
if (getExtension().getCustomManifest() != null) {
return false;

View File

@@ -36,6 +36,7 @@ public class Constants {
public static final String LIBRARIES_BASE = "https://libraries.minecraft.net/";
public static final String RESOURCES_BASE = "https://resources.download.minecraft.net/";
public static final String VERSION_MANIFESTS = "https://launchermeta.mojang.com/mc/game/version_manifest_v2.json";
public static final String EXPERIMENTAL_VERSIONS = "https://maven.fabricmc.net/net/minecraft/experimental_versions.json";
public static final String SYSTEM_ARCH = System.getProperty("os.arch").equals("64") ? "64" : "32";