diff options
| -rw-r--r-- | src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java | 2 | ||||
| -rw-r--r-- | src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java | 26 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java index f15a2a842c..2c0f4cfc29 100644 --- a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java +++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java @@ -10,7 +10,6 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; -import cpw.mods.modlauncher.Launcher; import io.github.zekerzhayard.forgewrapper.installer.detector.DetectorLoader; import io.github.zekerzhayard.forgewrapper.installer.detector.IFileDetector; import io.github.zekerzhayard.forgewrapper.installer.util.ModuleUtil; @@ -47,7 +46,6 @@ public class Main { try (URLClassLoader ucl = URLClassLoader.newInstance(new URL[] { Main.class.getProtectionDomain().getCodeSource().getLocation(), - Launcher.class.getProtectionDomain().getCodeSource().getLocation(), installerJar.toUri().toURL() }, ModuleUtil.getPlatformClassLoader())) { Class<?> installer = ucl.loadClass("io.github.zekerzhayard.forgewrapper.installer.Installer"); diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java index 1d3fb1f274..fc5f320539 100644 --- a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java +++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java @@ -1,12 +1,11 @@ package io.github.zekerzhayard.forgewrapper.installer.detector; +import java.net.URL; import java.net.URISyntaxException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; -import cpw.mods.modlauncher.Launcher; - public interface IFileDetector { /** * @return The name of the detector. @@ -29,7 +28,28 @@ public interface IFileDetector { return Paths.get(libraryDir).toAbsolutePath(); } try { - Path launcher = Paths.get(Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI()); + URL launcherLocation = null; + String[] classNames = { + "cpw.mods.modlauncher.Launcher", + "net.neoforged.fml.loading.FMLLoader" + }; + + for (String className : classNames) { + try { + Class<?> clazz = Class.forName(className); + // Return the location of the loaded class + if (clazz.getProtectionDomain().getCodeSource() != null) { + launcherLocation = clazz.getProtectionDomain().getCodeSource().getLocation(); + } + } catch (ClassNotFoundException e) { + // ignore and try next + } + } + + if (launcherLocation == null) { + throw new UnsupportedOperationException("Could not detect the libraries folder - it can be manually specified with `-Dforgewrapper.librariesDir=` (Java runtime argument)"); + } + Path launcher = Paths.get(launcherLocation.toURI()); while (!launcher.getFileName().toString().equals("libraries")) { launcher = launcher.getParent(); |
