Skip to content

Commit

Permalink
Merge pull request #1900 from thatsIch/export-names-to-csv
Browse files Browse the repository at this point in the history
Closes #1899, Fixed #1898: Adds an easy way to export item names
  • Loading branch information
thatsIch committed Oct 6, 2015
2 parents 64e4dc0 + 37ae213 commit c14bc82
Show file tree
Hide file tree
Showing 38 changed files with 1,469 additions and 210 deletions.
4 changes: 0 additions & 4 deletions build.gradle
Expand Up @@ -45,10 +45,6 @@ buildscript {
}
}

configurations.all {
resolutionStrategy.cacheDynamicVersionsFor 7200, 'hours'
}

sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -31,7 +31,7 @@ invtweaks_version=1.58
#########################################################
fmp_version=1.2.0.345
code_chicken_lib_version=1.1.3.138
code_chicken_core_version=1.0.7.46
code_chicken_core_version=1.0.7.47
nei_version=1.0.5.111
bc_version=7.0.9
opencomputers_version=1.5.12.26
Expand Down
2 changes: 1 addition & 1 deletion gradle/scripts/dependencies.gradle
Expand Up @@ -135,5 +135,5 @@ dependencies {
compile(group: 'api', name: 'railcraft', version: "${api_railcraft_version}")
compile(group: 'api', name: 'rf', version: "${api_rf_version}")

testCompile "junit:junit:4.11"
testCompile "junit:junit:4.12"
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,4 +1,4 @@
#Mon Aug 31 16:41:19 CEST 2015
#Tue Sep 01 22:00:39 CEST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
Expand Up @@ -50,6 +50,6 @@ public ItemStack getContainerItem( final ItemStack itemStack )
@Override
public boolean hasContainerItem( final ItemStack stack )
{
return AEConfig.instance.isFeatureEnabled( AEFeature.enableDisassemblyCrafting );
return AEConfig.instance.isFeatureEnabled( AEFeature.EnableDisassemblyCrafting );
}
}
2 changes: 1 addition & 1 deletion src/main/java/appeng/core/AEConfig.java
Expand Up @@ -171,7 +171,7 @@ public AEConfig( final File configFile )

for( final AEFeature feature : AEFeature.values() )
{
if( feature.isVisible )
if( feature.isVisible() )
{
if( this.get( "Features." + feature.category, feature.name(), feature.defaultValue ).getBoolean( feature.defaultValue ) )
{
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/appeng/core/AELog.java
Expand Up @@ -100,4 +100,12 @@ public static void crafting( final String format, final Object... data )
log( Level.INFO, format, data );
}
}

public static void debug( String format, Object... data )
{
if( AEConfig.instance.isFeatureEnabled( AEFeature.DebugLogging ) )
{
log( Level.DEBUG, format, data );
}
}
}
65 changes: 50 additions & 15 deletions src/main/java/appeng/core/AppEng.java
Expand Up @@ -21,11 +21,12 @@

import java.io.File;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nonnull;

import com.google.common.base.Stopwatch;

import net.minecraftforge.common.config.Configuration;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
Expand All @@ -48,8 +49,13 @@
import appeng.core.worlddata.WorldData;
import appeng.hooks.TickHandler;
import appeng.integration.IntegrationRegistry;
import appeng.recipes.CustomRecipeConfig;
import appeng.recipes.CustomRecipeForgeConfiguration;
import appeng.server.AECommand;
import appeng.services.VersionChecker;
import appeng.services.export.ExportConfig;
import appeng.services.export.ExportProcess;
import appeng.services.export.ForgeExportConfig;
import appeng.services.version.VersionCheckerConfig;
import appeng.util.Platform;

Expand All @@ -74,15 +80,28 @@ public final class AppEng
@Nonnull
private static final AppEng INSTANCE = new AppEng();

private final IMCHandler imcHandler;
private final Registration registration;

private File configDirectory;
private CustomRecipeConfig customRecipeConfig;

/**
* Folder for recipes
*
* used for CSV item names and the recipes
*/
private File recipeDirectory;

/**
* determined in pre-init but used in init
*/
private ExportConfig exportConfig;

AppEng()
{
this.imcHandler = new IMCHandler();

FMLCommonHandler.instance().registerCrashCallable( new ModCrashEnhancement( CrashInfo.MOD_VERSION ) );

this.registration = new Registration();
}

