2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
2015-05-17 23:51:57 +02:00
|
|
|
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
2014-11-14 12:02:52 +01:00
|
|
|
*
|
|
|
|
* 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-02-10 04:16:36 +01:00
|
|
|
package appeng.recipes;
|
|
|
|
|
2014-11-28 04:36:46 +01:00
|
|
|
|
2014-02-11 06:51:25 +01:00
|
|
|
import java.io.BufferedReader;
|
2014-03-05 20:34:56 +01:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
2014-02-10 04:16:36 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2015-05-17 23:51:57 +02:00
|
|
|
import java.util.Map;
|
2014-02-11 06:51:25 +01:00
|
|
|
import java.util.Map.Entry;
|
2014-03-05 20:34:56 +01:00
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
import java.util.zip.ZipOutputStream;
|
2015-04-05 20:16:02 +02:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
2015-05-08 23:34:24 +02:00
|
|
|
import com.google.common.base.Optional;
|
|
|
|
import com.google.common.collect.HashMultimap;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
import net.minecraft.item.Item;
|
2014-03-05 20:34:56 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-11-28 04:36:46 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.common.LoaderState;
|
|
|
|
import cpw.mods.fml.common.registry.GameRegistry;
|
|
|
|
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
|
|
|
|
2014-02-20 00:33:36 +01:00
|
|
|
import appeng.api.AEApi;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IBlocks;
|
|
|
|
import appeng.api.definitions.IDefinitions;
|
|
|
|
import appeng.api.definitions.IItems;
|
2014-02-20 00:33:36 +01:00
|
|
|
import appeng.api.exceptions.MissingIngredientError;
|
|
|
|
import appeng.api.exceptions.RecipeError;
|
|
|
|
import appeng.api.exceptions.RegistrationError;
|
|
|
|
import appeng.api.features.IRecipeHandlerRegistry;
|
|
|
|
import appeng.api.recipes.ICraftHandler;
|
|
|
|
import appeng.api.recipes.IIngredient;
|
2014-02-11 06:51:25 +01:00
|
|
|
import appeng.api.recipes.IRecipeHandler;
|
|
|
|
import appeng.api.recipes.IRecipeLoader;
|
2014-03-05 20:34:56 +01:00
|
|
|
import appeng.core.AEConfig;
|
2014-02-10 04:16:36 +01:00
|
|
|
import appeng.core.AELog;
|
2014-03-09 22:39:30 +01:00
|
|
|
import appeng.core.AppEng;
|
2014-03-05 20:34:56 +01:00
|
|
|
import appeng.core.features.AEFeature;
|
2014-05-06 07:16:29 +02:00
|
|
|
import appeng.items.materials.ItemMultiMaterial;
|
2014-03-13 05:50:26 +01:00
|
|
|
import appeng.items.misc.ItemCrystalSeed;
|
2014-05-06 07:16:29 +02:00
|
|
|
import appeng.items.parts.ItemMultiPart;
|
2014-11-28 04:36:46 +01:00
|
|
|
import appeng.recipes.handlers.IWebsiteSerializer;
|
2014-02-11 06:51:25 +01:00
|
|
|
import appeng.recipes.handlers.OreRegistration;
|
2014-07-26 04:52:21 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-04-05 20:16:02 +02:00
|
|
|
/**
|
|
|
|
* @author AlgorithmX2
|
|
|
|
* @author thatsIch
|
|
|
|
* @version rv2
|
|
|
|
* @since rv0
|
|
|
|
*/
|
2014-02-11 06:51:25 +01:00
|
|
|
public class RecipeHandler implements IRecipeHandler
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
|
|
|
|
2015-04-06 00:35:42 +02:00
|
|
|
public final List<String> tokens = new LinkedList<String>();
|
2014-02-11 06:51:25 +01:00
|
|
|
final RecipeData data;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public RecipeHandler()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.data = new RecipeData();
|
2014-02-11 06:51:25 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
RecipeHandler( RecipeHandler parent )
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.data = parent.data;
|
2014-02-11 06:51:25 +01:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private void addCrafting( ICraftHandler ch )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.data.Handlers.add( ch );
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
|
|
|
|
2015-04-05 20:16:02 +02:00
|
|
|
public String getName( @Nonnull IIngredient i )
|
2014-03-05 20:34:56 +01:00
|
|
|
{
|
2014-02-11 00:15:43 +01:00
|
|
|
try
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack is : i.getItemStackSet() )
|
2014-03-09 22:39:30 +01:00
|
|
|
{
|
2015-04-05 20:16:02 +02:00
|
|
|
return this.getName( is );
|
2014-03-09 22:39:30 +01:00
|
|
|
}
|
2014-03-05 20:34:56 +01:00
|
|
|
}
|
2015-04-05 20:16:02 +02:00
|
|
|
catch( RecipeError ignored )
|
|
|
|
{
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable t )
|
2014-03-05 20:34:56 +01:00
|
|
|
{
|
2014-03-09 00:31:09 +01:00
|
|
|
t.printStackTrace();
|
2014-03-05 20:34:56 +01:00
|
|
|
// :P
|
|
|
|
}
|
2014-03-06 06:52:25 +01:00
|
|
|
|
2014-11-28 04:36:46 +01:00
|
|
|
return i.getNameSpace() + ':' + i.getItemName();
|
2014-03-05 20:34:56 +01:00
|
|
|
}
|
2014-03-06 06:52:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public String getName( ItemStack is ) throws RecipeError
|
2014-03-06 06:52:25 +01:00
|
|
|
{
|
|
|
|
UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor( is.getItem() );
|
2014-11-28 04:36:46 +01:00
|
|
|
String realName = id.modId + ':' + id.name;
|
2014-03-06 06:52:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !id.modId.equals( AppEng.MOD_ID ) && !id.modId.equals( "minecraft" ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-03-09 22:39:30 +01:00
|
|
|
throw new RecipeError( "Not applicable for website" );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-03-09 22:39:30 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
final IDefinitions definitions = AEApi.instance().definitions();
|
|
|
|
final IItems items = definitions.items();
|
|
|
|
final IBlocks blocks = definitions.blocks();
|
|
|
|
|
|
|
|
final Optional<Item> maybeCrystalSeedItem = items.crystalSeed().maybeItem();
|
|
|
|
final Optional<Item> maybeSkyStoneItem = blocks.skyStone().maybeItem();
|
2015-05-08 23:34:24 +02:00
|
|
|
final Optional<Item> maybeCStorageItem = blocks.craftingStorage1k().maybeItem();
|
|
|
|
final Optional<Item> maybeCUnitItem = blocks.craftingUnit().maybeItem();
|
2015-01-03 02:53:14 +01:00
|
|
|
final Optional<Item> maybeSkyChestItem = blocks.skyChest().maybeItem();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( maybeCrystalSeedItem.isPresent() && is.getItem() == maybeCrystalSeedItem.get() )
|
2014-03-13 05:50:26 +01:00
|
|
|
{
|
|
|
|
int dmg = is.getItemDamage();
|
2015-05-08 23:37:09 +02:00
|
|
|
if( dmg < ItemCrystalSeed.NETHER )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-03-13 05:50:26 +01:00
|
|
|
realName += ".Certus";
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-05-08 23:37:09 +02:00
|
|
|
else if( dmg < ItemCrystalSeed.FLUIX )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-03-13 05:50:26 +01:00
|
|
|
realName += ".Nether";
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-05-08 23:37:09 +02:00
|
|
|
else if( dmg < ItemCrystalSeed.FINAL_STAGE )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-03-13 05:50:26 +01:00
|
|
|
realName += ".Fluix";
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-03-13 05:50:26 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( maybeSkyStoneItem.isPresent() && is.getItem() == maybeSkyStoneItem.get() )
|
2014-03-09 04:35:53 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( is.getItemDamage() )
|
2014-03-09 04:35:53 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case 1:
|
|
|
|
realName += ".Block";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
realName += ".Brick";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
realName += ".SmallBrick";
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-09 04:35:53 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-08 23:34:24 +02:00
|
|
|
else if( maybeCStorageItem.isPresent() && is.getItem() == maybeCStorageItem.get() )
|
2014-07-12 21:27:20 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( is.getItemDamage() )
|
2014-07-12 21:27:20 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case 1:
|
|
|
|
realName += "4k";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
realName += "16k";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
realName += "64k";
|
|
|
|
break;
|
|
|
|
default:
|
2014-07-12 21:27:20 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-08 23:34:24 +02:00
|
|
|
else if( maybeCUnitItem.isPresent() && is.getItem() == maybeCUnitItem.get() )
|
2014-07-12 21:27:20 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( is.getItemDamage() )
|
2014-07-12 21:27:20 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case 1:
|
|
|
|
realName = realName.replace( "Unit", "Accelerator" );
|
|
|
|
break;
|
|
|
|
default:
|
2014-07-12 21:27:20 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( maybeSkyChestItem.isPresent() && is.getItem() == maybeSkyChestItem.get() )
|
2014-03-09 04:35:53 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( is.getItemDamage() )
|
2014-03-09 04:35:53 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case 1:
|
|
|
|
realName += ".Block";
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-09 04:35:53 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( is.getItem() instanceof ItemMultiMaterial )
|
2014-07-12 21:27:20 +02:00
|
|
|
{
|
|
|
|
realName = realName.replace( "ItemMultiMaterial", "ItemMaterial" );
|
2015-04-03 08:54:31 +02:00
|
|
|
realName += '.' + ( (ItemMultiMaterial) is.getItem() ).getTypeByStack( is ).name();
|
2014-07-12 21:27:20 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( is.getItem() instanceof ItemMultiPart )
|
2014-07-12 21:27:20 +02:00
|
|
|
{
|
|
|
|
realName = realName.replace( "ItemMultiPart", "ItemPart" );
|
2015-04-03 08:54:31 +02:00
|
|
|
realName += '.' + ( (ItemMultiPart) is.getItem() ).getTypeByStack( is ).name();
|
2014-07-12 21:27:20 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( is.getItemDamage() > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-03-09 04:35:53 +01:00
|
|
|
realName += "." + is.getItemDamage();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-03-06 06:52:25 +01:00
|
|
|
|
2014-03-05 20:34:56 +01:00
|
|
|
return realName;
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public String alias( String in )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
String out = this.data.aliases.get( in );
|
2014-02-10 04:16:36 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( out != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-10 04:16:36 +01:00
|
|
|
return out;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void parseRecipes( IRecipeLoader loader, String path )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2014-02-11 00:15:43 +01:00
|
|
|
try
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
BufferedReader reader = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
reader = loader.getFile( path );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Exception err )
|
2014-02-11 06:51:25 +01:00
|
|
|
{
|
|
|
|
AELog.warning( "Error Loading Recipe File:" + path );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.data.exceptions )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-26 05:34:05 +01:00
|
|
|
AELog.error( err );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-11 00:15:43 +01:00
|
|
|
boolean inQuote = false;
|
2014-02-11 06:51:25 +01:00
|
|
|
boolean inComment = false;
|
|
|
|
|
2014-02-11 00:15:43 +01:00
|
|
|
String token = "";
|
|
|
|
int line = 0;
|
2014-02-11 06:51:25 +01:00
|
|
|
|
|
|
|
int val = -1;
|
2015-04-03 08:54:31 +02:00
|
|
|
while( ( val = reader.read() ) != -1 )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
char c = (char) val;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( c == '\n' )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-11 00:15:43 +01:00
|
|
|
line++;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( inComment )
|
2014-02-11 06:51:25 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( c == '\n' || c == '\r' )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
inComment = false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( inQuote )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( c )
|
2014-02-11 00:15:43 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case '"':
|
|
|
|
inQuote = !inQuote;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
token += c;
|
2014-02-11 00:15:43 +01:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
2014-02-11 00:15:43 +01:00
|
|
|
else
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( c )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case '"':
|
|
|
|
inQuote = !inQuote;
|
|
|
|
break;
|
|
|
|
case ',':
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( token.length() > 0 )
|
|
|
|
{
|
|
|
|
this.tokens.add( token );
|
|
|
|
this.tokens.add( "," );
|
|
|
|
}
|
|
|
|
token = "";
|
|
|
|
break;
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case '=':
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
this.processTokens( loader, path, line );
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( token.length() > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.tokens.add( token );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
token = "";
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case '#':
|
|
|
|
inComment = true;
|
|
|
|
// then add a token if you can...
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case '\n':
|
|
|
|
case '\t':
|
|
|
|
case '\r':
|
|
|
|
case ' ':
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( token.length() > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.tokens.add( token );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
token = "";
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
token += c;
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-07 03:53:01 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( token.length() > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tokens.add( token );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-07 03:53:01 +02:00
|
|
|
|
2014-02-11 06:51:25 +01:00
|
|
|
reader.close();
|
2014-12-29 15:13:47 +01:00
|
|
|
this.processTokens( loader, path, line );
|
2014-02-11 00:15:43 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable e )
|
2014-02-11 00:15:43 +01:00
|
|
|
{
|
|
|
|
AELog.error( e );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.data.crash )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( e );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public void injectRecipes()
|
|
|
|
{
|
|
|
|
if( cpw.mods.fml.common.Loader.instance().hasReachedState( LoaderState.POSTINITIALIZATION ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Recipes must now be loaded in Init." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-05-17 23:51:57 +02:00
|
|
|
Map<Class, Integer> processed = new HashMap<Class, Integer>();
|
2015-04-03 08:54:31 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
for( ICraftHandler ch : this.data.Handlers )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ch.register();
|
|
|
|
|
|
|
|
Class clz = ch.getClass();
|
|
|
|
Integer i = processed.get( clz );
|
|
|
|
if( i == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
processed.put( clz, 1 );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
processed.put( clz, i + 1 );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
catch( RegistrationError e )
|
|
|
|
{
|
|
|
|
AELog.warning( "Unable to register a recipe: " + e.getMessage() );
|
|
|
|
if( this.data.exceptions )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
AELog.error( e );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.data.crash )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
throw e;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
catch( MissingIngredientError e )
|
|
|
|
{
|
|
|
|
if( this.data.errorOnMissing )
|
|
|
|
{
|
|
|
|
AELog.warning( "Unable to register a recipe:" + e.getMessage() );
|
|
|
|
if( this.data.exceptions )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
AELog.error( e );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.data.crash )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
throw e;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( Throwable e )
|
|
|
|
{
|
|
|
|
if( this.data.exceptions )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
AELog.error( e );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.data.crash )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( e );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for( Entry<Class, Integer> e : processed.entrySet() )
|
|
|
|
{
|
|
|
|
AELog.info( "Recipes Loading: " + e.getKey().getSimpleName() + ": " + e.getValue() + " loaded." );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( AEConfig.instance.isFeatureEnabled( AEFeature.WebsiteRecipes ) )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ZipOutputStream out = new ZipOutputStream( new FileOutputStream( "recipes.zip" ) );
|
|
|
|
|
|
|
|
HashMultimap<String, IWebsiteSerializer> combined = HashMultimap.create();
|
|
|
|
|
|
|
|
for( String s : this.data.knownItem )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
|
|
|
Ingredient i = new Ingredient( this, s, 1 );
|
|
|
|
|
|
|
|
for( ItemStack is : i.getItemStackSet() )
|
|
|
|
{
|
|
|
|
String realName = this.getName( is );
|
|
|
|
List<IWebsiteSerializer> recipes = this.findRecipe( is );
|
|
|
|
if( !recipes.isEmpty() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
combined.putAll( realName, recipes );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( RecipeError ignored )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
catch( MissedIngredientSet ignored )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
catch( RegistrationError ignored )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
catch( MissingIngredientError ignored )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( String realName : combined.keySet() )
|
|
|
|
{
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
for( IWebsiteSerializer ws : combined.get( realName ) )
|
|
|
|
{
|
|
|
|
String rew = ws.getPattern( this );
|
|
|
|
if( rew != null && rew.length() > 0 )
|
|
|
|
{
|
|
|
|
out.putNextEntry( new ZipEntry( realName + '_' + offset + ".txt" ) );
|
|
|
|
offset++;
|
|
|
|
out.write( rew.getBytes() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out.close();
|
|
|
|
}
|
|
|
|
catch( FileNotFoundException e1 )
|
|
|
|
{
|
|
|
|
AELog.error( e1 );
|
|
|
|
}
|
|
|
|
catch( IOException e1 )
|
|
|
|
{
|
|
|
|
AELog.error( e1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<IWebsiteSerializer> findRecipe( ItemStack output )
|
|
|
|
{
|
|
|
|
List<IWebsiteSerializer> out = new LinkedList<IWebsiteSerializer>();
|
|
|
|
|
|
|
|
for( ICraftHandler ch : this.data.Handlers )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( ch instanceof IWebsiteSerializer && ( (IWebsiteSerializer) ch ).canCraft( output ) )
|
|
|
|
{
|
|
|
|
out.add( (IWebsiteSerializer) ch );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( Throwable t )
|
|
|
|
{
|
|
|
|
AELog.error( t );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processTokens( IRecipeLoader loader, String file, int line ) throws RecipeError
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-02-20 00:33:36 +01:00
|
|
|
IRecipeHandlerRegistry cr = AEApi.instance().registries().recipes();
|
2014-02-20 06:18:49 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tokens.isEmpty() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-10 04:16:36 +01:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
int split = this.tokens.indexOf( "->" );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( split != -1 )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
String operation = this.tokens.remove( 0 ).toLowerCase();
|
2014-02-10 04:16:36 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( operation.equals( "alias" ) )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tokens.size() == 3 && this.tokens.indexOf( "->" ) == 1 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.data.aliases.put( this.tokens.get( 0 ), this.tokens.get( 2 ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-10 04:16:36 +01:00
|
|
|
throw new RecipeError( "Alias must have exactly 1 input and 1 output." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( operation.equals( "group" ) )
|
2014-02-11 00:15:43 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
List<String> pre = this.tokens.subList( 0, split - 1 );
|
|
|
|
List<String> post = this.tokens.subList( split, this.tokens.size() );
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
List<List<IIngredient>> inputs = this.parseLines( pre );
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( inputs.size() == 1 && inputs.get( 0 ).size() > 0 && post.size() == 1 )
|
2014-02-11 00:15:43 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.data.groups.put( post.get( 0 ), new GroupIngredient( post.get( 0 ), inputs.get( 0 ) ) );
|
2014-02-11 00:15:43 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
throw new RecipeError( "Group must have exactly 1 output, and 1 or more inputs." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 00:15:43 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( operation.equals( "ore" ) )
|
2014-02-11 00:15:43 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
List<String> pre = this.tokens.subList( 0, split - 1 );
|
|
|
|
List<String> post = this.tokens.subList( split, this.tokens.size() );
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
List<List<IIngredient>> inputs = this.parseLines( pre );
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( inputs.size() == 1 && inputs.get( 0 ).size() > 0 && post.size() == 1 )
|
2014-02-11 00:15:43 +01:00
|
|
|
{
|
2014-02-20 00:33:36 +01:00
|
|
|
ICraftHandler ch = new OreRegistration( inputs.get( 0 ), post.get( 0 ) );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.addCrafting( ch );
|
2014-02-11 00:15:43 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
throw new RecipeError( "Group must have exactly 1 output, and 1 or more inputs in a single row." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 00:15:43 +01:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
else
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
List<String> pre = this.tokens.subList( 0, split - 1 );
|
|
|
|
List<String> post = this.tokens.subList( split, this.tokens.size() );
|
2014-02-10 04:16:36 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
List<List<IIngredient>> inputs = this.parseLines( pre );
|
|
|
|
List<List<IIngredient>> outputs = this.parseLines( post );
|
2014-02-10 04:16:36 +01:00
|
|
|
|
2014-02-20 06:18:49 +01:00
|
|
|
ICraftHandler ch = cr.getCraftHandlerFor( operation );
|
2014-02-10 04:16:36 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ch != null )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
|
|
|
ch.setup( inputs, outputs );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.addCrafting( ch );
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-10 04:16:36 +01:00
|
|
|
throw new RecipeError( "Invalid crafting type: " + operation );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2014-02-11 06:51:25 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
String operation = this.tokens.remove( 0 ).toLowerCase();
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( operation.equals( "exceptions" ) && ( this.tokens.get( 0 ).equals( "true" ) || this.tokens.get( 0 ).equals( "false" ) ) )
|
2014-02-25 06:33:31 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tokens.size() == 1 )
|
2014-02-25 06:33:31 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.data.exceptions = this.tokens.get( 0 ).equals( "true" );
|
2014-02-25 06:33:31 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-25 06:33:31 +01:00
|
|
|
throw new RecipeError( "exceptions must be true or false explicitly." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-25 06:33:31 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( operation.equals( "crash" ) && ( this.tokens.get( 0 ).equals( "true" ) || this.tokens.get( 0 ).equals( "false" ) ) )
|
2014-02-11 06:51:25 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tokens.size() == 1 )
|
2014-02-11 06:51:25 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.data.crash = this.tokens.get( 0 ).equals( "true" );
|
2014-02-11 06:51:25 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
throw new RecipeError( "crash must be true or false explicitly." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( operation.equals( "erroronmissing" ) )
|
2014-02-11 06:51:25 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tokens.size() == 1 && ( this.tokens.get( 0 ).equals( "true" ) || this.tokens.get( 0 ).equals( "false" ) ) )
|
2014-02-11 06:51:25 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.data.errorOnMissing = this.tokens.get( 0 ).equals( "true" );
|
2014-02-11 06:51:25 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
throw new RecipeError( "erroronmissing must be true or false explicitly." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( operation.equals( "import" ) )
|
2014-02-11 06:51:25 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tokens.size() == 1 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
( new RecipeHandler( this ) ).parseRecipes( loader, this.tokens.get( 0 ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
throw new RecipeError( "Import must have exactly 1 input." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
throw new RecipeError( operation + ": " + this.tokens.toString() + "; recipe without an output." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( RecipeError e )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
AELog.warning( "Recipe Error '" + e.getMessage() + "' near line:" + line + " in " + file + " with: " + this.tokens.toString() );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.data.exceptions )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-25 06:33:31 +01:00
|
|
|
AELog.error( e );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.data.crash )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
throw e;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tokens.clear();
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private List<List<IIngredient>> parseLines( List<String> subList ) throws RecipeError
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2014-02-20 00:33:36 +01:00
|
|
|
List<List<IIngredient>> out = new LinkedList<List<IIngredient>>();
|
|
|
|
List<IIngredient> cList = new LinkedList<IIngredient>();
|
2014-02-10 04:16:36 +01:00
|
|
|
|
2014-02-11 06:51:25 +01:00
|
|
|
boolean hasQty = false;
|
|
|
|
int qty = 1;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( String v : subList )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( v.equals( "," ) )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hasQty )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
throw new RecipeError( "Qty found with no item." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !cList.isEmpty() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-10 04:16:36 +01:00
|
|
|
out.add( cList );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-20 00:33:36 +01:00
|
|
|
cList = new LinkedList<IIngredient>();
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isNumber( v ) )
|
2014-02-11 06:51:25 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hasQty )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
throw new RecipeError( "Qty found with no item." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
hasQty = true;
|
|
|
|
qty = Integer.parseInt( v );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hasQty )
|
2014-02-11 06:51:25 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
cList.add( this.findIngredient( v, qty ) );
|
2014-02-11 06:51:25 +01:00
|
|
|
hasQty = false;
|
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
cList.add( this.findIngredient( v, 1 ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !cList.isEmpty() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-10 04:16:36 +01:00
|
|
|
out.add( cList );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private IIngredient findIngredient( String v, int qty ) throws RecipeError
|
2014-02-25 06:33:31 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
GroupIngredient gi = this.data.groups.get( v );
|
2014-03-06 06:52:25 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( gi != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-25 06:33:31 +01:00
|
|
|
return gi.copy( qty );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-03-06 06:52:25 +01:00
|
|
|
|
2014-03-10 03:11:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return new Ingredient( this, v, qty );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( MissedIngredientSet grp )
|
2014-03-10 03:11:29 +01:00
|
|
|
{
|
|
|
|
return new IngredientSet( grp.rrs );
|
|
|
|
}
|
2014-02-25 06:33:31 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private boolean isNumber( String v )
|
2014-02-11 06:51:25 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( v.length() <= 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
|
|
|
|
int l = v.length();
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < l; x++ )
|
2014-02-11 06:51:25 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !Character.isDigit( v.charAt( x ) ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-02-11 06:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|