Fix cloud in dev env

This commit is contained in:
Zoë
2022-07-05 14:17:44 -07:00
parent 639fc71f7a
commit b31f917acf
3 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package com.dfsek.terra.quilt;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
/**
* So you want to Mixin into Authlib/Brigadier/DataFixerUpper, on Fabric you'll need this guy.
*
* <p>YOU SHOULD ONLY USE THIS CLASS DURING "preLaunch" and ONLY TARGET A CLASS WHICH IS NOT ANY CLASS YOU MIXIN TO.
*
* This will likely not work on Gson because FabricLoader has some special logic related to Gson.
*/
public final class PreLaunchHacks {
private PreLaunchHacks() {}
private static final ClassLoader KNOT_CLASSLOADER = Thread.currentThread().getContextClassLoader();
private static final Method ADD_URL_METHOD;
static {
Method tempAddUrlMethod = null;
try {
tempAddUrlMethod = KNOT_CLASSLOADER.getClass().getMethod("addURL", URL.class);
tempAddUrlMethod.setAccessible(true);
} catch (ReflectiveOperationException e) {
throw new RuntimeException("Failed to load Classloader fields", e);
}
ADD_URL_METHOD = tempAddUrlMethod;
}
/**
* Hackily load the package which a mixin may exist within.
*
* YOU SHOULD NOT TARGET A CLASS WHICH YOU MIXIN TO.
*
* @param pathOfAClass The path of any class within the package.
*/
public static void hackilyLoadForMixin(String pathOfAClass) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException {
URL url = Class.forName(pathOfAClass).getProtectionDomain().getCodeSource().getLocation();
ADD_URL_METHOD.invoke(KNOT_CLASSLOADER, url);
}
}

View File

@@ -0,0 +1,22 @@
package com.dfsek.terra.quilt;
import cloud.commandframework.brigadier.BrigadierMappingBuilder;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.loader.api.entrypoint.PreLaunchEntrypoint;
import java.lang.reflect.InvocationTargetException;
public class QuiltPreLaunchEntryPoint implements PreLaunchEntrypoint {
@Override
public void onPreLaunch(ModContainer mod) {
if (QuiltLoader.isDevelopmentEnvironment()) {
try {
PreLaunchHacks.hackilyLoadForMixin(BrigadierMappingBuilder.class.getName());
} catch(ClassNotFoundException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
}

View File

@@ -23,6 +23,9 @@
"entrypoints": {
"init": [
"com.dfsek.terra.quilt.QuiltEntryPoint"
],
"pre_launch": [
"com.dfsek.terra.quilt.QuiltPreLaunchEntryPoint"
]
},
"depends": [