@Nonnull
Expand All @@ -92,9 +111,10 @@ public static AppEng instance()
return INSTANCE;
}

public final File getConfigDirectory()
@Nonnull
public final Registration getRegistration()
{
return this.configDirectory;
return this.registration;
}

@EventHandler
Expand All @@ -107,14 +127,19 @@ private void preInit( final FMLPreInitializationEvent event )

final Stopwatch watch = Stopwatch.createStarted();
this.configDirectory = new File( event.getModConfigurationDirectory().getPath(), "AppliedEnergistics2" );
this.recipeDirectory = new File( this.configDirectory, "recipes" );

final File configFile = new File( this.configDirectory, "AppliedEnergistics2.cfg" );
final File facadeFile = new File( this.configDirectory, "Facades.cfg" );
final File versionFile = new File( this.configDirectory, "VersionChecker.cfg" );
final File recipeFile = new File( this.configDirectory, "CustomRecipes.cfg" );
final Configuration recipeConfiguration = new Configuration( recipeFile );

AEConfig.instance = new AEConfig( configFile );
FacadeConfig.instance = new FacadeConfig( facadeFile );
final VersionCheckerConfig versionCheckerConfig = new VersionCheckerConfig( versionFile );
this.customRecipeConfig = new CustomRecipeForgeConfiguration( recipeConfiguration );
this.exportConfig = new ForgeExportConfig( recipeConfiguration );

AELog.info( "Pre Initialization ( started )" );

Expand All @@ -129,9 +154,9 @@ private void preInit( final FMLPreInitializationEvent event )
CommonHelper.proxy.init();
}

Registration.INSTANCE.preInitialize( event );
this.registration.preInitialize( event );

