2014-11-13 14:48:04 +01:00
|
|
|
/*
|
|
|
|
* 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 <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
package appeng.integration;
|
|
|
|
|
2014-11-13 14:48:04 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.util.LinkedList;
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
2014-11-13 14:48:04 +01:00
|
|
|
|
|
|
|
public enum IntegrationRegistry
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-13 14:48:04 +01:00
|
|
|
INSTANCE;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-09-29 09:54:34 +02:00
|
|
|
private final LinkedList<IntegrationNode> modules = new LinkedList<IntegrationNode>();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-11-13 14:48:04 +01:00
|
|
|
public void add( IntegrationType type )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
if ( type.side == IntegrationSide.CLIENT && FMLLaunchHandler.side() == Side.SERVER )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( type.side == IntegrationSide.SERVER && FMLLaunchHandler.side() == Side.CLIENT )
|
|
|
|
return;
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.modules.add( new IntegrationNode( type.dspName, type.modID, type, "appeng.integration.modules." + type.name() ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void init()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
for ( IntegrationNode node : this.modules )
|
2014-09-28 11:47:17 +02:00
|
|
|
node.Call( IntegrationStage.PRE_INIT );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
for ( IntegrationNode node : this.modules )
|
2014-09-24 02:26:27 +02:00
|
|
|
node.Call( IntegrationStage.INIT );
|
|
|
|
}
|
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
public void postInit()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
for ( IntegrationNode node : this.modules )
|
2014-09-28 11:47:17 +02:00
|
|
|
node.Call( IntegrationStage.POST_INIT );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getStatus()
|
|
|
|
{
|
|
|
|
String out = null;
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
for ( IntegrationNode node : this.modules )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-13 14:48:04 +01:00
|
|
|
String str = node.shortName + ":" + ( node.state == IntegrationStage.FAILED ? "OFF" : "ON" );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
if ( out == null )
|
|
|
|
out = str;
|
|
|
|
else
|
|
|
|
out += ", " + str;
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:48:04 +01:00
|
|
|
public boolean isEnabled( IntegrationType name )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
for ( IntegrationNode node : this.modules )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
if ( node.shortName == name )
|
|
|
|
return node.isActive();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:48:04 +01:00
|
|
|
public Object getInstance( IntegrationType name )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
for ( IntegrationNode node : this.modules )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
if ( node.shortName.equals( name ) && node.isActive() )
|
|
|
|
{
|
|
|
|
return node.instance;
|
|
|
|
}
|
|
|
|
}
|
2014-11-13 14:48:04 +01:00
|
|
|
throw new RuntimeException( "integration with " + name.name() + " is disabled." );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|