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

122 lines
4.5 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;
import techreborn.client.render.parts.ClientPartLoader;
2017-06-02 16:44:00 +02:00
import techreborn.compat.buildcraft.BuildcraftBuildersCompat;
import techreborn.compat.buildcraft.BuildcraftCompat;
2016-06-06 20:52:46 +02:00
import techreborn.compat.ic2.RecipesIC2;
2017-03-14 13:59:17 +01:00
import techreborn.compat.crafttweaker.CraftTweakerCompat;
2016-06-04 15:53:16 +02:00
import techreborn.compat.theoneprobe.CompactTheOneProbe;
import techreborn.compat.tinkers.CompatModuleTinkers;
import techreborn.compat.waila.CompatModuleWaila;
import techreborn.config.ConfigTechReborn;
2016-03-06 15:51:13 +01:00
import techreborn.parts.StandalonePartCompact;
2016-03-19 19:01:34 +01:00
import techreborn.parts.TechRebornParts;
import techreborn.parts.walia.WailaMcMultiPartCompact;
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");
registerCompact(TechRebornParts.class, false, "reborncore-mcmultipart");
registerCompact(ClientPartLoader.class, false, "reborncore-mcmultipart", "@client");
registerCompact(StandalonePartCompact.class, false, "!reborncore-mcmultipart");
registerCompact(WailaMcMultiPartCompact.class, false, "reborncore-mcmultipart", "Waila", "!IC2");
register(CompatModuleWaila.class, "Waila");
register(CompatModuleTinkers.class, "tconstruct");
register(CompactTheOneProbe.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");
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) {
boolean shouldLoad = true;
2016-11-25 14:25:51 +01:00
if (config) {
shouldLoad = ConfigTechReborn.config
.get(ConfigTechReborn.CATEGORY_INTEGRATION, "Compat:" + moduleClass.getSimpleName(), true,
"Should the " + moduleClass.getSimpleName() + " be loaded?")
.getBoolean(true);
2016-03-25 10:47:34 +01:00
}
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-11-25 14:25:51 +01:00
if (config) {
if (ConfigTechReborn.config.hasChanged())
ConfigTechReborn.config.save();
if (!shouldLoad) {
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();
}
}
}