if( versionCheckerConfig.isEnabled() )
if( versionCheckerConfig.isVersionCheckingEnabled() )
{
final VersionChecker versionChecker = new VersionChecker( versionCheckerConfig );
final Thread versionCheckerThread = new Thread( versionChecker );
Expand All @@ -154,22 +179,30 @@ private void startService( final String serviceName, final Thread thread )
@EventHandler
private void init( final FMLInitializationEvent event )
{
final Stopwatch star = Stopwatch.createStarted();
final Stopwatch start = Stopwatch.createStarted();
AELog.info( "Initialization ( started )" );

Registration.INSTANCE.initialize( event );
if( exportConfig.isExportingItemNamesEnabled() )
{
final ExportProcess process = new ExportProcess( this.recipeDirectory, exportConfig );
final Thread exportProcessThread = new Thread( process );

this.startService( "AE2 CSV Export", exportProcessThread );
}

this.registration.initialize( event, this.recipeDirectory, this.customRecipeConfig );
IntegrationRegistry.INSTANCE.init();

AELog.info( "Initialization ( ended after " + star.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
AELog.info( "Initialization ( ended after " + start.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
}

@EventHandler
private void postInit( final FMLPostInitializationEvent event )
{
final Stopwatch star = Stopwatch.createStarted();
final Stopwatch start = Stopwatch.createStarted();
AELog.info( "Post Initialization ( started )" );

Registration.INSTANCE.postInit( event );
this.registration.postInit( event );
IntegrationRegistry.INSTANCE.postInit();
FMLCommonHandler.instance().registerCrashCallable( new IntegrationCrashEnhancement() );

Expand All @@ -179,13 +212,15 @@ private void postInit( final FMLPostInitializationEvent event )
NetworkRegistry.INSTANCE.registerGuiHandler( this, GuiBridge.GUI_Handler );
NetworkHandler.instance = new NetworkHandler( "AE2" );

AELog.info( "Post Initialization ( ended after " + star.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
AELog.info( "Post Initialization ( ended after " + start.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
}

@EventHandler
private void handleIMCEvent( final FMLInterModComms.IMCEvent event )
{
this.imcHandler.handleIMCEvent( event );
final IMCHandler imcHandler = new IMCHandler();

imcHandler.handleIMCEvent( event );
}

@EventHandler
Expand Down
87 changes: 52 additions & 35 deletions src/main/java/appeng/core/RecipeLoader.java
Expand Up @@ -22,14 +22,14 @@
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

import javax.annotation.Nonnull;

import com.google.common.base.Preconditions;

import org.apache.commons.io.FileUtils;

import appeng.api.recipes.IRecipeHandler;
import appeng.recipes.CustomRecipeConfig;
import appeng.recipes.loader.ConfigLoader;
import appeng.recipes.loader.JarLoader;
import appeng.recipes.loader.RecipeResourceCopier;
Expand All @@ -44,57 +44,74 @@
*/
public class RecipeLoader implements Runnable
{
/**
* recipe path in the jar
*/
private static final String ASSETS_RECIPE_PATH = "/assets/appliedenergistics2/recipes/";

@Nonnull
private final IRecipeHandler handler;
@Nonnull
private final CustomRecipeConfig config;
@Nonnull
private final File recipeDirectory;

/**
* @param config configuration for the knowledge how to handle the loading process
* @param handler handler to load the recipes
*
* @throws NullPointerException if handler is <tt>null</tt>
*/
public RecipeLoader( @Nonnull final IRecipeHandler handler )
public RecipeLoader( @Nonnull final File recipeDirectory, @Nonnull final CustomRecipeConfig config, @Nonnull final IRecipeHandler handler )
{
Preconditions.checkNotNull( handler );

this.handler = handler;
this.recipeDirectory = Preconditions.checkNotNull( recipeDirectory );
Preconditions.checkArgument( !recipeDirectory.isFile() );
this.config = Preconditions.checkNotNull( config );
this.handler = Preconditions.checkNotNull( handler );
}

@Override
public void run()
public final void run()
{
// setup copying
final RecipeResourceCopier copier = new RecipeResourceCopier( "assets/appliedenergistics2/recipes/" );
final File configDirectory = AppEng.instance().getConfigDirectory();
final File generatedRecipesDir = new File( configDirectory, "generated-recipes" );
final File userRecipesDir = new File( configDirectory, "user-recipes" );
final File readmeGenDest = new File( generatedRecipesDir, "README.html" );
final File readmeUserDest = new File( userRecipesDir, "README.html" );

// generates generated and user recipes dir
// will clean the generated every time to keep it up to date
// copies over the recipes in the jar over to the generated folder
// copies over the readmes
try
if( this.config.isEnabled() )
{
FileUtils.forceMkdir( generatedRecipesDir );
FileUtils.forceMkdir( userRecipesDir );
FileUtils.cleanDirectory( generatedRecipesDir );
// setup copying
final RecipeResourceCopier copier = new RecipeResourceCopier( "assets/appliedenergistics2/recipes/" );

copier.copyTo( generatedRecipesDir );
FileUtils.copyFile( readmeGenDest, readmeUserDest );
final File generatedRecipesDir = new File( this.recipeDirectory, "generated" );
final File userRecipesDir = new File( this.recipeDirectory, "user" );

// parse recipes prioritising the user scripts by using the generated as template
this.handler.parseRecipes( new ConfigLoader( generatedRecipesDir, userRecipesDir ), "index.recipe" );
}
// on failure use jar parsing
catch( final IOException e )
{
AELog.error( e );
this.handler.parseRecipes( new JarLoader( "/assets/appliedenergistics2/recipes/" ), "index.recipe" );
// generates generated and user recipes dir
// will clean the generated every time to keep it up to date
// copies over the recipes in the jar over to the generated folder
// copies over the readmes
try
{
FileUtils.forceMkdir( generatedRecipesDir );
FileUtils.forceMkdir( userRecipesDir );
FileUtils.cleanDirectory( generatedRecipesDir );

copier.copyTo( ".recipe", generatedRecipesDir );
copier.copyTo( ".html", recipeDirectory );

// parse recipes prioritising the user scripts by using the generated as template
this.handler.parseRecipes( new ConfigLoader( generatedRecipesDir, userRecipesDir ), "index.recipe" );
}
// on failure use jar parsing
catch( final IOException e )
{
AELog.error( e );
this.handler.parseRecipes( new JarLoader( ASSETS_RECIPE_PATH ), "index.recipe" );
}
catch( final URISyntaxException e )
{
AELog.error( e );
this.handler.parseRecipes( new JarLoader( ASSETS_RECIPE_PATH ), "index.recipe" );
}
}
catch( final URISyntaxException e )
else
{
AELog.error( e );
this.handler.parseRecipes( new JarLoader( "/assets/appliedenergistics2/recipes/" ), "index.recipe" );
this.handler.parseRecipes( new JarLoader( ASSETS_RECIPE_PATH ), "index.recipe" );
}
}
}

0 comments on commit c14bc82

Please sign in to comment.