Added copyrights

Reformated code
Rearrnaged code
Changed the integration registry into a real singleton independent about its instantiation by other classes
This commit is contained in:
thatsIch 2014-11-13 14:48:04 +01:00
parent ae397b0256
commit b37d995d35
4 changed files with 174 additions and 99 deletions

View file

@ -1,9 +1,44 @@
/*
* 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>.
*/
package appeng.core;
import java.io.File;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Stopwatch;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import appeng.api.config.TunnelType;
import appeng.core.api.IIMCHandler;
import appeng.core.api.imc.IMCBlackListSpatial;
@ -23,23 +58,8 @@ import appeng.server.AECommand;
import appeng.services.VersionChecker;
import appeng.util.Platform;
import com.google.common.base.Stopwatch;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
@Mod(modid = AppEng.modid, acceptedMinecraftVersions = "[1.7.10]", name = AppEng.name, version = AEConfig.VERSION, dependencies = AppEng.dependencies, guiFactory = "appeng.client.gui.config.AEConfigGuiFactory")
@Mod( modid = AppEng.modid, acceptedMinecraftVersions = "[1.7.10]", name = AppEng.name, version = AEConfig.VERSION, dependencies = AppEng.dependencies, guiFactory = "appeng.client.gui.config.AEConfigGuiFactory" )
public class AppEng
{
@ -59,18 +79,19 @@ public class AppEng
public final static String dependencies =
// a few mods, AE should load after, probably.
// required-after:AppliedEnergistics2API|all;
// "after:gregtech_addon;after:Mekanism;after:IC2;after:ThermalExpansion;after:BuildCraft|Core;" +
// a few mods, AE should load after, probably.
// required-after:AppliedEnergistics2API|all;
// "after:gregtech_addon;after:Mekanism;after:IC2;after:ThermalExpansion;after:BuildCraft|Core;" +
// depend on version of forge used for build.
"after:appliedenergistics2-core;" + "required-after:Forge@[" // require forge.
+ net.minecraftforge.common.ForgeVersion.majorVersion + "." // majorVersion
+ net.minecraftforge.common.ForgeVersion.minorVersion + "." // minorVersion
+ net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion
+ net.minecraftforge.common.ForgeVersion.buildVersion + ",)"; // buildVersion
// depend on version of forge used for build.
"after:appliedenergistics2-core;" + "required-after:Forge@[" // require forge.
+ net.minecraftforge.common.ForgeVersion.majorVersion + "." // majorVersion
+ net.minecraftforge.common.ForgeVersion.minorVersion + "." // minorVersion
+ net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion
+ net.minecraftforge.common.ForgeVersion.buildVersion + ",)"; // buildVersion
public AppEng() {
public AppEng()
{
instance = this;
IMCHandlers.put( "blacklist-block-spatial", new IMCBlackListSpatial() );
@ -78,7 +99,7 @@ public class AppEng
IMCHandlers.put( "add-grindable", new IMCGrinder() );
IMCHandlers.put( "add-mattercannon-ammo", new IMCMatterCannon() );
for (TunnelType type : TunnelType.values())
for ( TunnelType type : TunnelType.values() )
{
IMCHandlers.put( "add-p2p-attunement-" + type.name().replace( '_', '-' ).toLowerCase(), new IMCP2PAttunement() );
}
@ -86,17 +107,17 @@ public class AppEng
FMLCommonHandler.instance().registerCrashCallable( new CrashEnhancement( CrashInfo.MOD_VERSION ) );
}
public boolean isIntegrationEnabled(IntegrationType Name)
public boolean isIntegrationEnabled( IntegrationType Name )
{
return IntegrationRegistry.instance.isEnabled( Name );
return IntegrationRegistry.INSTANCE.isEnabled( Name );
}
public Object getIntegration(IntegrationType Name)
public Object getIntegration( IntegrationType Name )
{
return IntegrationRegistry.instance.getInstance( Name );
return IntegrationRegistry.INSTANCE.getInstance( Name );
}
private void startService(String serviceName, Thread thread)
private void startService( String serviceName, Thread thread )
{
thread.setName( serviceName );
thread.setPriority( Thread.MIN_PRIORITY );
@ -104,7 +125,7 @@ public class AppEng
}
@EventHandler
void PreInit(FMLPreInitializationEvent event)
void PreInit( FMLPreInitializationEvent event )
{
if ( !Loader.isModLoaded( "appliedenergistics2-core" ) )
{
@ -138,25 +159,25 @@ public class AppEng
}
@EventHandler
void Init(FMLInitializationEvent event)
void Init( FMLInitializationEvent event )
{
Stopwatch star = Stopwatch.createStarted();
AELog.info( "Init" );
Registration.instance.Init( event );
IntegrationRegistry.instance.init();
IntegrationRegistry.INSTANCE.init();
AELog.info( "Init ( end " + star.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
}
@EventHandler
void PostInit(FMLPostInitializationEvent event)
void PostInit( FMLPostInitializationEvent event )
{
Stopwatch star = Stopwatch.createStarted();
AELog.info( "PostInit" );
Registration.instance.PostInit( event );
IntegrationRegistry.instance.postInit();
IntegrationRegistry.INSTANCE.postInit();
FMLCommonHandler.instance().registerCrashCallable( new CrashEnhancement( CrashInfo.INTEGRATION ) );
CommonHelper.proxy.postInit();
@ -169,9 +190,9 @@ public class AppEng
}
@EventHandler
public void processIMC(FMLInterModComms.IMCEvent event)
public void processIMC( FMLInterModComms.IMCEvent event )
{
for (IMCMessage m : event.getMessages())
for ( IMCMessage m : event.getMessages() )
{
try
{
@ -181,7 +202,7 @@ public class AppEng
else
throw new RuntimeException( "Invalid IMC Called: " + m.key );
}
catch (Throwable t)
catch ( Throwable t )
{
AELog.warning( "Problem detected when processing IMC " + m.key + " from " + m.getSender() );
AELog.error( t );
@ -190,20 +211,20 @@ public class AppEng
}
@EventHandler
public void serverStopping(FMLServerStoppingEvent event)
public void serverStopping( FMLServerStoppingEvent event )
{
WorldSettings.getInstance().shutdown();
TickHandler.instance.shutdown();
}
@EventHandler
public void serverStarting(FMLServerAboutToStartEvent evt)
public void serverStarting( FMLServerAboutToStartEvent evt )
{
WorldSettings.getInstance().init();
}
@EventHandler
public void serverStarting(FMLServerStartingEvent evt)
public void serverStarting( FMLServerStartingEvent evt )
{
evt.registerServerCommand( new AECommand( evt.getServer() ) );
}

View file

@ -1,8 +1,29 @@
/*
* 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>.
*/
package appeng.core.crash;
import cpw.mods.fml.common.ICrashCallable;
import appeng.core.AEConfig;
import appeng.integration.IntegrationRegistry;
import cpw.mods.fml.common.ICrashCallable;
public class CrashEnhancement implements ICrashCallable
{
@ -11,13 +32,14 @@ public class CrashEnhancement implements ICrashCallable
private final String value;
private final String ModVersion = AEConfig.CHANNEL + " " + AEConfig.VERSION + " for Forge " + // WHAT?
net.minecraftforge.common.ForgeVersion.majorVersion + "." // majorVersion
net.minecraftforge.common.ForgeVersion.majorVersion + "." // majorVersion
+ net.minecraftforge.common.ForgeVersion.minorVersion + "." // minorVersion
+ net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion
+ net.minecraftforge.common.ForgeVersion.buildVersion;
public CrashEnhancement(CrashInfo Output) {
public CrashEnhancement( CrashInfo Output )
{
if ( Output == CrashInfo.MOD_VERSION )
{
name = "AE2 Version";
@ -25,11 +47,8 @@ public class CrashEnhancement implements ICrashCallable
}
else if ( Output == CrashInfo.INTEGRATION )
{
name ="AE2 Integration";
if ( IntegrationRegistry.instance != null )
value = IntegrationRegistry.instance.getStatus();
else
value = "N/A";
name = "AE2 Integration";
value = IntegrationRegistry.INSTANCE.getStatus();
}
else
{

View file

@ -1,17 +1,37 @@
/*
* 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>.
*/
package appeng.integration;
import java.util.LinkedList;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import cpw.mods.fml.relauncher.Side;
public class IntegrationRegistry
{
public static IntegrationRegistry instance = null;
public enum IntegrationRegistry
{
INSTANCE;
private final LinkedList<IntegrationNode> modules = new LinkedList<IntegrationNode>();
public void add( IntegrationType type)
public void add( IntegrationType type )
{
if ( type.side == IntegrationSide.CLIENT && FMLLaunchHandler.side() == Side.SERVER )
return;
@ -22,22 +42,18 @@ public class IntegrationRegistry
modules.add( new IntegrationNode( type.dspName, type.modID, type, "appeng.integration.modules." + type.name() ) );
}
public IntegrationRegistry() {
instance = this;
}
public void init()
{
for (IntegrationNode node : modules)
for ( IntegrationNode node : modules )
node.Call( IntegrationStage.PRE_INIT );
for (IntegrationNode node : modules)
for ( IntegrationNode node : modules )
node.Call( IntegrationStage.INIT );
}
public void postInit()
{
for (IntegrationNode node : modules)
for ( IntegrationNode node : modules )
node.Call( IntegrationStage.POST_INIT );
}
@ -45,9 +61,9 @@ public class IntegrationRegistry
{
String out = null;
for (IntegrationNode node : modules)
for ( IntegrationNode node : modules )
{
String str = node.shortName + ":" + (node.state == IntegrationStage.FAILED ? "OFF" : "ON");
String str = node.shortName + ":" + ( node.state == IntegrationStage.FAILED ? "OFF" : "ON" );
if ( out == null )
out = str;
@ -58,9 +74,9 @@ public class IntegrationRegistry
return out;
}
public boolean isEnabled(IntegrationType name)
public boolean isEnabled( IntegrationType name )
{
for (IntegrationNode node : modules)
for ( IntegrationNode node : modules )
{
if ( node.shortName == name )
return node.isActive();
@ -68,16 +84,16 @@ public class IntegrationRegistry
return false;
}
public Object getInstance(IntegrationType name)
public Object getInstance( IntegrationType name )
{
for (IntegrationNode node : modules)
for ( IntegrationNode node : modules )
{
if ( node.shortName.equals( name ) && node.isActive() )
{
return node.instance;
}
}
throw new RuntimeException( "integration with "+name.name()+" is disabled." );
throw new RuntimeException( "integration with " + name.name() + " is disabled." );
}
}

View file

@ -1,10 +1,27 @@
/*
* 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>.
*/
package appeng.transformer.asm;
import java.util.Iterator;
import java.util.List;
import net.minecraft.launchwrapper.IClassTransformer;
import org.apache.logging.log4j.Level;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
@ -13,17 +30,19 @@ import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import net.minecraft.launchwrapper.IClassTransformer;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.transformer.annotations.integration;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
public class ASMIntegration implements IClassTransformer
{
private final IntegrationRegistry integrationModules = new IntegrationRegistry();
public ASMIntegration() {
public ASMIntegration()
{
/**
* Side, Display Name, ModID ClassPostFix
@ -31,9 +50,9 @@ public class ASMIntegration implements IClassTransformer
for ( IntegrationType type : IntegrationType.values() )
{
integrationModules.add( type );
IntegrationRegistry.INSTANCE.add( type );
}
// integrationModules.add( IntegrationSide.BOTH, "Thermal Expansion", "ThermalExpansion", IntegrationType.TE );
// integrationModules.add( IntegrationSide.BOTH, "Mystcraft", "Mystcraft", IntegrationType.Mystcraft );
// integrationModules.add( IntegrationSide.BOTH, "Greg Tech", "gregtech_addon", IntegrationType.GT );
@ -46,7 +65,7 @@ public class ASMIntegration implements IClassTransformer
}
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass)
public byte[] transform( String name, String transformedName, byte[] basicClass )
{
if ( basicClass == null || transformedName.startsWith( "appeng.transformer" ) )
return basicClass;
@ -70,7 +89,7 @@ public class ASMIntegration implements IClassTransformer
return writer.toByteArray();
}
}
catch (Throwable t)
catch ( Throwable t )
{
t.printStackTrace();
}
@ -78,13 +97,13 @@ public class ASMIntegration implements IClassTransformer
return basicClass;
}
private boolean removeOptionals(ClassNode classNode)
private boolean removeOptionals( ClassNode classNode )
{
boolean changed = false;
if ( classNode.visibleAnnotations != null )
{
for (AnnotationNode an : classNode.visibleAnnotations)
for ( AnnotationNode an : classNode.visibleAnnotations )
{
if ( hasAnnotation( an, integration.Interface.class ) )
{
@ -93,9 +112,9 @@ public class ASMIntegration implements IClassTransformer
}
else if ( hasAnnotation( an, integration.InterfaceList.class ) )
{
for (Object o : ((List) an.values.get( 1 )))
for ( Object o : ( ( List ) an.values.get( 1 ) ) )
{
if ( stripInterface( classNode, integration.InterfaceList.class, (AnnotationNode) o ) )
if ( stripInterface( classNode, integration.InterfaceList.class, ( AnnotationNode ) o ) )
changed = true;
}
}
@ -103,13 +122,13 @@ public class ASMIntegration implements IClassTransformer
}
Iterator<MethodNode> i = classNode.methods.iterator();
while (i.hasNext())
while ( i.hasNext() )
{
MethodNode mn = i.next();
if ( mn.visibleAnnotations != null )
{
for (AnnotationNode an : mn.visibleAnnotations)
for ( AnnotationNode an : mn.visibleAnnotations )
{
if ( hasAnnotation( an, integration.Method.class ) )
{
@ -127,12 +146,12 @@ public class ASMIntegration implements IClassTransformer
return changed;
}
private boolean hasAnnotation(AnnotationNode ann, Class annotation)
private boolean hasAnnotation( AnnotationNode ann, Class annotation )
{
return ann.desc.equals( Type.getDescriptor( annotation ) );
}
private boolean stripMethod(ClassNode classNode, MethodNode mn, Iterator<MethodNode> i, Class class1, AnnotationNode an)
private boolean stripMethod( ClassNode classNode, MethodNode mn, Iterator<MethodNode> i, Class class1, AnnotationNode an )
{
if ( an.values.size() != 2 )
throw new RuntimeException( "Unable to handle Method annotation on " + classNode.name );
@ -140,12 +159,12 @@ public class ASMIntegration implements IClassTransformer
String iName = null;
if ( an.values.get( 0 ).equals( "iname" ) )
iName = (String) an.values.get( 1 );
iName = ( String ) an.values.get( 1 );
if ( iName != null )
{
IntegrationType type = IntegrationType.valueOf( iName );
if ( !IntegrationRegistry.instance.isEnabled( type ) )
if ( !IntegrationRegistry.INSTANCE.isEnabled( type ) )
{
log( "Removing Method " + mn.name + " from " + classNode.name + " because " + iName + " integration is disabled." );
i.remove();
@ -160,7 +179,7 @@ public class ASMIntegration implements IClassTransformer
return false;
}
private boolean stripInterface(ClassNode classNode, Class class1, AnnotationNode an)
private boolean stripInterface( ClassNode classNode, Class class1, AnnotationNode an )
{
if ( an.values.size() != 4 )
throw new RuntimeException( "Unable to handle Interface annotation on " + classNode.name );
@ -169,20 +188,20 @@ public class ASMIntegration implements IClassTransformer
String iName = null;
if ( an.values.get( 0 ).equals( "iface" ) )
iFace = (String) an.values.get( 1 );
iFace = ( String ) an.values.get( 1 );
else if ( an.values.get( 2 ).equals( "iface" ) )
iFace = (String) an.values.get( 3 );
iFace = ( String ) an.values.get( 3 );
if ( an.values.get( 0 ).equals( "iname" ) )
iName = (String) an.values.get( 1 );
iName = ( String ) an.values.get( 1 );
else if ( an.values.get( 2 ).equals( "iname" ) )
iName = (String) an.values.get( 3 );
iName = ( String ) an.values.get( 3 );
IntegrationType type = IntegrationType.valueOf( iName );
if ( iName != null && iFace != null )
{
if ( !IntegrationRegistry.instance.isEnabled( type ) )
if ( !IntegrationRegistry.INSTANCE.isEnabled( type ) )
{
log( "Removing Interface " + iFace + " from " + classNode.name + " because " + iName + " integration is disabled." );
classNode.interfaces.remove( iFace.replace( '.', '/' ) );
@ -197,7 +216,7 @@ public class ASMIntegration implements IClassTransformer
return false;
}
private void log(String string)
private void log( String string )
{
FMLRelaunchLog.log( "AE2-CORE", Level.INFO, string );
}