Primitive capability for tweakers to order. Add a "TweakOrder" integer

property to your manifest, or accept the default of zero.
This commit is contained in:
Christian 2013-10-12 10:27:06 -04:00
parent efead4d200
commit 5e03f2e85b
2 changed files with 25 additions and 6 deletions

View file

@ -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<String, String> launchArgs;
private List<String> standaloneArgs;
private static URI jarLocation;
private List<Integer> sortOrderValues = Lists.newArrayList();
@Override
public void acceptOptions(List<String> 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<String> tweakClasses = (List<String>) 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);
}
}

View file

@ -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));
}
}