Rework custom recipe system (#3232)

This commit is contained in:
fscan
2018-06-24 17:20:29 +02:00
committed by GitHub
parent e72b5b369c
commit 841bc6e356
165 changed files with 680 additions and 6300 deletions
+2 -16
View File
@@ -58,8 +58,6 @@ import appeng.core.worlddata.WorldData;
import appeng.hooks.TickHandler;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.recipes.CustomRecipeConfig;
import appeng.recipes.CustomRecipeForgeConfiguration;
import appeng.server.AECommand;
import appeng.services.VersionChecker;
import appeng.services.export.ExportConfig;
@@ -98,14 +96,6 @@ public final class AppEng
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
@@ -152,7 +142,6 @@ public final class AppEng
{
final Stopwatch watch = Stopwatch.createStarted();
this.configDirectory = new File( event.getModConfigurationDirectory().getPath(), "AppliedEnergistics2" );
this.recipeDirectory = new File( this.configDirectory, "aerecipes" );
final File configFile = new File( this.configDirectory, "AppliedEnergistics2.cfg" );
final File facadeFile = new File( this.configDirectory, "Facades.cfg" );
@@ -164,11 +153,8 @@ public final class AppEng
FacadeConfig.init( facadeFile );
final VersionCheckerConfig versionCheckerConfig = new VersionCheckerConfig( versionFile );
this.customRecipeConfig = new CustomRecipeForgeConfiguration( recipeConfiguration );
this.exportConfig = new ForgeExportConfig( recipeConfiguration );
this.registration.setRecipeInformation( this.recipeDirectory, this.customRecipeConfig );
AELog.info( "Pre Initialization ( started )" );
CreativeTab.init();
@@ -226,7 +212,7 @@ public final class AppEng
{
if( FMLCommonHandler.instance().getSide().isClient() )
{
final ExportProcess process = new ExportProcess( this.recipeDirectory, this.exportConfig );
final ExportProcess process = new ExportProcess( this.configDirectory, this.exportConfig );
final Thread exportProcessThread = new Thread( process );
this.startService( "AE2 CSV Export", exportProcessThread );
@@ -237,7 +223,7 @@ public final class AppEng
}
}
this.registration.initialize( event, this.recipeDirectory, this.customRecipeConfig );
this.registration.initialize( event, this.configDirectory );
IntegrationRegistry.INSTANCE.init();
AELog.info( "Initialization ( ended after " + start.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
-118
View File
@@ -1,118 +0,0 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.core;
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;
/**
* handles the decision if recipes should be loaded from jar, loaded from file system or force copied from jar
*
* @author thatsIch
* @version rv3 - 12.05.2015
* @since rv3 12.05.2015
*/
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 File recipeDirectory, @Nonnull final CustomRecipeConfig config, @Nonnull final IRecipeHandler handler )
{
this.recipeDirectory = Preconditions.checkNotNull( recipeDirectory );
Preconditions.checkArgument( !recipeDirectory.isFile() );
this.config = Preconditions.checkNotNull( config );
this.handler = Preconditions.checkNotNull( handler );
}
@Override
public final void run()
{
if( this.config.isEnabled() )
{
// setup copying
final RecipeResourceCopier copier = new RecipeResourceCopier( "assets/appliedenergistics2/aerecipes/" );
final File generatedRecipesDir = new File( this.recipeDirectory, "generated" );
final File userRecipesDir = new File( this.recipeDirectory, "user" );
// 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", this.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.debug( e );
this.handler.parseRecipes( new JarLoader( ASSETS_RECIPE_PATH ), "index.recipe" );
}
catch( final URISyntaxException e )
{
AELog.debug( e );
this.handler.parseRecipes( new JarLoader( ASSETS_RECIPE_PATH ), "index.recipe" );
}
}
else
{
this.handler.parseRecipes( new JarLoader( ASSETS_RECIPE_PATH ), "index.recipe" );
}
}
}
+6 -67
View File
@@ -77,7 +77,6 @@ import appeng.api.networking.spatial.ISpatialCache;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.networking.ticking.ITickManager;
import appeng.api.parts.IPartHelper;
import appeng.api.recipes.IRecipeHandler;
import appeng.bootstrap.ICriterionTriggerRegistry;
import appeng.bootstrap.IModelRegistry;
import appeng.bootstrap.components.IBlockRegistrationComponent;
@@ -103,6 +102,7 @@ import appeng.fluids.registries.BasicFluidCellHandler;
import appeng.hooks.TickHandler;
import appeng.items.materials.ItemMaterial;
import appeng.items.parts.ItemFacade;
import appeng.items.parts.ItemPart;
import appeng.loot.ChestLoot;
import appeng.me.cache.CraftingGridCache;
import appeng.me.cache.EnergyGridCache;
@@ -114,20 +114,9 @@ import appeng.me.cache.SpatialPylonCache;
import appeng.me.cache.TickManagerCache;
import appeng.parts.PartPlacement;
import appeng.recipes.AEItemResolver;
import appeng.recipes.CustomRecipeConfig;
import appeng.recipes.RecipeHandler;
import appeng.recipes.AERecipeLoader;
import appeng.recipes.game.DisassembleRecipe;
import appeng.recipes.game.FacadeRecipe;
import appeng.recipes.handlers.Crusher;
import appeng.recipes.handlers.Grind;
import appeng.recipes.handlers.HCCrusher;
import appeng.recipes.handlers.Inscribe;
import appeng.recipes.handlers.Macerator;
import appeng.recipes.handlers.MekCrusher;
import appeng.recipes.handlers.MekEnrichment;
import appeng.recipes.handlers.Press;
import appeng.recipes.handlers.Pulverizer;
import appeng.recipes.handlers.Smelt;
import appeng.recipes.ores.OreDictionaryHandler;
import appeng.spatial.BiomeGenStorage;
import appeng.spatial.StorageWorldProvider;
@@ -143,15 +132,6 @@ final class Registration
Biome storageBiome;
AdvancementTriggers advancementTriggers;
private File recipeDirectory;
private CustomRecipeConfig customRecipeConfig;
public void setRecipeInformation( File f, CustomRecipeConfig f2 )
{
this.recipeDirectory = f;
this.customRecipeConfig = f2;
}
void preInitialize( final FMLPreInitializationEvent event )
{
Capabilities.register();
@@ -160,10 +140,6 @@ final class Registration
final IRecipeHandlerRegistry recipeRegistry = api.registries().recipes();
this.registerCraftHandlers( recipeRegistry );
// RecipeSorter.register( "AE2-Facade", FacadeRecipe.class, Category.SHAPED, "" );
// RecipeSorter.register( "AE2-Shaped", ShapedRecipe.class, Category.SHAPED, "" );
// RecipeSorter.register( "AE2-Shapeless", ShapelessRecipe.class, Category.SHAPELESS, "" );
MinecraftForge.EVENT_BUS.register( OreDictionaryHandler.INSTANCE );
ApiDefinitions definitions = api.definitions();
@@ -226,26 +202,13 @@ final class Registration
private void registerCraftHandlers( final IRecipeHandlerRegistry registry )
{
registry.addNewSubItemResolver( new AEItemResolver() );
registry.addNewCraftHandler( "hccrusher", HCCrusher.class );
registry.addNewCraftHandler( "mekcrusher", MekCrusher.class );
registry.addNewCraftHandler( "mekechamber", MekEnrichment.class );
registry.addNewCraftHandler( "grind", Grind.class );
registry.addNewCraftHandler( "crusher", Crusher.class );
registry.addNewCraftHandler( "pulverizer", Pulverizer.class );
registry.addNewCraftHandler( "macerator", Macerator.class );
registry.addNewCraftHandler( "smelt", Smelt.class );
registry.addNewCraftHandler( "inscribe", Inscribe.class );
registry.addNewCraftHandler( "press", Press.class );
}
public void initialize( @Nonnull final FMLInitializationEvent event, @Nonnull final File recipeDirectory, @Nonnull final CustomRecipeConfig customRecipeConfig )
public void initialize( @Nonnull final FMLInitializationEvent event, @Nonnull final File recipeDirectory )
{
Preconditions.checkNotNull( event );
Preconditions.checkNotNull( recipeDirectory );
Preconditions.checkArgument( !recipeDirectory.isFile() );
Preconditions.checkNotNull( customRecipeConfig );
final Api api = Api.INSTANCE;
final IPartHelper partHelper = api.partHelper();
@@ -255,19 +218,6 @@ final class Registration
definitions.getRegistry().getBootstrapComponents( IOreDictComponent.class ).forEachRemaining( b -> b.oreRegistration( event.getSide() ) );
definitions.getRegistry().getBootstrapComponents( IInitComponent.class ).forEachRemaining( b -> b.initialize( event.getSide() ) );
//
// // Perform ore camouflage!
// ItemMaterial.instance.makeUnique();
// final Runnable recipeLoader = new RecipeLoader( recipeDirectory, customRecipeConfig, this.recipeHandler );
// recipeLoader.run();
// if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.OpenComputers ) )
// {
// partHelper.registerNewLayer( "appeng.parts.layers.LayerSidedEnvironment",
// "li.cil.oc.api.network.SidedEnvironment" );
// }
MinecraftForge.EVENT_BUS.register( TickHandler.INSTANCE );
MinecraftForge.EVENT_BUS.register( new PartPlacement() );
@@ -349,13 +299,12 @@ final class Registration
// Perform ore camouflage!
ItemMaterial.instance.makeUnique();
ItemPart.instance.registerOreDicts();
if( AEConfig.instance().isFeatureEnabled( AEFeature.ENABLE_DISASSEMBLY_CRAFTING ) )
{
DisassembleRecipe r = new DisassembleRecipe();
registry.register( r.setRegistryName( AppEng.MOD_ID.toLowerCase(), "disassemble" ) );
// RecipeSorter.register( "appliedenergistics2:disassemble", DisassembleRecipe.class, Category.SHAPELESS,
// "after:minecraft:shapeless" );
}
if( AEConfig.instance().isFeatureEnabled( AEFeature.ENABLE_FACADE_CRAFTING ) )
@@ -364,18 +313,13 @@ final class Registration
{
FacadeRecipe f = new FacadeRecipe( (ItemFacade) facadeItem );
registry.register( f.setRegistryName( AppEng.MOD_ID.toLowerCase(), "facade" ) );
// RecipeSorter.register( "appliedenergistics2:facade", FacadeRecipe.class, Category.SHAPED,
// "after:minecraft:shaped" );
} );
}
definitions.getRegistry().getBootstrapComponents( IRecipeRegistrationComponent.class ).forEachRemaining( b -> b.recipeRegistration( side, registry ) );
// load machine recipes
final IRecipeHandler recipeHandler = new RecipeHandler();
final Runnable recipeLoader = new RecipeLoader( this.recipeDirectory, this.customRecipeConfig, recipeHandler );
recipeLoader.run();
recipeHandler.injectRecipes();
final AERecipeLoader ldr = new AERecipeLoader();
ldr.loadProcessingRecipes();
}
@SubscribeEvent
@@ -572,11 +516,6 @@ final class Registration
{
registries.worldgen().enableWorldGenForDimension( WorldGenType.METEORITES, dimension );
}
/*
* initial recipe bake, if ore dictionary changes after this it re-bakes.
*/
OreDictionaryHandler.INSTANCE.bakeRecipes();
}
private static class ModelLoaderWrapper implements IModelRegistry
@@ -250,7 +250,11 @@ public final class ApiBlocks implements IBlocks
this.quartzOreCharged = registry.block( "charged_quartz_ore", BlockChargedQuartzOre::new )
.features( AEFeature.CERTUS_ORE, AEFeature.CHARGED_CERTUS_ORE )
.useCustomItemModel()
.bootstrap( ( block, item ) -> (IOreDictComponent) side -> OreDictionary.registerOre( "oreCertusQuartz", new ItemStack( block ) ) )
.bootstrap( ( block, item ) -> (IOreDictComponent) side ->
{
OreDictionary.registerOre( "oreCertusQuartz", new ItemStack( block ) );
OreDictionary.registerOre( "oreChargedCertusQuartz", new ItemStack( block ) );
} )
.build();
this.matrixFrame = registry.block( "matrix_frame", BlockMatrixFrame::new ).features( AEFeature.SPATIAL_IO ).build();