mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-18 03:25:10 +00:00
Port TCon to use the v2 loader infrastructure from Mantle
This commit is contained in:
1 parent
a3aa7c2380
commit
891086dca4
9 files changed
+88
-241
No files matched your search
@@ -1,133 +1,29 @@
|
||||
package tconstruct.plugins;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import tconstruct.TConstruct;
|
||||
import static tconstruct.TConstruct.moduleLoader;
|
||||
import tconstruct.plugins.fmp.ForgeMultiPart;
|
||||
import tconstruct.plugins.ic2.IC2;
|
||||
import tconstruct.plugins.imc.AppEng;
|
||||
import tconstruct.plugins.imc.BuildcraftTransport;
|
||||
import tconstruct.plugins.imc.Mystcraft;
|
||||
import tconstruct.plugins.imc.Thaumcraft;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
public class PluginController
|
||||
{
|
||||
|
||||
private enum Phase
|
||||
{
|
||||
PRELAUNCH, PREINIT, INIT, POSTINIT, DONE
|
||||
}
|
||||
private PluginController() {} // Don't need to instantiate this.
|
||||
|
||||
private static PluginController instance;
|
||||
private Configuration conf = null;
|
||||
private List<ICompatPlugin> plugins = new LinkedList<ICompatPlugin>();
|
||||
private Phase currPhase = Phase.PRELAUNCH;
|
||||
|
||||
private PluginController()
|
||||
{
|
||||
String path = Loader.instance().getConfigDir().toString() + File.separator + "TDynstruct.cfg";
|
||||
TConstruct.logger.info("[PluginController] Using config path: " + path);
|
||||
conf = new Configuration(new File(path));
|
||||
}
|
||||
|
||||
public static PluginController getController ()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = new PluginController();
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a plugin with the controller.
|
||||
*
|
||||
* Warning: Make sure your plugin class imports no APIs directly! Any API
|
||||
* interaction should be done by handlers called in pre/init/post so merely
|
||||
* creating an instance to check the mod ID isn't a hazard to the
|
||||
* controller.
|
||||
*
|
||||
* @param plugin
|
||||
* Plugin to register
|
||||
*/
|
||||
public void registerPlugin (ICompatPlugin plugin)
|
||||
{
|
||||
conf.load();
|
||||
boolean shouldLoad = conf.get("Plugins", plugin.getModId(), true).getBoolean(true);
|
||||
conf.save();
|
||||
|
||||
if (shouldLoad)
|
||||
loadPlugin(plugin);
|
||||
}
|
||||
|
||||
// This does the actual plugin loading if mod is present; needed to allow
|
||||
// force-enabling.
|
||||
private void loadPlugin (ICompatPlugin plugin)
|
||||
{
|
||||
if (!Loader.isModLoaded(plugin.getModId()))
|
||||
return;
|
||||
|
||||
TConstruct.logger.info("[PluginController] Registering compat plugin for " + plugin.getModId());
|
||||
plugins.add(plugin);
|
||||
|
||||
switch (currPhase)
|
||||
// Play catch-up if plugin is registered late
|
||||
{
|
||||
case DONE:
|
||||
case POSTINIT:
|
||||
plugin.preInit();
|
||||
plugin.init();
|
||||
plugin.postInit();
|
||||
break;
|
||||
case INIT:
|
||||
plugin.preInit();
|
||||
plugin.init();
|
||||
break;
|
||||
case PREINIT:
|
||||
plugin.preInit();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void preInit ()
|
||||
{
|
||||
currPhase = Phase.PREINIT;
|
||||
for (ICompatPlugin pl : plugins)
|
||||
pl.preInit();
|
||||
}
|
||||
|
||||
public void init ()
|
||||
{
|
||||
currPhase = Phase.INIT;
|
||||
for (ICompatPlugin pl : plugins)
|
||||
pl.init();
|
||||
}
|
||||
|
||||
public void postInit ()
|
||||
{
|
||||
currPhase = Phase.POSTINIT;
|
||||
for (ICompatPlugin pl : plugins)
|
||||
pl.postInit();
|
||||
currPhase = Phase.DONE;
|
||||
}
|
||||
|
||||
public void registerBuiltins ()
|
||||
public static void registerModules()
|
||||
{
|
||||
// Mystcraft is pushed in through the backdoor so it can't be disabled.
|
||||
loadPlugin(new Mystcraft());
|
||||
moduleLoader.registerUncheckedModule(Mystcraft.class);
|
||||
|
||||
registerPlugin(new AppEng());
|
||||
registerPlugin(new BuildcraftTransport());
|
||||
registerPlugin(new ForgeMultiPart());
|
||||
registerPlugin(new IC2());
|
||||
// registerPlugin(new MineFactoryReloaded());
|
||||
// registerPlugin(new NotEnoughItems());
|
||||
registerPlugin(new Thaumcraft());
|
||||
// registerPlugin(new Waila());
|
||||
// Register the remaining plugin classes normally
|
||||
moduleLoader.registerModule(AppEng.class);
|
||||
moduleLoader.registerModule(BuildcraftTransport.class);
|
||||
moduleLoader.registerModule(ForgeMultiPart.class);
|
||||
moduleLoader.registerModule(IC2.class);
|
||||
moduleLoader.registerModule(Thaumcraft.class);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user