2015-04-12 12:39:06 +02:00
package techreborn.compat ;
2016-03-04 20:47:08 +01:00
import net.minecraftforge.fml.common.FMLCommonHandler ;
2015-11-23 15:40:30 +01:00
import net.minecraftforge.fml.common.Loader ;
2016-03-04 20:47:08 +01:00
import net.minecraftforge.fml.relauncher.Side ;
2016-03-05 11:48:13 +01:00
import techreborn.client.render.parts.ClientPartLoader ;
2015-12-28 11:57:22 +01:00
import techreborn.compat.minetweaker.MinetweakerCompat ;
2015-12-31 00:57:06 +01:00
import techreborn.compat.recipes.RecipesBiomesOPlenty ;
2016-02-29 12:20:40 +01:00
import techreborn.compat.recipes.RecipesBuildcraft ;
import techreborn.compat.recipes.RecipesThaumcraft ;
2015-12-13 20:41:46 +01:00
import techreborn.compat.waila.CompatModuleWaila ;
2015-12-18 20:17:11 +01:00
import techreborn.config.ConfigTechReborn ;
2016-03-06 15:51:13 +01:00
import techreborn.parts.StandalonePartCompact ;
2016-03-02 17:29:51 +01:00
import techreborn.parts.TechRebornParts ;
2016-03-07 21:33:08 +01:00
import techreborn.parts.walia.WailaMcMultiPartCompact ;
2015-06-12 19:40:08 +02:00
2016-03-13 16:37:55 +01:00
import java.util.ArrayList ;
2015-04-12 12:39:06 +02:00
public class CompatManager {
2015-08-09 12:05:32 +02:00
public ArrayList < ICompatModule > compatModules = new ArrayList < ICompatModule > ( ) ;
2015-06-12 19:40:08 +02:00
2015-08-09 12:05:32 +02:00
public static CompatManager INSTANCE = new CompatManager ( ) ;
2015-06-12 19:40:08 +02:00
2015-10-14 14:39:05 +02:00
public static boolean isIC2Loaded = false ;
public static boolean isIC2ClassicLoaded = false ;
2015-11-11 18:08:41 +01:00
public static boolean isClassicEnet = false ;
2015-12-05 23:48:11 +01:00
public static boolean isGregTechLoaded = false ;
2015-06-12 19:40:08 +02:00
2015-08-09 12:05:32 +02:00
public CompatManager ( ) {
2015-10-14 14:39:05 +02:00
isIC2Loaded = Loader . isModLoaded ( " IC2 " ) ;
2015-11-29 11:42:34 +01:00
isIC2ClassicLoaded = false ;
2015-12-05 23:48:11 +01:00
if ( isIC2ClassicLoaded ) {
2015-11-11 18:08:41 +01:00
isClassicEnet = true ;
}
2015-12-05 23:48:11 +01:00
if ( Loader . isModLoaded ( " Uncomplication " ) ) {
2015-11-11 18:08:41 +01:00
isClassicEnet = true ;
}
2015-12-05 23:48:11 +01:00
if ( Loader . isModLoaded ( " gregtech " ) ) {
2015-11-22 12:16:54 +01:00
isGregTechLoaded = true ;
2015-11-22 11:27:33 +01:00
}
2016-02-25 18:35:47 +01:00
registerCompact ( CompatModuleWaila . class , " Waila " ) ;
2015-12-28 11:57:22 +01:00
registerCompact ( MinetweakerCompat . class , " MineTweaker3 " ) ;
2015-12-31 00:57:06 +01:00
registerCompact ( RecipesBiomesOPlenty . class , " BiomesOPlenty " ) ;
2016-02-29 12:20:40 +01:00
registerCompact ( RecipesBuildcraft . class , " BuildCraft|Builders " ) ;
registerCompact ( RecipesThaumcraft . class , " Thaumcraft " ) ;
2016-03-02 17:29:51 +01:00
registerCompact ( TechRebornParts . class , " mcmultipart " ) ;
2016-03-05 11:48:13 +01:00
registerCompact ( ClientPartLoader . class , " mcmultipart " , " @client " ) ;
2016-03-06 15:51:13 +01:00
registerCompact ( StandalonePartCompact . class , " !mcmultipart " ) ;
2016-03-07 21:33:08 +01:00
registerCompact ( WailaMcMultiPartCompact . class , " mcmultipart " , " Waila " ) ;
2015-08-09 12:05:32 +02:00
}
2015-05-30 12:47:01 +02:00
2016-03-05 11:48:13 +01:00
public void registerCompact ( Class < ? extends ICompatModule > moduleClass , Object . . . objs ) {
2015-12-18 20:17:11 +01:00
boolean shouldLoad = ConfigTechReborn . config . get ( ConfigTechReborn . CATEGORY_INTEGRATION , " Compat: " + moduleClass . getSimpleName ( ) , true , " Should the " + moduleClass . getSimpleName ( ) + " be loaded? " ) . getBoolean ( true ) ;
if ( ConfigTechReborn . config . hasChanged ( ) )
ConfigTechReborn . config . save ( ) ;
if ( ! shouldLoad ) {
return ;
}
2015-11-08 13:15:45 +01:00
for ( Object obj : objs ) {
if ( obj instanceof String ) {
2015-08-30 22:16:22 +02:00
String modid = ( String ) obj ;
2016-03-04 20:47:08 +01:00
if ( modid . startsWith ( " @ " ) ) {
if ( modid . equals ( " @client " ) ) {
if ( FMLCommonHandler . instance ( ) . getSide ( ) ! = Side . CLIENT ) {
return ;
}
}
} else if ( modid . startsWith ( " ! " ) ) {
2015-10-02 22:01:30 +02:00
if ( Loader . isModLoaded ( modid . replaceAll ( " ! " , " " ) ) ) {
2015-08-30 22:16:22 +02:00
return ;
}
} else {
if ( ! Loader . isModLoaded ( modid ) ) {
return ;
}
}
2015-11-08 13:15:45 +01:00
} else if ( obj instanceof Boolean ) {
2015-10-02 22:01:30 +02:00
Boolean boo = ( Boolean ) obj ;
2015-11-08 13:15:45 +01:00
if ( boo = = false ) {
2015-08-30 22:16:22 +02:00
}
2015-11-08 13:15:45 +01:00
return ;
}
2015-07-23 17:19:07 +02:00
}
2015-08-09 12:05:32 +02:00
try {
compatModules . add ( ( ICompatModule ) moduleClass . newInstance ( ) ) ;
} catch ( InstantiationException e ) {
e . printStackTrace ( ) ;
} catch ( IllegalAccessException e ) {
e . printStackTrace ( ) ;
}
}
2015-10-07 09:34:24 +02:00
2015-11-08 13:15:45 +01:00
public boolean isForestry4 ( ) {
2015-10-07 09:34:24 +02:00
try {
Class . forName ( " forestry.api.arboriculture.EnumWoodType " ) ;
return true ;
2015-11-08 13:15:45 +01:00
} catch ( ClassNotFoundException e ) {
2015-10-07 09:34:24 +02:00
return false ;
}
}
2015-11-11 18:08:41 +01:00
2015-04-12 12:39:06 +02:00
}