class loading seems to work again like this
This commit is contained in:
parent
0b55824be0
commit
8a75f71ab4
|
@ -16,8 +16,6 @@ import java.util.Map;
|
|||
|
||||
import io.github.moehreag.nonsense.loader.impl.mixin.NonsenseMixinService;
|
||||
import lombok.Getter;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.spongepowered.asm.launch.MixinBootstrap;
|
||||
import org.spongepowered.asm.service.IPropertyKey;
|
||||
|
||||
|
@ -37,7 +35,6 @@ public class Launcher {
|
|||
private final Env env;
|
||||
|
||||
public static void run(String[] args, Env env) {
|
||||
//Configurator.setRootLevel(Level.INFO); // TODO replace with actual log4j config
|
||||
new Launcher(args, env);
|
||||
}
|
||||
|
||||
|
@ -63,9 +60,11 @@ public class Launcher {
|
|||
MixinBootstrap.init();
|
||||
|
||||
try {
|
||||
MethodHandle ctor = MethodHandles.publicLookup().findStatic(targetClassLoader.loadClass(LoaderImpl.class.getName()), "run", MethodType.methodType(void.class, String[].class, Env.class));
|
||||
Class<?> clazz = targetClassLoader.findClass("io.github.moehreag.nonsense.loader.impl.LoaderImpl");
|
||||
MethodHandle ctor = MethodHandles.publicLookup().findStatic(clazz, "run", MethodType.methodType(void.class, String[].class, Env.class));
|
||||
ctor.invoke(args, env);
|
||||
} catch (Throwable e) {
|
||||
// TODO
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public class LoaderImpl implements Loader {
|
|||
|
||||
classes.stream().map((String className) -> {
|
||||
try {
|
||||
return Class.forName(className);
|
||||
return classloader.findClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// TODO error handling
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
@ -15,15 +15,15 @@ public class MixinClassloader extends URLClassLoader {
|
|||
super.addURL(url);
|
||||
}
|
||||
|
||||
public boolean isClassLoaded(String name){
|
||||
return findLoadedClass(name) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
return super.findClass(name);
|
||||
}
|
||||
|
||||
public boolean isClassLoaded(String name){
|
||||
return findLoadedClass(name) != null;
|
||||
}
|
||||
|
||||
public byte[] getClassBytes(String name) throws IOException {
|
||||
String binName = name.replace(".", "/");
|
||||
String path = binName.concat(".class");
|
||||
|
@ -34,4 +34,5 @@ public class MixinClassloader extends URLClassLoader {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -57,18 +57,25 @@ public class Minecraft implements NonsensePlugin {
|
|||
}).forEach(LoaderImpl.getInstance().getClassloader()::addURL);
|
||||
LOGGER.info("Found {} mods", mods.size());
|
||||
|
||||
if (!Files.exists(remappedGamePath)){
|
||||
Path gameJar = findGame();
|
||||
if (gameJar == null){
|
||||
throw new IllegalStateException("Could not find game jar!");
|
||||
}
|
||||
if (!Files.exists(remappedGamePath)){
|
||||
try {
|
||||
|
||||
MojMapPatcher.run(version, gameJar, remappedGamePath);
|
||||
} catch (IOException e) {
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
LoaderImpl.getInstance().getClassloader().addURL(remappedGamePath.toUri().toURL());
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Path findGame() {
|
||||
|
@ -102,6 +109,8 @@ public class Minecraft implements NonsensePlugin {
|
|||
Class<?> mainClass = Class.forName(foundMainClass);
|
||||
MethodHandle main = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
|
||||
main.invoke((Object) LoaderImpl.getInstance().getArgs());
|
||||
} else {
|
||||
LOGGER.warn("Failed to locate main class!");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Reference in a new issue