From 12b05275f2380352c9d9ca9f43a84d4b53ca0354 Mon Sep 17 00:00:00 2001 From: yueh Date: Tue, 31 Jan 2017 12:17:03 +0100 Subject: [PATCH] Fixes #2750: Added missing RF Integration Modules. (#2770) * Fixes #2750: Added missing RF Integration Modules. Readded the integration modules for both RF integrations. These are necessary to correctly enable RF support as well as act as fallback to disable it automatically on missing interfaces. * Unittests and improved logging for integration modules. Added a unittest to ensure an integration types instaniates an integration module without throwing any exception. Improved the logging should this ever happen at runtime again. --- src/main/java/appeng/core/AELog.java | 2 +- .../appeng/integration/IntegrationNode.java | 6 +-- .../appeng/integration/IntegrationType.java | 30 +++++++---- .../MissingIntegrationModuleException.java | 32 ++++++++++++ .../integration/modules/rf/RFItemModule.java | 32 ++++++++++++ .../integration/modules/rf/RFTileModule.java | 32 ++++++++++++ .../integration/IntegrationTypeTest.java | 52 +++++++++++++++++++ 7 files changed, 170 insertions(+), 16 deletions(-) create mode 100644 src/main/java/appeng/integration/MissingIntegrationModuleException.java create mode 100644 src/main/java/appeng/integration/modules/rf/RFItemModule.java create mode 100644 src/main/java/appeng/integration/modules/rf/RFTileModule.java create mode 100644 src/test/java/appeng/integration/IntegrationTypeTest.java diff --git a/src/main/java/appeng/core/AELog.java b/src/main/java/appeng/core/AELog.java index 217e4ba4..ca0bdcab 100644 --- a/src/main/java/appeng/core/AELog.java +++ b/src/main/java/appeng/core/AELog.java @@ -307,7 +307,7 @@ public final class AELog { if( AEConfig.instance().isFeatureEnabled( AEFeature.INTEGRATION_LOGGING ) ) { - debug( exception ); + error( exception ); } } diff --git a/src/main/java/appeng/integration/IntegrationNode.java b/src/main/java/appeng/integration/IntegrationNode.java index 34d9e40c..ac34d3e1 100644 --- a/src/main/java/appeng/integration/IntegrationNode.java +++ b/src/main/java/appeng/integration/IntegrationNode.java @@ -25,9 +25,6 @@ import net.minecraftforge.fml.common.ModAPIManager; import appeng.api.exceptions.ModNotInstalled; import appeng.core.AEConfig; import appeng.core.AELog; -import appeng.integration.modules.ic2.IC2Module; -import appeng.integration.modules.jei.JEIModule; -import appeng.integration.modules.waila.WailaModule; final class IntegrationNode @@ -80,7 +77,8 @@ final class IntegrationNode final ModAPIManager apiManager = ModAPIManager.INSTANCE; boolean enabled = this.modID == null || Loader.isModLoaded( this.modID ) || apiManager.hasAPI( this.modID ); - AEConfig.instance().addCustomCategoryComment( "ModIntegration", "Valid Values are 'AUTO', 'ON', or 'OFF' - defaults to 'AUTO' ; Suggested that you leave this alone unless your experiencing an issue, or wish to disable the integration for a reason." ); + AEConfig.instance().addCustomCategoryComment( "ModIntegration", + "Valid Values are 'AUTO', 'ON', or 'OFF' - defaults to 'AUTO' ; Suggested that you leave this alone unless your experiencing an issue, or wish to disable the integration for a reason." ); final String mode = AEConfig.instance().get( "ModIntegration", this.displayName.replace( " ", "" ), "AUTO" ).getString(); if( mode.toUpperCase().equals( "ON" ) ) diff --git a/src/main/java/appeng/integration/IntegrationType.java b/src/main/java/appeng/integration/IntegrationType.java index 35612f23..33fb860e 100644 --- a/src/main/java/appeng/integration/IntegrationType.java +++ b/src/main/java/appeng/integration/IntegrationType.java @@ -21,6 +21,8 @@ package appeng.integration; import appeng.integration.modules.ic2.IC2Module; import appeng.integration.modules.jei.JEIModule; +import appeng.integration.modules.rf.RFItemModule; +import appeng.integration.modules.rf.RFTileModule; import appeng.integration.modules.theoneprobe.TheOneProbeModule; import appeng.integration.modules.waila.WailaModule; @@ -36,13 +38,25 @@ public enum IntegrationType } }, - RC( IntegrationSide.BOTH, "Railcraft", "Railcraft" ), + RF( IntegrationSide.BOTH, "RedstoneFlux Power - Tiles", "CoFHAPI" ) + { - RF( IntegrationSide.BOTH, "RedstoneFlux Power - Tiles", "CoFHAPI" ), + @Override + public IIntegrationModule createInstance() + { + return new RFTileModule(); + } + }, - RFItem( IntegrationSide.BOTH, "RedstoneFlux Power - Items", "CoFHAPI" ), + RFItem( IntegrationSide.BOTH, "RedstoneFlux Power - Items", "CoFHAPI" ) + { - MFR( IntegrationSide.BOTH, "Mine Factory Reloaded", "MineFactoryReloaded" ), + @Override + public IIntegrationModule createInstance() + { + return new RFItemModule(); + } + }, Waila( IntegrationSide.BOTH, "Waila", "Waila" ) { @@ -53,8 +67,6 @@ public enum IntegrationType } }, - InvTweaks( IntegrationSide.CLIENT, "Inventory Tweaks", "inventorytweaks" ), - JEI( IntegrationSide.CLIENT, "Just Enough Items", "JEI" ) { @Override @@ -64,10 +76,6 @@ public enum IntegrationType } }, - Mekanism( IntegrationSide.BOTH, "Mekanism", "Mekanism" ), - - OpenComputers( IntegrationSide.BOTH, "OpenComputers", "OpenComputers" ), - THE_ONE_PROBE( IntegrationSide.BOTH, "TheOneProbe", "theoneprobe" ) { @Override @@ -90,7 +98,7 @@ public enum IntegrationType public IIntegrationModule createInstance() { - throw new UnsupportedOperationException(); + throw new MissingIntegrationModuleException( this.name() ); } } diff --git a/src/main/java/appeng/integration/MissingIntegrationModuleException.java b/src/main/java/appeng/integration/MissingIntegrationModuleException.java new file mode 100644 index 00000000..b06a4c12 --- /dev/null +++ b/src/main/java/appeng/integration/MissingIntegrationModuleException.java @@ -0,0 +1,32 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration; + + +public class MissingIntegrationModuleException extends RuntimeException +{ + + private static final long serialVersionUID = 1927357647297008228L; + + public MissingIntegrationModuleException( String name ) + { + super( "Missing integration module for type '" + name + "'." ); + } + +} diff --git a/src/main/java/appeng/integration/modules/rf/RFItemModule.java b/src/main/java/appeng/integration/modules/rf/RFItemModule.java new file mode 100644 index 00000000..127417ea --- /dev/null +++ b/src/main/java/appeng/integration/modules/rf/RFItemModule.java @@ -0,0 +1,32 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.rf; + + +import appeng.integration.IIntegrationModule; +import appeng.integration.IntegrationHelper; + + +public class RFItemModule implements IIntegrationModule +{ + public RFItemModule() + { + IntegrationHelper.testClassExistence( this, cofh.api.energy.IEnergyContainerItem.class ); + } +} diff --git a/src/main/java/appeng/integration/modules/rf/RFTileModule.java b/src/main/java/appeng/integration/modules/rf/RFTileModule.java new file mode 100644 index 00000000..4a1b08bd --- /dev/null +++ b/src/main/java/appeng/integration/modules/rf/RFTileModule.java @@ -0,0 +1,32 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.rf; + + +import appeng.integration.IIntegrationModule; +import appeng.integration.IntegrationHelper; + + +public class RFTileModule implements IIntegrationModule +{ + public RFTileModule() + { + IntegrationHelper.testClassExistence( this, cofh.api.energy.IEnergyReceiver.class ); + } +} diff --git a/src/test/java/appeng/integration/IntegrationTypeTest.java b/src/test/java/appeng/integration/IntegrationTypeTest.java new file mode 100644 index 00000000..8d010245 --- /dev/null +++ b/src/test/java/appeng/integration/IntegrationTypeTest.java @@ -0,0 +1,52 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration; + + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + + +public class IntegrationTypeTest +{ + + @Test + public void testCreateInstanceWithoutExceptions() + { + for( IntegrationType type : IntegrationType.values() ) + { + try + { + assertNotNull( type.createInstance() ); + } + // We actually only care about this specific type not being thrown. + catch( MissingIntegrationModuleException e ) + { + throw e; + } + // Throw everything else away as these might be caused due to missing dependencies during testing. + catch( Throwable e ) + { + // ignore + } + } + } + +}