Prepare ICompatibility for phase based loading

Some compat will need to be done at different loading phases. This should allow that to be handled fairly easily.
This commit is contained in:
Nick 2016-01-09 20:41:01 -08:00
parent de5ca8dfee
commit 254d9bec80
5 changed files with 39 additions and 11 deletions

View file

@ -2,6 +2,7 @@ package WayofTime.bloodmagic;
import java.io.File;
import WayofTime.bloodmagic.compat.ICompatibility;
import lombok.Getter;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
@ -66,6 +67,8 @@ public class BloodMagic
ModItems.init();
ModPotions.init();
ModEntities.init();
ModCompatibility.registerModCompat();
ModCompatibility.loadCompat(ICompatibility.InitializationPhase.PRE_INIT);
proxy.preInit();
}
@ -78,8 +81,8 @@ public class BloodMagic
ModRecipes.init();
ModRituals.initRituals();
ModRituals.initImperfectRituals();
ModCompatibility.registerModCompat();
ModArmourTrackers.init();
ModCompatibility.loadCompat(ICompatibility.InitializationPhase.INIT);
ConfigHandler.checkRituals();
NetworkRegistry.INSTANCE.registerGuiHandler(BloodMagic.instance, new GuiHandler());
@ -90,6 +93,7 @@ public class BloodMagic
public void postInit(FMLPostInitializationEvent event)
{
ModRecipes.addCompressionHandlers();
ModCompatibility.loadCompat(ICompatibility.InitializationPhase.POST_INIT);
proxy.postInit();
}

View file

@ -6,9 +6,13 @@ package WayofTime.bloodmagic.compat;
public interface ICompatibility
{
/**
* Called after the given {@code modid} has been verified as loaded.
* Called during each initialization phase after the given {@link #getModId()}
* has been verified as loaded.
*
* @param phase
* - The load phase at which this method is being called.
*/
void loadCompatibility();
void loadCompatibility(InitializationPhase phase);
/**
* @return The {@code modid} of the mod we are adding compatibility for.
@ -24,4 +28,22 @@ public interface ICompatibility
* @return If Compatibility should load.
*/
boolean enableCompat();
/**
* Represents a given mod initialization state.
*/
enum InitializationPhase {
/**
* Represents {@link net.minecraftforge.fml.common.event.FMLPreInitializationEvent}
*/
PRE_INIT,
/**
* Represents {@link net.minecraftforge.fml.common.event.FMLInitializationEvent}
*/
INIT,
/**
* Represents {@link net.minecraftforge.fml.common.event.FMLPostInitializationEvent}
*/
POST_INIT
}
}

View file

@ -5,7 +5,7 @@ import WayofTime.bloodmagic.compat.ICompatibility;
public class CompatibilityJustEnoughItems implements ICompatibility
{
@Override
public void loadCompatibility()
public void loadCompatibility(InitializationPhase phase)
{
}

View file

@ -6,9 +6,10 @@ import net.minecraftforge.fml.common.event.FMLInterModComms;
public class CompatibilityWaila implements ICompatibility
{
@Override
public void loadCompatibility()
public void loadCompatibility(InitializationPhase phase)
{
FMLInterModComms.sendMessage(getModId(), "register", "WayofTime.bloodmagic.compat.waila.WailaCallbackHandler.callbackRegister");
if (phase == InitializationPhase.INIT)
FMLInterModComms.sendMessage(getModId(), "register", "WayofTime.bloodmagic.compat.waila.WailaCallbackHandler.callbackRegister");
}
@Override

View file

@ -15,11 +15,12 @@ public class ModCompatibility
{
compatibilities.add(new CompatibilityJustEnoughItems());
compatibilities.add(new CompatibilityWaila());
}
for (ICompatibility compat : compatibilities)
{
if (compat.enableCompat() && Loader.isModLoaded(compat.getModId()))
compat.loadCompatibility();
}
public static void loadCompat(ICompatibility.InitializationPhase phase)
{
for (ICompatibility compatibility : compatibilities)
if (Loader.isModLoaded(compatibility.getModId()) && compatibility.enableCompat())
compatibility.loadCompatibility(phase);
}
}