2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
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;
|
2016-06-06 20:52:46 +02:00
|
|
|
import techreborn.compat.ic2.RecipesIC2;
|
2016-07-15 00:15:36 +02:00
|
|
|
import techreborn.compat.minetweaker.MinetweakerCompat;
|
2016-06-04 15:53:16 +02:00
|
|
|
import techreborn.compat.theoneprobe.CompactTheOneProbe;
|
2016-06-04 12:31:53 +02:00
|
|
|
import techreborn.compat.tinkers.CompatModuleTinkers;
|
2016-04-13 14:47:02 +02: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-19 19:01:34 +01:00
|
|
|
import techreborn.parts.TechRebornParts;
|
2016-04-13 14:47:02 +02:00
|
|
|
import techreborn.parts.walia.WailaMcMultiPartCompact;
|
2016-03-26 16:58:38 +01:00
|
|
|
|
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;
|
2016-09-27 18:50:34 +02:00
|
|
|
public static boolean isQuantumStorageLoaded = false;
|
2016-04-03 15:34:39 +02:00
|
|
|
public ArrayList<ICompatModule> compatModules = new ArrayList<>();
|
2015-06-12 19:40:08 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public CompatManager() {
|
2016-09-07 09:21:42 +02:00
|
|
|
isIC2Loaded = Loader.isModLoaded("IC2");
|
2016-09-27 18:50:34 +02:00
|
|
|
isQuantumStorageLoaded = Loader.isModLoaded("quantumstorage");
|
2016-10-08 22:56:24 +02:00
|
|
|
register(MinetweakerCompat.class, "MineTweaker3");
|
|
|
|
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");
|
|
|
|
register(RecipesIC2.class, "IC2");
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2015-05-30 12:47:01 +02:00
|
|
|
|
2016-11-25 14:25:51 +01:00
|
|
|
public void register(Class<? extends ICompatModule> moduleClass, Object... objs) {
|
2016-10-08 22:56:24 +02:00
|
|
|
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) {
|
2016-10-08 22:56:24 +02:00
|
|
|
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) {
|
2016-10-08 22:56:24 +02:00
|
|
|
if (ConfigTechReborn.config.hasChanged())
|
|
|
|
ConfigTechReborn.config.save();
|
|
|
|
if (!shouldLoad) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
try {
|
2016-04-03 15:34:39 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2015-04-12 12:39:06 +02:00
|
|
|
}
|