28
28
import java .io .IOException ;
29
29
import java .lang .reflect .Field ;
30
30
import java .lang .reflect .InvocationTargetException ;
31
+ import java .lang .reflect .Method ;
31
32
import java .net .MalformedURLException ;
32
33
import java .net .URL ;
33
34
import java .net .URLClassLoader ;
@@ -262,6 +263,7 @@ public static void discoverCoreMods(File mcDir, LaunchClassLoader classLoader) {
262
263
}
263
264
}
264
265
}
266
+ private static final Set <String > injectedURLS = new HashSet <>();
265
267
266
268
private static void loadTweakersAndCoreMods (File mcDir , LaunchClassLoader classLoader ) {
267
269
FMLRelaunchLog .fine ("Loading Tweakers and coremods" );
@@ -278,6 +280,7 @@ private static void loadTweakersAndCoreMods(File mcDir, LaunchClassLoader classL
278
280
modCandidates .clear ();
279
281
modCandidates .addAll (resolvedCandidates .get ());
280
282
283
+ boolean injectMixins = false ;
281
284
282
285
for (ModCandidateV2 candidate : modCandidates ) {
283
286
final File modFile = candidate .getModContainer ();
@@ -289,7 +292,20 @@ private static void loadTweakersAndCoreMods(File mcDir, LaunchClassLoader classL
289
292
FMLRelaunchLog .info ("Tweaker is %s" , candidate .getTweaker ());
290
293
handleCascadingTweak (modFile , null , candidate .getTweaker (), classLoader , candidate .getSortOrder ());
291
294
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
+ }
293
309
}
294
310
295
311
if (!candidate .containsMod ()) {
@@ -316,6 +332,9 @@ private static void loadTweakersAndCoreMods(File mcDir, LaunchClassLoader classL
316
332
loadCoreMod (classLoader , candidate .getCoreMod (), modFile );
317
333
}
318
334
}
335
+ if (injectMixins ) {
336
+ injectMixinTweaker (classLoader , mcDir , FMLInjectionData .mccversion );
337
+ }
319
338
modCandidates .clear ();
320
339
}
321
340
@@ -357,14 +376,20 @@ private static void addModAccessTransformers(Map<String, String> atMap) {
357
376
}
358
377
}
359
378
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
+
360
389
public static void handleCascadingTweak (File coreMod , JarFile jar , String cascadedTweaker , LaunchClassLoader classLoader , Integer sortingOrder ) {
361
390
try {
362
391
// 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 ());
368
393
classLoader .addURL (coreMod .toURI ().toURL ());
369
394
CoreModManager .tweaker .injectCascadingTweak (cascadedTweaker );
370
395
tweakSorting .put (cascadedTweaker , sortingOrder );
0 commit comments