summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheKodeToad <TheKodeToad@proton.me>2025-10-04 09:53:44 +0100
committerGitHub <noreply@github.com>2025-10-04 09:53:44 +0100
commitf56fd33f57a17ef7d893687c3698e41ae0e4fdcb (patch)
tree4d28ab88dd5a3927e1b0804b0080a8fb6cf608d0
parent9bcf6c591cb0147eac9b97d378bb8b67b9073ed5 (diff)
parent6f46a6f14278d69ebdb013a0c68d39f967a2fcf2 (diff)
downloadProject-Tick-f56fd33f57a17ef7d893687c3698e41ae0e4fdcb.tar.gz
Project-Tick-f56fd33f57a17ef7d893687c3698e41ae0e4fdcb.zip
Merge pull request #9 from Trial97/loader
Fix NeoForge 1.21.9
-rw-r--r--src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java2
-rw-r--r--src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java26
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();