Skip to content

Commit 4979cb0

Browse files
Trial97peterix
authored andcommitted
fix: noeforge 1.21.9
Signed-off-by: Trial97 <[email protected]> Signed-off-by: Petr Mrázek <[email protected]>
1 parent 838de7a commit 4979cb0

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.stream.Collectors;
1111
import java.util.stream.Stream;
1212

13-
import cpw.mods.modlauncher.Launcher;
1413
import io.github.zekerzhayard.forgewrapper.installer.detector.DetectorLoader;
1514
import io.github.zekerzhayard.forgewrapper.installer.detector.IFileDetector;
1615
import io.github.zekerzhayard.forgewrapper.installer.util.ModuleUtil;
@@ -47,7 +46,6 @@ public static void main(String[] args) throws Throwable {
4746

4847
try (URLClassLoader ucl = URLClassLoader.newInstance(new URL[] {
4948
Main.class.getProtectionDomain().getCodeSource().getLocation(),
50-
Launcher.class.getProtectionDomain().getCodeSource().getLocation(),
5149
installerJar.toUri().toURL()
5250
}, ModuleUtil.getPlatformClassLoader())) {
5351
Class<?> installer = ucl.loadClass("io.github.zekerzhayard.forgewrapper.installer.Installer");

src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package io.github.zekerzhayard.forgewrapper.installer.detector;
22

3+
import java.net.URL;
34
import java.net.URISyntaxException;
45
import java.nio.file.Path;
56
import java.nio.file.Paths;
67
import java.util.HashMap;
78

8-
import cpw.mods.modlauncher.Launcher;
9-
109
public interface IFileDetector {
1110
/**
1211
* @return The name of the detector.
@@ -29,7 +28,28 @@ default Path getLibraryDir() {
2928
return Paths.get(libraryDir).toAbsolutePath();
3029
}
3130
try {
32-
Path launcher = Paths.get(Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI());
31+
URL launcherLocation = null;
32+
String[] classNames = {
33+
"cpw.mods.modlauncher.Launcher",
34+
"net.neoforged.fml.loading.FMLLoader"
35+
};
36+
37+
for (String className : classNames) {
38+
try {
39+
Class<?> clazz = Class.forName(className);
40+
// Return the location of the loaded class
41+
if (clazz.getProtectionDomain().getCodeSource() != null) {
42+
launcherLocation = clazz.getProtectionDomain().getCodeSource().getLocation();
43+
}
44+
} catch (ClassNotFoundException e) {
45+
// ignore and try next
46+
}
47+
}
48+
49+
if (launcherLocation == null) {
50+
throw new UnsupportedOperationException("Could not detect the libraries folder - it can be manually specified with `-Dforgewrapper.librariesDir=` (Java runtime argument)");
51+
}
52+
Path launcher = Paths.get(launcherLocation.toURI());
3353

3454
while (!launcher.getFileName().toString().equals("libraries")) {
3555
launcher = launcher.getParent();

0 commit comments

Comments
 (0)