mirror of
https://github.com/GTNewHorizons/ThaumicEnergistics.git
synced 2026-10-26 14:33:46 +00:00
Remove reflection and use APIs.
Extra Cells - use the API directly Others - move to a static method instead of instantiating it. Use optionals instead of using reflection + try catch.
This commit is contained in:
1 parent
a84cb83e99
commit
48fa67a805
6 files changed
+45
-97
No files matched your search
@@ -8,6 +8,7 @@ dependencies {
|
||||
|
||||
implementation("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev")
|
||||
|
||||
compileOnly('com.github.GTNewHorizons:ExtraCells2:2.5.34:dev') { transitive = false }
|
||||
compileOnly("com.github.GTNewHorizons:waila:1.6.0:dev") {
|
||||
transitive = false
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package thaumicenergistics.common.integration;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
@@ -21,10 +23,6 @@ import thaumicenergistics.common.utils.ThELog;
|
||||
*/
|
||||
public final class IntegrationCore {
|
||||
|
||||
/**
|
||||
* Class path to all integration modules
|
||||
*/
|
||||
private static final String CLASS_PATH = ThaumicEnergistics.MOD_ID + ".common.integration.Module";
|
||||
|
||||
/**
|
||||
* Module ID for Waila
|
||||
@@ -48,56 +46,15 @@ public final class IntegrationCore {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static void integrateWithClientMods() {
|
||||
// Integrate with version checker
|
||||
IntegrationCore.integrateWithVersionChecker();
|
||||
|
||||
// Integrate with NEI
|
||||
IntegrationCore.integrateWithMod(IntegrationCore.MODID_NEI);
|
||||
|
||||
// Integrate with Waila
|
||||
IntegrationCore.integrateWithMod(IntegrationCore.MODID_WAILA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Integrates with the specified mod if it exists
|
||||
*
|
||||
* @param modID
|
||||
*/
|
||||
private static void integrateWithMod(final String modID) {
|
||||
try {
|
||||
// Attempt to get the module
|
||||
Class<?> module = Class.forName(IntegrationCore.CLASS_PATH + modID);
|
||||
|
||||
// Instantiate it
|
||||
module.getDeclaredConstructor().newInstance();
|
||||
|
||||
// Log success
|
||||
ThELog.info("Successfully integrated with %s", modID);
|
||||
} catch (Throwable e) {
|
||||
|
||||
// Log failure
|
||||
ThELog.info("Skipping integration with %s", modID);
|
||||
if (Loader.isModLoaded("NotEnoughItems")) {
|
||||
// Integrate with NEI
|
||||
ModuleNEI.init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Integrates with version checker
|
||||
*/
|
||||
private static void integrateWithVersionChecker() {
|
||||
// Create the tag
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
||||
// Set the project name
|
||||
tag.setString("curseProjectName", "223666-thaumic-energistics");
|
||||
|
||||
// Set the file name
|
||||
tag.setString("curseFilenameParser", "thaumicenergistics-[].jar");
|
||||
|
||||
// Set the mod name
|
||||
tag.setString("modDisplayName", "Thaumic Energistics");
|
||||
|
||||
// Send to version checker
|
||||
FMLInterModComms.sendRuntimeMessage(ThaumicEnergistics.MOD_ID, "VersionChecker", "addCurseCheck", tag);
|
||||
if (Loader.isModLoaded("Waila")) {
|
||||
// Integrate with Waila
|
||||
ModuleWaila.init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,25 +62,20 @@ public final class IntegrationCore {
|
||||
*/
|
||||
public static void init() {
|
||||
long startTime = ThELog.beginSection("Integration");
|
||||
try {
|
||||
// Is client side?
|
||||
if (EffectiveSide.isClientSide()) {
|
||||
// Integrate with client mods
|
||||
IntegrationCore.integrateWithClientMods();
|
||||
}
|
||||
// Is client side?
|
||||
if (EffectiveSide.isClientSide()) {
|
||||
// Integrate with client mods
|
||||
IntegrationCore.integrateWithClientMods();
|
||||
}
|
||||
if (Loader.isModLoaded("ComputerCraft")) {
|
||||
ModuleCC.init();
|
||||
}
|
||||
if (Loader.isModLoaded("extracells")) {
|
||||
ModuleEC2.init();
|
||||
}
|
||||
|
||||
// Integrate with EC2 if blacklisting enabled
|
||||
if (ThEApi.instance().config().blacklistEssentiaFluidInExtraCells()) {
|
||||
IntegrationCore.integrateWithMod(IntegrationCore.MODID_EC2);
|
||||
}
|
||||
|
||||
// Integrate with computer craft
|
||||
IntegrationCore.integrateWithMod(IntegrationCore.MODID_CC);
|
||||
|
||||
// Send a message to Thaumic Tinkerer to blacklist the essentia provider from its CC support
|
||||
FMLInterModComms.sendMessage("ThaumicTinkerer", "AddCCBlacklist", TileEssentiaProvider.class.getName());
|
||||
|
||||
} catch (Throwable e) {}
|
||||
// Send a message to Thaumic Tinkerer to blacklist the essentia provider from its CC support
|
||||
FMLInterModComms.sendMessage("ThaumicTinkerer", "AddCCBlacklist", TileEssentiaProvider.class.getName());
|
||||
|
||||
// Register the Arcane Assembler for upgrades
|
||||
Upgrades.SPEED.registerItem(
|
||||
|
||||
@@ -15,7 +15,6 @@ import thaumicenergistics.common.tiles.TileEssentiaProvider;
|
||||
*
|
||||
*/
|
||||
public class ModuleCC {
|
||||
|
||||
public static class ThEPeripherals implements IPeripheralProvider {
|
||||
|
||||
@Override
|
||||
@@ -37,10 +36,12 @@ public class ModuleCC {
|
||||
}
|
||||
}
|
||||
|
||||
private ModuleCC() {}
|
||||
|
||||
/**
|
||||
* Integrates with CC
|
||||
*/
|
||||
public ModuleCC() {
|
||||
static void init() {
|
||||
// Create and register the handler
|
||||
ComputerCraftAPI.registerPeripheralProvider(new ThEPeripherals());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package thaumicenergistics.common.integration;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import extracells.api.ECApi;
|
||||
import thaumicenergistics.api.ThEApi;
|
||||
import thaumicenergistics.common.fluids.GaseousEssentia;
|
||||
|
||||
@@ -12,27 +12,14 @@ import thaumicenergistics.common.fluids.GaseousEssentia;
|
||||
*
|
||||
*/
|
||||
public class ModuleEC2 {
|
||||
private ModuleEC2() {}
|
||||
|
||||
public ModuleEC2() throws Exception {
|
||||
@Optional.Method(modid = "extracells")
|
||||
static void init() {
|
||||
// Is blacklisting enabled?
|
||||
if (ThEApi.instance().config().blacklistEssentiaFluidInExtraCells()) {
|
||||
// Get the API
|
||||
Class<?> ECApi_Class = Class.forName("extracells.api.ECApi");
|
||||
|
||||
// Get the 'instance' method
|
||||
Method ECApi_instance = ECApi_Class.getDeclaredMethod("instance");
|
||||
|
||||
// Invoke the 'instance' method
|
||||
Object ECApi = ECApi_instance.invoke(null);
|
||||
|
||||
// Get the blacklist methods
|
||||
Method addFluidToShowBlacklist = ECApi.getClass().getDeclaredMethod("addFluidToShowBlacklist", Class.class);
|
||||
Method addFluidToStorageBlacklist = ECApi.getClass()
|
||||
.getDeclaredMethod("addFluidToStorageBlacklist", Class.class);
|
||||
|
||||
// Invoke the blacklist methods
|
||||
addFluidToShowBlacklist.invoke(ECApi, GaseousEssentia.class);
|
||||
addFluidToStorageBlacklist.invoke(ECApi, GaseousEssentia.class);
|
||||
ECApi.instance().addFluidToShowBlacklist(GaseousEssentia.class);
|
||||
ECApi.instance().addFluidToStorageBlacklist(GaseousEssentia.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -244,12 +245,13 @@ public class ModuleNEI {
|
||||
*/
|
||||
static final int NEI_REGULAR_SLOT_OFFSET_Y = 6;
|
||||
|
||||
private ModuleNEI() {}
|
||||
|
||||
/**
|
||||
* Integrates with Not Enough Items
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public ModuleNEI() throws Exception {
|
||||
@Optional.Method(modid = "NotEnoughItems")
|
||||
static void init() {
|
||||
// Register the ACT overlays
|
||||
API.registerGuiOverlay(
|
||||
thaumicenergistics.client.gui.GuiArcaneCraftingTerminal.class,
|
||||
|
||||
@@ -2,6 +2,7 @@ package thaumicenergistics.common.integration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -33,9 +34,12 @@ public class ModuleWaila implements IWailaDataProvider {
|
||||
/**
|
||||
* Attempts to integrate with Waila
|
||||
*/
|
||||
public ModuleWaila() {
|
||||
private ModuleWaila() {}
|
||||
|
||||
@Optional.Method(modid = "Waila")
|
||||
static void init() {
|
||||
// Set the singleton
|
||||
ModuleWaila.INSTANCE = this;
|
||||
ModuleWaila.INSTANCE = new ModuleWaila();
|
||||
|
||||
// Register with Waila
|
||||
FMLInterModComms.sendMessage("Waila", "register", ModuleWaila.class.getCanonicalName() + ".callbackRegister");
|
||||
@@ -46,6 +50,7 @@ public class ModuleWaila implements IWailaDataProvider {
|
||||
*
|
||||
* @param registrar
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static void callbackRegister(final IWailaRegistrar registrar) {
|
||||
// Register the providers
|
||||
registrar.registerBodyProvider(ModuleWaila.INSTANCE, AbstractBlockProviderBase.class);
|
||||
|
||||
Reference in new issue
Block a user