Skip to content

Commit

Permalink
Port TCon to use the v2 loader infrastructure from Mantle
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunstrike committed Apr 20, 2014
1 parent a3aa7c2 commit 891086d
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 242 deletions.
14 changes: 9 additions & 5 deletions src/main/java/tconstruct/TConstruct.java
@@ -1,6 +1,7 @@
package tconstruct;

import mantle.lib.TabTools;
import mantle.module.ModuleController;
import net.minecraft.world.gen.structure.MapGenStructureIO;
import net.minecraftforge.common.MinecraftForge;

Expand Down Expand Up @@ -80,6 +81,9 @@ public class TConstruct
@SidedProxy(clientSide = "tconstruct.client.TProxyClient", serverSide = "tconstruct.common.TProxyCommon")
public static TProxyCommon proxy;

// Module loader
public static final ModuleController moduleLoader = new ModuleController("TDynstruct.cfg", "TConstruct");

// The packet pipeline
public static final PacketPipeline packetPipeline = new PacketPipeline();

Expand All @@ -99,7 +103,7 @@ public TConstruct()

EnvironmentChecks.verifyEnvironmentSanity();
MinecraftForge.EVENT_BUS.register(events = new TEventHandler());
PluginController.getController().registerBuiltins();
PluginController.registerModules();
}

@EventHandler
Expand Down Expand Up @@ -166,7 +170,7 @@ public void preInit (FMLPreInitializationEvent event)
FMLCommonHandler.instance().bus().register(new TControls());
}

PluginController.getController().preInit();
moduleLoader.preInit();
}

@EventHandler
Expand All @@ -181,12 +185,12 @@ public void init (FMLInitializationEvent event)
DimensionBlacklist.getBadBimensions();
GameRegistry.registerWorldGenerator(new SlimeIslandGen(TRepo.slimePool, 2), 2);

PluginController.getController().init();

if (PHConstruct.achievementsEnabled)
{
TAchievements.init();
}

moduleLoader.init();
}

@EventHandler
Expand All @@ -201,7 +205,7 @@ public void postInit (FMLPostInitializationEvent evt)
content.createEntities();
recipes.modRecipes();

PluginController.getController().postInit();
moduleLoader.postInit();
}

public static LiquidCasting getTableCasting ()
Expand Down
126 changes: 11 additions & 115 deletions src/main/java/tconstruct/plugins/PluginController.java
@@ -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 static PluginController instance;
private Configuration conf = null;
private List<ICompatPlugin> plugins = new LinkedList<ICompatPlugin>();
private Phase currPhase = Phase.PRELAUNCH;
private PluginController() {} // Don't need to instantiate this.

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());

registerPlugin(new AppEng());
registerPlugin(new BuildcraftTransport());
registerPlugin(new ForgeMultiPart());
registerPlugin(new IC2());
// registerPlugin(new MineFactoryReloaded());
// registerPlugin(new NotEnoughItems());
registerPlugin(new Thaumcraft());
// registerPlugin(new Waila());
moduleLoader.registerUncheckedModule(Mystcraft.class);

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

}
59 changes: 47 additions & 12 deletions src/main/java/tconstruct/plugins/fmp/ForgeMultiPart.java
@@ -1,15 +1,18 @@
package tconstruct.plugins.fmp;

import codechicken.microblock.BlockMicroMaterial;
import codechicken.microblock.MicroMaterialRegistry;
import mantle.module.ILoadableModule;
import net.minecraft.block.Block;
import tconstruct.TConstruct;
import tconstruct.common.TRepo;
import tconstruct.plugins.ICompatPlugin;

public class ForgeMultiPart implements ICompatPlugin
public class ForgeMultiPart implements ILoadableModule
{
@Override
public String getModId() {
return "ForgeMultipart";
}

@SuppressWarnings("unused")
public static String modId = "ForgeMultipart";

@Override
public void preInit() {
Expand All @@ -20,18 +23,50 @@ public void preInit() {
public void init()
{
TConstruct.logger.info("ForgeMultipart detected. Registering TConstruct decorative blocks with FMP.");
RegisterWithFMP.registerBlock(TRepo.clearGlass);
RegisterWithFMP.registerBlock(TRepo.stainedGlassClear, 0, 15);
RegisterWithFMP.registerBlock(TRepo.multiBrick, 0, 13);
RegisterWithFMP.registerBlock(TRepo.metalBlock, 0, 10);
RegisterWithFMP.registerBlock(TRepo.multiBrickFancy, 0, 15);
RegisterWithFMP.registerBlock(TRepo.smeltery, 2, 2);
RegisterWithFMP.registerBlock(TRepo.smeltery, 4, 10);
registerBlock(TRepo.clearGlass);
registerBlock(TRepo.stainedGlassClear, 0, 15);
registerBlock(TRepo.multiBrick, 0, 13);
registerBlock(TRepo.metalBlock, 0, 10);
registerBlock(TRepo.multiBrickFancy, 0, 15);
registerBlock(TRepo.smeltery, 2, 2);
registerBlock(TRepo.smeltery, 4, 10);
}

@Override
public void postInit() {
// Nothing
}

//For blocks with metadata values only
public static void registerBlock (Block block, int metastart, int metaend)
{
for (int meta = metastart; meta <= metaend; meta++)
{
String identifier = new String(block.getUnlocalizedName());
MicroMaterialRegistry.registerMaterial(new BlockMicroMaterial(block, meta), identifier + meta);
}
}

//For blocks without metadata values only.
public static void registerBlock (Block block)
{
BlockMicroMaterial.createAndRegister(block, 0);
}

//For blocks with metadata values and special MicroMaterial only
public static void registerBlock (Block block, int metastart, int metaend, MicroMaterialRegistry.IMicroMaterial material)
{
for (int meta = metastart; meta <= metaend; meta++)
{
String identifier = new String(block.getUnlocalizedName());
MicroMaterialRegistry.registerMaterial(material, identifier + meta);
}
}

//For blocks without metadata values and special MicroMaterial only.
public static void registerBlock (Block block, MicroMaterialRegistry.IMicroMaterial material)
{
MicroMaterialRegistry.registerMaterial(material, new String(block.getUnlocalizedName()));
}

}
42 changes: 0 additions & 42 deletions src/main/java/tconstruct/plugins/fmp/RegisterWithFMP.java

This file was deleted.

0 comments on commit 891086d

Please sign in to comment.