diff options
| author | TheKodeToad <TheKodeToad@proton.me> | 2025-10-07 11:29:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-07 11:29:41 +0100 |
| commit | a00a876058f3fd123b8ad9eb4a4f72c4d4450c86 (patch) | |
| tree | 802188cf3b93181a98461f36362b765a0687918c | |
| parent | f56fd33f57a17ef7d893687c3698e41ae0e4fdcb (diff) | |
| parent | 69d7b0e5a4c6ca0776ddd0b0cb495569f5b3eb0a (diff) | |
| download | Project-Tick-a00a876058f3fd123b8ad9eb4a4f72c4d4450c86.tar.gz Project-Tick-a00a876058f3fd123b8ad9eb4a4f72c4d4450c86.zip | |
Merge pull request #10 from Trial97/loader
fix: noeforge
| -rw-r--r-- | src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java | 26 |
1 files changed, 16 insertions, 10 deletions
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 fc5f320539..6f695ff884 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 @@ -2,6 +2,7 @@ package io.github.zekerzhayard.forgewrapper.installer.detector; import java.net.URL; import java.net.URISyntaxException; +import java.net.MalformedURLException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; @@ -30,19 +31,24 @@ public interface IFileDetector { try { URL launcherLocation = null; String[] classNames = { - "cpw.mods.modlauncher.Launcher", - "net.neoforged.fml.loading.FMLLoader" + "cpw/mods/modlauncher/Launcher.class", + "net/neoforged/fml/loading/FMLLoader.class" }; - 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(); + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + for (String classResource : classNames) { + URL url = cl.getResource(classResource); + if (url != null) { + String path = url.toString(); + if (path.startsWith("jar:") && path.contains("!")) { + path = path.substring(4, path.indexOf('!')); + try { + launcherLocation = new URL(path); + break; + } catch (MalformedURLException e) { + // ignore and try next + } } - } catch (ClassNotFoundException e) { - // ignore and try next } } |
