From 6f46a6f14278d69ebdb013a0c68d39f967a2fcf2 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sat, 4 Oct 2025 00:06:37 +0300 Subject: [PATCH] fix: noeforge 1.21.9 Signed-off-by: Trial97 --- .../forgewrapper/installer/Main.java | 2 -- .../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 f15a2a8..2c0f4cf 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.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 static void main(String[] args) throws Throwable { 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 1d3fb1f..fc5f320 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 @@ default Path getLibraryDir() { 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();