Support 21w39a

dev/0.11
modmuss50 2021-09-29 19:33:04 +01:00
parent f33637aa3c
commit da66abfaef
2 changed files with 60 additions and 3 deletions

View File

@ -27,10 +27,15 @@ package net.fabricmc.loom.configuration.providers;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.StandardCopyOption;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import com.google.common.io.Files;
import org.gradle.api.GradleException;
@ -57,7 +62,10 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
private File workingDir;
private File minecraftJson;
private File minecraftClientJar;
// Note this will be the boostrap jar starting with 21w39a
private File minecraftServerJar;
// The extracted server jar from the boostrap, only exists in >=21w39a
private File minecraftExtractedServerJar;
private File minecraftMergedJar;
private File versionManifestJson;
private File experimentalVersionsJson;
@ -116,6 +124,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
minecraftJson = file("minecraft-info.json");
minecraftClientJar = file("minecraft-client.jar");
minecraftServerJar = file("minecraft-server.jar");
minecraftExtractedServerJar = file("minecraft-extracted_server.jar");
minecraftMergedJar = file("minecraft-merged.jar");
versionManifestJson = new File(getDirectories().getUserCache(), "version_manifest.json");
experimentalVersionsJson = new File(getDirectories().getUserCache(), "experimental_version_manifest.json");
@ -248,12 +257,60 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
private void mergeJars(Logger logger) throws IOException {
logger.info(":merging jars");
try (JarMerger jarMerger = new JarMerger(minecraftClientJar, minecraftServerJar, minecraftMergedJar)) {
try (JarMerger jarMerger = new JarMerger(minecraftClientJar, getServerJarToMerge(logger), minecraftMergedJar)) {
jarMerger.enableSyntheticParamsOffset();
jarMerger.merge();
}
}
private File getServerJarToMerge(Logger logger) throws IOException {
try (ZipFile zipFile = new ZipFile(minecraftServerJar)) {
ZipEntry versionsListEntry = zipFile.getEntry("META-INF/versions.list");
if (versionsListEntry == null) {
// Legacy pre 21w38a jar
return minecraftServerJar;
}
logger.info(":Extracting server jar from bootstrap");
String versionsList;
try (InputStream is = zipFile.getInputStream(versionsListEntry)) {
versionsList = new String(is.readAllBytes(), StandardCharsets.UTF_8);
}
String jarPath = null;
for (String version : versionsList.split("\n")) {
if (version.isBlank()) continue;
String[] split = version.split("\t");
if (split.length != 3) continue;
final String hash = split[0];
final String id = split[1];
final String path = split[2];
if (minecraftVersion().equals(id)) {
jarPath = path;
break;
}
}
Objects.requireNonNull(jarPath, "Could not find minecraft server jar for " + minecraftVersion());
ZipEntry serverJarEntry = zipFile.getEntry("META-INF/versions/" + jarPath);
Objects.requireNonNull(serverJarEntry, "Could not find server jar in boostrap@ " + jarPath);
try (InputStream is = zipFile.getInputStream(serverJarEntry)) {
java.nio.file.Files.copy(is, minecraftExtractedServerJar.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
return minecraftExtractedServerJar;
}
}
public File getMergedJar() {
return minecraftMergedJar;
}

View File

@ -1,7 +1,7 @@
org.gradle.jvmargs=-Xmx1G
minecraft_version=21w38a
yarn_mappings=21w38a+build.9
minecraft_version=21w39a
yarn_mappings=21w39a+build.1
loader_version=0.11.7
fabric_version=0.40.4+1.18