From 5e03f2e85b5d0de403e67969e1a1cd694ae854a6 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 12 Oct 2013 10:27:06 -0400 Subject: [PATCH] Primitive capability for tweakers to order. Add a "TweakOrder" integer property to your manifest, or accept the default of zero. --- .../mods/fml/common/launcher/FMLTweaker.java | 20 +++++++++++++++++-- .../mods/fml/relauncher/CoreModManager.java | 11 ++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/fml/common/cpw/mods/fml/common/launcher/FMLTweaker.java b/fml/common/cpw/mods/fml/common/launcher/FMLTweaker.java index c86e21a97..ed13b355a 100644 --- a/fml/common/cpw/mods/fml/common/launcher/FMLTweaker.java +++ b/fml/common/cpw/mods/fml/common/launcher/FMLTweaker.java @@ -22,6 +22,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.ObjectArrays; +import com.google.common.primitives.Ints; import cpw.mods.fml.relauncher.FMLLaunchHandler; @@ -37,6 +38,7 @@ public class FMLTweaker implements ITweaker { private Map launchArgs; private List standaloneArgs; private static URI jarLocation; + private List sortOrderValues = Lists.newArrayList(); @Override public void acceptOptions(List args, File gameDir, File assetsDir, String profile) @@ -156,10 +158,24 @@ public class FMLTweaker implements ITweaker { return jarLocation; } - public void injectCascadingTweak(String tweakClassName) + public void injectCascadingTweak(String tweakClassName, Integer sortingOrder) { List tweakClasses = (List) Launch.blackboard.get("TweakClasses"); - tweakClasses.add(tweakClassName); + if (tweakClasses.size() != sortOrderValues.size()) + { + throw new RuntimeException("Sort ordering mismatch!"); + } + int i = 0; + for (i = 0; i < sortOrderValues.size(); i++) + { + Integer sort = sortOrderValues.get(i); + if (sort.compareTo(sortingOrder) > 0) + { + break; + } + } + tweakClasses.add(i, tweakClassName); + sortOrderValues.add(i, sortingOrder); } } diff --git a/fml/common/cpw/mods/fml/relauncher/CoreModManager.java b/fml/common/cpw/mods/fml/relauncher/CoreModManager.java index cad8e8ed5..5c3e2fc7c 100644 --- a/fml/common/cpw/mods/fml/relauncher/CoreModManager.java +++ b/fml/common/cpw/mods/fml/relauncher/CoreModManager.java @@ -37,6 +37,7 @@ import com.google.common.base.Throwables; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.ObjectArrays; +import com.google.common.primitives.Ints; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.launcher.FMLTweaker; @@ -200,7 +201,9 @@ public class CoreModManager if (cascadedTweaker != null) { FMLRelaunchLog.info("Loading tweaker %s from %s", cascadedTweaker, coreMod.getName()); - handleCascadingTweak(coreMod, jar, cascadedTweaker, classLoader); + Integer sortOrder = Ints.tryParse(mfAttributes.getValue("TweakOrder")); + sortOrder = (sortOrder == null ? Integer.valueOf(0) : sortOrder); + handleCascadingTweak(coreMod, jar, cascadedTweaker, classLoader, sortOrder); loadedCoremods.add(coreMod.getName()); continue; } @@ -237,7 +240,7 @@ public class CoreModManager } private static Method ADDURL; - private static void handleCascadingTweak(File coreMod, JarFile jar, String cascadedTweaker, LaunchClassLoader classLoader) + private static void handleCascadingTweak(File coreMod, JarFile jar, String cascadedTweaker, LaunchClassLoader classLoader, Integer sortingOrder) { try { @@ -249,7 +252,7 @@ public class CoreModManager } ADDURL.invoke(classLoader.getClass().getClassLoader(), coreMod.toURI().toURL()); classLoader.addURL(coreMod.toURI().toURL()); - CoreModManager.tweaker.injectCascadingTweak(cascadedTweaker); + CoreModManager.tweaker.injectCascadingTweak(cascadedTweaker, sortingOrder); } catch (Exception e) { @@ -452,6 +455,6 @@ public class CoreModManager } Launch.blackboard.put("fml.deobfuscatedEnvironment", deobfuscatedEnvironment); - tweaker.injectCascadingTweak("cpw.mods.fml.common.launcher.FMLDeobfTweaker"); + tweaker.injectCascadingTweak("cpw.mods.fml.common.launcher.FMLDeobfTweaker", Integer.valueOf(1000)); } }