fix: use SRG client jar for securejarhandler minecraft module
ensureVersionJarForForge() was copying the vanilla Mojang jar (obfuscated class names) to versions/<forgeId>/<forgeId>.jar. securejarhandler creates the minecraft module from this jar, but obfuscated names dont match SRG names like PreparableReloadListener. The package is claimed by the module but class is not found → crash. Now prioritizes the SRG-mapped client jar from Forge libraries (client-*-srg.jar) which has Automatic-Module-Name: minecraft and correct SRG class names. Falls back to vanilla jar only if SRG jar is not found. Also removed redundant -DlibraryDirectory already in manifest args.
This commit is contained in:
+51
-17
@@ -125,7 +125,6 @@ public class LaunchCommandBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
command.add("-DlibraryDirectory=" + instance.getPath().resolve("libraries").toAbsolutePath());
|
|
||||||
command.add(getVanillaMainClass());
|
command.add(getVanillaMainClass());
|
||||||
command.addAll(getVanillaGameArguments(options));
|
command.addAll(getVanillaGameArguments(options));
|
||||||
command.addAll(getModloaderLaunchArgs());
|
command.addAll(getModloaderLaunchArgs());
|
||||||
@@ -674,17 +673,15 @@ public class LaunchCommandBuilder {
|
|||||||
* Ensure the version jar exists at versions/<versionId>/<versionId>.jar
|
* Ensure the version jar exists at versions/<versionId>/<versionId>.jar
|
||||||
* so that securejarhandler can create the "minecraft" module from it.
|
* so that securejarhandler can create the "minecraft" module from it.
|
||||||
*
|
*
|
||||||
* The Forge installer only creates the JSON at that path, not the jar.
|
* The version jar MUST contain SRG-mapped classes (not obfuscated Mojang
|
||||||
* We copy the vanilla version jar (e.g. versions/1.20.1/1.20.1.jar) there.
|
* names) and have Automatic-Module-Name: minecraft in its MANIFEST.MF.
|
||||||
|
* Without this, securejarhandler creates an automatic module from the
|
||||||
|
* filename, claims the net.minecraft.server.packs.resources package, but
|
||||||
|
* doesn't have SRG-named classes like PreparableReloadListener → crash.
|
||||||
*
|
*
|
||||||
* securejarhandler reads Automatic-Module-Name: minecraft from the jar's
|
* Priority:
|
||||||
* MANIFEST.MF and creates a named "minecraft" module. This is the module
|
* 1. SRG-mapped client jar from Forge libraries (client-*-srg.jar)
|
||||||
* that Forge's code expects classes like PreparableReloadListener to be in.
|
* 2. Vanilla version jar (fallback, may cause module issues)
|
||||||
*
|
|
||||||
* Critical: the jar is NOT put on -cp. Only the copy at versions/<versionId>/
|
|
||||||
* is used by securejarhandler. The original 1.20.1.jar must stay off the
|
|
||||||
* classpath to prevent automatic module _1._20._1 from being created,
|
|
||||||
* which would conflict with the "minecraft" module (split-package error).
|
|
||||||
*/
|
*/
|
||||||
private void ensureVersionJarForForge() throws IOException {
|
private void ensureVersionJarForForge() throws IOException {
|
||||||
String versionId = getVersionId();
|
String versionId = getVersionId();
|
||||||
@@ -699,16 +696,53 @@ public class LaunchCommandBuilder {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Source: the vanilla version jar
|
Files.createDirectories(targetDir);
|
||||||
Path sourceJar = versionsDir.resolve(mcVersion).resolve(mcVersion + ".jar");
|
|
||||||
if (!Files.exists(sourceJar) || !isValidJar(sourceJar)) {
|
// Priority 1: SRG-mapped client jar from Forge libraries
|
||||||
System.out.println(ZAnsi.yellow(" Vanilla version jar not found at " + sourceJar));
|
// This jar has Automatic-Module-Name: minecraft and correct SRG class names
|
||||||
|
Path srgJar = findSrgClientJar();
|
||||||
|
if (srgJar != null && isValidJar(srgJar)) {
|
||||||
|
Files.copy(srgJar, targetJar);
|
||||||
|
System.out.println(ZAnsi.green(" Copied SRG client jar for securejarhandler: " + srgJar.getFileName() + " → " + targetJar));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: vanilla version jar (obfuscated names, may cause module issues)
|
||||||
|
Path sourceJar = versionsDir.resolve(mcVersion).resolve(mcVersion + ".jar");
|
||||||
|
if (!Files.exists(sourceJar) || !isValidJar(sourceJar)) {
|
||||||
|
System.out.println(ZAnsi.yellow(" No suitable version jar found (SRG or vanilla)"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Files.createDirectories(targetDir);
|
|
||||||
Files.copy(sourceJar, targetJar);
|
Files.copy(sourceJar, targetJar);
|
||||||
System.out.println(ZAnsi.green(" Copied version jar for securejarhandler: " + sourceJar.getFileName() + " → " + targetJar));
|
System.out.println(ZAnsi.yellow(" Copied vanilla jar (fallback) for securejarhandler: " + sourceJar.getFileName() + " → " + targetJar));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the SRG-mapped client jar in Forge libraries.
|
||||||
|
* Path: libraries/net/minecraftforge/client/<mcVersion>-<mcpVersion>/client-<mcVersion>-<mcpVersion>-srg.jar
|
||||||
|
* This jar contains SRG-mapped classes and has Automatic-Module-Name: minecraft.
|
||||||
|
*/
|
||||||
|
private Path findSrgClientJar() {
|
||||||
|
Path librariesDir = instance.getPath().resolve("libraries");
|
||||||
|
Path mcDir = librariesDir.resolve("net/minecraftforge/client");
|
||||||
|
if (!Files.exists(mcDir)) return null;
|
||||||
|
|
||||||
|
String mcVersion = instance.getMinecraftVersion();
|
||||||
|
try (var stream = Files.list(mcDir)) {
|
||||||
|
return stream
|
||||||
|
.filter(Files::isDirectory)
|
||||||
|
.filter(dir -> dir.getFileName().toString().startsWith(mcVersion + "-"))
|
||||||
|
.flatMap(dir -> {
|
||||||
|
try { return Files.list(dir); } catch (Exception e) { return java.util.stream.Stream.empty(); }
|
||||||
|
})
|
||||||
|
.filter(p -> p.getFileName().toString().endsWith("-srg.jar"))
|
||||||
|
.filter(this::isValidJar)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user