Uses an instance factory access for AE2
Removes the improper way to set itself into a public static non-final variable. Removes the direct access to the IntegrationRegistry from AppEng. Will be added at some later point somewhere else for non-singleton access. Constructor is set to package private to enable possible construction from unit tests. Are current not runnable sind it is currently tied to the FML Loader instance.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* 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
|
||||
@@ -21,6 +21,7 @@ package appeng.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
|
||||
@@ -45,7 +46,6 @@ import appeng.core.sync.GuiBridge;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.integration.IntegrationRegistry;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.server.AECommand;
|
||||
import appeng.services.VersionChecker;
|
||||
import appeng.services.version.VersionCheckerConfig;
|
||||
@@ -68,38 +68,35 @@ public final class AppEng
|
||||
+ net.minecraftforge.common.ForgeVersion.minorVersion + '.' // minorVersion
|
||||
+ net.minecraftforge.common.ForgeVersion.revisionVersion + '.' // revisionVersion
|
||||
+ net.minecraftforge.common.ForgeVersion.buildVersion + ",)"; // buildVersion
|
||||
public static AppEng instance;
|
||||
|
||||
@Nonnull
|
||||
private static final AppEng INSTANCE = new AppEng();
|
||||
|
||||
private final IMCHandler imcHandler;
|
||||
|
||||
private File configDirectory;
|
||||
|
||||
public AppEng()
|
||||
AppEng()
|
||||
{
|
||||
instance = this;
|
||||
|
||||
this.imcHandler = new IMCHandler();
|
||||
|
||||
FMLCommonHandler.instance().registerCrashCallable( new ModCrashEnhancement( CrashInfo.MOD_VERSION ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Mod.InstanceFactory
|
||||
public static AppEng instance()
|
||||
{
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public final File getConfigDirectory()
|
||||
{
|
||||
return this.configDirectory;
|
||||
}
|
||||
|
||||
public boolean isIntegrationEnabled( IntegrationType integrationName )
|
||||
{
|
||||
return IntegrationRegistry.INSTANCE.isEnabled( integrationName );
|
||||
}
|
||||
|
||||
public Object getIntegration( IntegrationType integrationName )
|
||||
{
|
||||
return IntegrationRegistry.INSTANCE.getInstance( integrationName );
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void preInit( FMLPreInitializationEvent event )
|
||||
private void preInit( FMLPreInitializationEvent event )
|
||||
{
|
||||
if( !Loader.isModLoaded( "appliedenergistics2-core" ) )
|
||||
{
|
||||
@@ -153,7 +150,7 @@ public final class AppEng
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void init( FMLInitializationEvent event )
|
||||
private void init( FMLInitializationEvent event )
|
||||
{
|
||||
Stopwatch star = Stopwatch.createStarted();
|
||||
AELog.info( "Initialization ( started )" );
|
||||
@@ -165,7 +162,7 @@ public final class AppEng
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void postInit( FMLPostInitializationEvent event )
|
||||
private void postInit( FMLPostInitializationEvent event )
|
||||
{
|
||||
Stopwatch star = Stopwatch.createStarted();
|
||||
AELog.info( "Post Initialization ( started )" );
|
||||
@@ -184,26 +181,26 @@ public final class AppEng
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleIMCEvent( FMLInterModComms.IMCEvent event )
|
||||
private void handleIMCEvent( FMLInterModComms.IMCEvent event )
|
||||
{
|
||||
this.imcHandler.handleIMCEvent( event );
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void serverStopping( FMLServerStoppingEvent event )
|
||||
private void serverStopping( FMLServerStoppingEvent event )
|
||||
{
|
||||
WorldSettings.getInstance().shutdown();
|
||||
TickHandler.INSTANCE.shutdown();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void serverAboutToStart( FMLServerAboutToStartEvent evt )
|
||||
private void serverAboutToStart( FMLServerAboutToStartEvent evt )
|
||||
{
|
||||
WorldSettings.getInstance().init();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void serverStarting( FMLServerStartingEvent evt )
|
||||
private void serverStarting( FMLServerStartingEvent evt )
|
||||
{
|
||||
evt.registerServerCommand( new AECommand( evt.getServer() ) );
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* 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
|
||||
@@ -38,6 +38,8 @@ import appeng.core.api.imc.IMCSpatial;
|
||||
*/
|
||||
public class IMCHandler
|
||||
{
|
||||
private static final int INITIAL_PROCESSORS_CAPACITY = 20;
|
||||
|
||||
/**
|
||||
* Contains the processors,
|
||||
*
|
||||
@@ -51,7 +53,7 @@ public class IMCHandler
|
||||
*/
|
||||
public IMCHandler()
|
||||
{
|
||||
this.processors = new HashMap<String, IIMCProcessor>();
|
||||
this.processors = new HashMap<String, IIMCProcessor>( INITIAL_PROCESSORS_CAPACITY );
|
||||
|
||||
this.processors.put( "blacklist-block-spatial", new IMCBlackListSpatial() );
|
||||
this.processors.put( "whitelist-spatial", new IMCSpatial() );
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* 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
|
||||
@@ -76,6 +76,7 @@ import appeng.core.localization.PlayerMessages;
|
||||
import appeng.core.stats.PlayerStatsRegistration;
|
||||
import appeng.hooks.AETrading;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.integration.IntegrationRegistry;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.items.materials.ItemMultiMaterial;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
@@ -517,7 +518,7 @@ public final class Registration
|
||||
|
||||
if( AEConfig.instance.isFeatureEnabled( AEFeature.CustomRecipes ) )
|
||||
{
|
||||
this.recipeHandler.parseRecipes( new ConfigLoader( AppEng.instance.getConfigDirectory() ), "index.recipe" );
|
||||
this.recipeHandler.parseRecipes( new ConfigLoader( AppEng.instance().getConfigDirectory() ), "index.recipe" );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -528,18 +529,18 @@ public final class Registration
|
||||
partHelper.registerNewLayer( "appeng.parts.layers.LayerIFluidHandler", "net.minecraftforge.fluids.IFluidHandler" );
|
||||
partHelper.registerNewLayer( "appeng.parts.layers.LayerITileStorageMonitorable", "appeng.api.implementations.tiles.ITileStorageMonitorable" );
|
||||
|
||||
if( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) )
|
||||
if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.IC2 ) )
|
||||
{
|
||||
partHelper.registerNewLayer( "appeng.parts.layers.LayerIEnergySink", "ic2.api.energy.tile.IEnergySink" );
|
||||
partHelper.registerNewLayer( "appeng.parts.layers.LayerIEnergySource", "ic2.api.energy.tile.IEnergySource" );
|
||||
}
|
||||
|
||||
if( AppEng.instance.isIntegrationEnabled( IntegrationType.RF ) )
|
||||
if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.RF ) )
|
||||
{
|
||||
partHelper.registerNewLayer( "appeng.parts.layers.LayerIEnergyHandler", "cofh.api.energy.IEnergyReceiver" );
|
||||
}
|
||||
|
||||
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.OpenComputers ) )
|
||||
if ( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.OpenComputers ) )
|
||||
{
|
||||
partHelper.registerNewLayer( "appeng.parts.layers.LayerSidedEnvironment", "li.cil.oc.api.network.SidedEnvironment" );
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* 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
|
||||
@@ -52,8 +52,8 @@ import appeng.api.parts.IPartItem;
|
||||
import appeng.api.parts.LayerBase;
|
||||
import appeng.client.render.BusRenderer;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CommonHelper;
|
||||
import appeng.integration.IntegrationRegistry;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IFMP;
|
||||
import appeng.parts.PartPlacement;
|
||||
@@ -73,9 +73,9 @@ public class ApiPart implements IPartHelper
|
||||
{
|
||||
for( Class layerInterface : this.interfaces2Layer.keySet() )
|
||||
{
|
||||
if( AppEng.instance.isIntegrationEnabled( IntegrationType.FMP ) )
|
||||
if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.FMP ) )
|
||||
{
|
||||
( (IFMP) AppEng.instance.getIntegration( IntegrationType.FMP ) ).registerPassThrough( layerInterface );
|
||||
( (IFMP) IntegrationRegistry.INSTANCE.getInstance( IntegrationType.FMP ) ).registerPassThrough( layerInterface );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* 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
|
||||
@@ -26,9 +26,9 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.core.sync.network.INetworkInfo;
|
||||
import appeng.integration.IntegrationRegistry;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IFMP;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class PacketMultiPart extends AppEngPacket
|
||||
@Override
|
||||
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
|
||||
{
|
||||
IFMP fmp = (IFMP) AppEng.instance.getIntegration( IntegrationType.FMP );
|
||||
IFMP fmp = (IFMP) IntegrationRegistry.INSTANCE.getInstance( IntegrationType.FMP );
|
||||
if( fmp != null )
|
||||
{
|
||||
EntityPlayerMP sender = (EntityPlayerMP) player;
|
||||
|
||||
Reference in New Issue
Block a user