Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -30,19 +31,24 @@ default Path getLibraryDir() {
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
}
}

Expand Down