|
2 | 2 |
|
3 | 3 | import java.net.URL; |
4 | 4 | import java.net.URISyntaxException; |
| 5 | +import java.net.MalformedURLException; |
5 | 6 | import java.nio.file.Path; |
6 | 7 | import java.nio.file.Paths; |
7 | 8 | import java.util.HashMap; |
@@ -30,19 +31,24 @@ default Path getLibraryDir() { |
30 | 31 | try { |
31 | 32 | URL launcherLocation = null; |
32 | 33 | String[] classNames = { |
33 | | - "cpw.mods.modlauncher.Launcher", |
34 | | - "net.neoforged.fml.loading.FMLLoader" |
| 34 | + "cpw/mods/modlauncher/Launcher.class", |
| 35 | + "net/neoforged/fml/loading/FMLLoader.class" |
35 | 36 | }; |
36 | 37 |
|
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(); |
| 38 | + ClassLoader cl = Thread.currentThread().getContextClassLoader(); |
| 39 | + for (String classResource : classNames) { |
| 40 | + URL url = cl.getResource(classResource); |
| 41 | + if (url != null) { |
| 42 | + String path = url.toString(); |
| 43 | + if (path.startsWith("jar:") && path.contains("!")) { |
| 44 | + path = path.substring(4, path.indexOf('!')); |
| 45 | + try { |
| 46 | + launcherLocation = new URL(path); |
| 47 | + break; |
| 48 | + } catch (MalformedURLException e) { |
| 49 | + // ignore and try next |
| 50 | + } |
43 | 51 | } |
44 | | - } catch (ClassNotFoundException e) { |
45 | | - // ignore and try next |
46 | 52 | } |
47 | 53 | } |
48 | 54 |
|
|
0 commit comments