TechReborn/src/main/java/techreborn/compat/CompatManager.java

107 lines
3.8 KiB
Java
Raw Normal View History

/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
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;
2017-06-02 16:44:00 +02:00
import techreborn.compat.buildcraft.BuildcraftBuildersCompat;
import techreborn.compat.buildcraft.BuildcraftCompat;
2017-03-14 13:59:17 +01:00
import techreborn.compat.crafttweaker.CraftTweakerCompat;
2017-06-12 11:55:26 +02:00
import techreborn.compat.ic2.RecipesIC2;
import techreborn.compat.theoneprobe.TheOneProbeCompat;
import techreborn.compat.thermalexpansion.RecipeThermalExpansion;
import techreborn.compat.tinkers.CompatModuleTinkers;
2016-05-09 03:02:11 +02:00
import java.util.ArrayList;
2016-10-08 21:46:16 +02:00
public class CompatManager {
2015-06-12 19:40:08 +02:00
2016-03-25 10:47:34 +01:00
public static CompatManager INSTANCE = new CompatManager();
public static boolean isIC2Loaded = false;
public static boolean isQuantumStorageLoaded = false;
public ArrayList<ICompatModule> compatModules = new ArrayList<>();
2015-06-12 19:40:08 +02:00
2016-10-08 21:46:16 +02:00
public CompatManager() {
2017-04-21 10:09:28 +02:00
isIC2Loaded = Loader.isModLoaded("ic2");
isQuantumStorageLoaded = Loader.isModLoaded("quantumstorage");
2017-03-14 13:59:17 +01:00
register(CraftTweakerCompat.class, "crafttweaker");
register(CompatModuleTinkers.class, "tconstruct");
register(TheOneProbeCompat.class, "theoneprobe");
//register(CompatModulePsi.class, "Psi");
2017-04-21 10:09:28 +02:00
register(RecipesIC2.class, "ic2");
2017-06-02 16:44:00 +02:00
register(BuildcraftBuildersCompat.class, "buildcraftbuilders");
register(BuildcraftCompat.class, "buildcraftcore");
register(RecipeThermalExpansion.class, "thermalexpansion");
2016-03-25 10:47:34 +01:00
}
2016-11-25 14:25:51 +01:00
public void register(Class<? extends ICompatModule> moduleClass, Object... objs) {
registerCompact(moduleClass, true, objs);
}
public void registerCompact(Class<? extends ICompatModule> moduleClass, boolean config, Object... objs) {
2017-09-08 01:03:35 +02:00
//boolean shouldLoad = true;
2017-06-12 21:51:36 +02:00
//TODO config
2017-06-28 21:54:12 +02:00
// if (config) {
// shouldLoad = ConfigTechReborn.config
// .get(ConfigTechReborn.CATEGORY_INTEGRATION, "Compat:" + moduleClass.getSimpleName(), true,
// "Should the " + moduleClass.getSimpleName() + " be loaded?")
// .getBoolean(true);
// }
2016-10-08 21:46:16 +02:00
for (Object obj : objs) {
if (obj instanceof String) {
2016-03-25 10:47:34 +01:00
String modid = (String) obj;
2016-10-08 21:46:16 +02:00
if (modid.startsWith("@")) {
if (modid.equals("@client")) {
if (FMLCommonHandler.instance().getSide() != Side.CLIENT) {
2016-03-25 10:47:34 +01:00
return;
}
}
2016-10-08 21:46:16 +02:00
} else if (modid.startsWith("!")) {
if (Loader.isModLoaded(modid.replaceAll("!", ""))) {
2016-03-25 10:47:34 +01:00
return;
}
2016-10-08 21:46:16 +02:00
} else {
if (!Loader.isModLoaded(modid)) {
2016-03-25 10:47:34 +01:00
return;
}
}
2016-10-08 21:46:16 +02:00
} else if (obj instanceof Boolean) {
2016-03-25 10:47:34 +01:00
Boolean boo = (Boolean) obj;
2016-10-08 21:46:16 +02:00
if (!boo) {
2016-03-25 10:47:34 +01:00
}
return;
}
}
2016-10-08 21:46:16 +02:00
try {
compatModules.add(moduleClass.newInstance());
2016-10-08 21:46:16 +02:00
} catch (InstantiationException e) {
2016-03-25 10:47:34 +01:00
e.printStackTrace();
2016-10-08 21:46:16 +02:00
} catch (IllegalAccessException e) {
2016-03-25 10:47:34 +01:00
e.printStackTrace();
}
}
}