Skip to content

Commit 216fb5d

Browse files
committed
Properly load mixins without a coremod
* Fixes a bug in which mods that specified the mixin tweaker, but had no coremod, and no late/early mixin annotations, would not be considered as mixin candidates * Gracefully handle DiscovererV1 (mainly for in-dev testing)
1 parent 77eaec4 commit 216fb5d

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

gradle.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ usesMavenPublishing = true
134134
#
135135
# The project's ID on Modrinth. Can be either the slug or the ID.
136136
# Leave this empty if you don't want to publish to Modrinth.
137-
modrinthProjectId =
137+
modrinthProjectId = jarjar
138138

139139
# The project's relations on Modrinth. You can use this to refer to other projects on Modrinth.
140140
# Syntax: scope1-type1:name1;scope2-type2:name2;...
@@ -143,21 +143,21 @@ modrinthProjectId =
143143
# and the name is the Modrinth project or version slug/id of the other mod.
144144
# Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech
145145
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
146-
modrinthRelations =
146+
modrinthRelations = required-project:lwjgl3ify
147147

148148
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.
149149
#
150150
# The project's numeric ID on CurseForge. You can find this in the About Project box.
151151
# Leave this empty if you don't want to publish on CurseForge.
152-
curseForgeProjectId =
152+
curseForgeProjectId = 1215676
153153

154154
# The project's relations on CurseForge. You can use this to refer to other projects on CurseForge.
155155
# Syntax: type1:name1;type2:name2;...
156156
# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
157157
# and the name is the CurseForge project slug of the other mod.
158158
# Example: requiredDependency:railcraft;embeddedLibrary:cofhlib;incompatible:buildcraft
159159
# Note: UniMixins is automatically set as a required dependency if usesMixins = true.
160-
curseForgeRelations =
160+
curseForgeRelations = requiredDependency:lwjgl3ify
161161

162162
# Optional parameter to customize the produced artifacts. Use this to preserve artifact naming when migrating older
163163
# projects. New projects should not use this parameter.

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ pluginManagement {
1717
}
1818

1919
plugins {
20-
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.36'
20+
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.37'
2121
}

src/main/java/com/mitchej123/jarjar/fml/common/discovery/asm/ModClassVisitorV2.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ public ModClassVisitorV2(ASMModParser discoverer) {
3131
if(discoverer instanceof ASMModParserV2 discovererV2) {
3232
this.discovererV2 = discovererV2;
3333
} else {
34-
throw new IllegalArgumentException("ASMModParser must be an instance of ASMModParserV2");
34+
this.discovererV2 = null;
3535
}
36-
3736
}
3837

3938
@Override
4039
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
41-
discovererV2.beginNewTypeName(name, version, superName, interfaces);
40+
if(discovererV2 != null) {
41+
discovererV2.beginNewTypeName(name, version, superName, interfaces);
42+
} else {
43+
super.visit(version, access, name, signature, superName, interfaces);
44+
}
4245
}
4346

4447
}

src/main/java/com/mitchej123/jarjar/fml/relauncher/CoreModManagerV2.java

+31-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.IOException;
2929
import java.lang.reflect.Field;
3030
import java.lang.reflect.InvocationTargetException;
31+
import java.lang.reflect.Method;
3132
import java.net.MalformedURLException;
3233
import java.net.URL;
3334
import java.net.URLClassLoader;
@@ -262,6 +263,7 @@ public static void discoverCoreMods(File mcDir, LaunchClassLoader classLoader) {
262263
}
263264
}
264265
}
266+
private static final Set<String> injectedURLS = new HashSet<>();
265267

266268
private static void loadTweakersAndCoreMods(File mcDir, LaunchClassLoader classLoader) {
267269
FMLRelaunchLog.fine("Loading Tweakers and coremods");
@@ -278,6 +280,7 @@ private static void loadTweakersAndCoreMods(File mcDir, LaunchClassLoader classL
278280
modCandidates.clear();
279281
modCandidates.addAll(resolvedCandidates.get());
280282

283+
boolean injectMixins = false;
281284

282285
for (ModCandidateV2 candidate : modCandidates) {
283286
final File modFile = candidate.getModContainer();
@@ -289,7 +292,20 @@ private static void loadTweakersAndCoreMods(File mcDir, LaunchClassLoader classL
289292
FMLRelaunchLog.info("Tweaker is %s", candidate.getTweaker());
290293
handleCascadingTweak(modFile, null, candidate.getTweaker(), classLoader, candidate.getSortOrder());
291294
if ("org.spongepowered.asm.launch.MixinTweaker".equals(candidate.getTweaker())) {
292-
injectMixinTweaker(classLoader, mcDir, FMLInjectionData.mccversion);
295+
injectMixins = true;
296+
try {
297+
if(injectedURLS.add(modFile.getName())) {
298+
// Have to manually stuff the tweaker into the parent classloader
299+
getADDURL().invoke(classLoader.getClass().getClassLoader(), modFile.toURI().toURL());
300+
}
301+
} catch (IllegalAccessException | InvocationTargetException | MalformedURLException | NoSuchMethodException e) {
302+
throw new RuntimeException(e);
303+
}
304+
try {
305+
classLoader.addURL(modFile.toURI().toURL());
306+
} catch (MalformedURLException e) {
307+
FMLRelaunchLog.log(Level.ERROR, e, "Unable to convert file into a URL. weird");
308+
}
293309
}
294310

295311
if (!candidate.containsMod()) {
@@ -316,6 +332,9 @@ private static void loadTweakersAndCoreMods(File mcDir, LaunchClassLoader classL
316332
loadCoreMod(classLoader, candidate.getCoreMod(), modFile);
317333
}
318334
}
335+
if(injectMixins) {
336+
injectMixinTweaker(classLoader, mcDir, FMLInjectionData.mccversion);
337+
}
319338
modCandidates.clear();
320339
}
321340

@@ -357,14 +376,20 @@ private static void addModAccessTransformers(Map<String, String> atMap) {
357376
}
358377
}
359378

379+
public static Method getADDURL() throws NoSuchMethodException {
380+
if (ADDURL == null) {
381+
ADDURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
382+
ADDURL.setAccessible(true);
383+
}
384+
385+
return ADDURL;
386+
387+
}
388+
360389
public static void handleCascadingTweak(File coreMod, JarFile jar, String cascadedTweaker, LaunchClassLoader classLoader, Integer sortingOrder) {
361390
try {
362391
// Have to manually stuff the tweaker into the parent classloader
363-
if (ADDURL == null) {
364-
ADDURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
365-
ADDURL.setAccessible(true);
366-
}
367-
ADDURL.invoke(classLoader.getClass().getClassLoader(), coreMod.toURI().toURL());
392+
getADDURL().invoke(classLoader.getClass().getClassLoader(), coreMod.toURI().toURL());
368393
classLoader.addURL(coreMod.toURI().toURL());
369394
CoreModManager.tweaker.injectCascadingTweak(cascadedTweaker);
370395
tweakSorting.put(cascadedTweaker, sortingOrder);

0 commit comments

Comments
 (0)