Relocate Source to proper directory.

This commit is contained in:
AlgorithmX2
2014-09-23 19:26:27 -05:00
parent fe927ce65d
commit 386d18a059
785 changed files with 35585 additions and 35580 deletions
@@ -0,0 +1,147 @@
package appeng.recipes;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.recipes.ISubItemResolver;
import appeng.api.recipes.ResolverResult;
import appeng.api.recipes.ResolverResultSet;
import appeng.api.util.AEColor;
import appeng.api.util.AEColoredItemDefinition;
import appeng.core.AppEng;
import appeng.items.materials.ItemMultiMaterial;
import appeng.items.materials.MaterialType;
import appeng.items.misc.ItemCrystalSeed;
import appeng.items.parts.ItemMultiPart;
import appeng.items.parts.PartType;
public class AEItemResolver implements ISubItemResolver
{
@Override
public Object resolveItemByName(String nameSpace, String itemName)
{
if ( nameSpace.equals( AppEng.modid ) )
{
if ( itemName.startsWith( "PaintBall." ) )
{
return paintBall( AEApi.instance().items().itemPaintBall, itemName.substring( itemName.indexOf( "." ) + 1 ), false );
}
if ( itemName.startsWith( "LumenPaintBall." ) )
{
return paintBall( AEApi.instance().items().itemPaintBall, itemName.substring( itemName.indexOf( "." ) + 1 ), true );
}
if ( itemName.equals( "CableGlass" ) )
{
return new ResolverResultSet( "CableGlass", AEApi.instance().parts().partCableGlass.allStacks( 1 ) );
}
if ( itemName.startsWith( "CableGlass." ) )
{
return cableItem( AEApi.instance().parts().partCableGlass, itemName.substring( itemName.indexOf( "." ) + 1 ) );
}
if ( itemName.equals( "CableCovered" ) )
{
return new ResolverResultSet( "CableCovered", AEApi.instance().parts().partCableCovered.allStacks( 1 ) );
}
if ( itemName.startsWith( "CableCovered." ) )
{
return cableItem( AEApi.instance().parts().partCableCovered, itemName.substring( itemName.indexOf( "." ) + 1 ) );
}
if ( itemName.equals( "CableSmart" ) )
{
return new ResolverResultSet( "CableSmart", AEApi.instance().parts().partCableSmart.allStacks( 1 ) );
}
if ( itemName.startsWith( "CableSmart." ) )
{
return cableItem( AEApi.instance().parts().partCableSmart, itemName.substring( itemName.indexOf( "." ) + 1 ) );
}
if ( itemName.equals( "CableDense" ) )
{
return new ResolverResultSet( "CableDense", AEApi.instance().parts().partCableDense.allStacks( 1 ) );
}
if ( itemName.startsWith( "CableDense." ) )
{
return cableItem( AEApi.instance().parts().partCableDense, itemName.substring( itemName.indexOf( "." ) + 1 ) );
}
if ( itemName.startsWith( "ItemCrystalSeed." ) )
{
if ( itemName.equalsIgnoreCase( "ItemCrystalSeed.Certus" ) )
return ItemCrystalSeed.getResolver( ItemCrystalSeed.Certus );
if ( itemName.equalsIgnoreCase( "ItemCrystalSeed.Nether" ) )
return new ResolverResult( "ItemCrystalSeed", ItemCrystalSeed.Nether );
if ( itemName.equalsIgnoreCase( "ItemCrystalSeed.Fluix" ) )
return new ResolverResult( "ItemCrystalSeed", ItemCrystalSeed.Fluix );
return null;
}
if ( itemName.startsWith( "ItemMaterial." ) )
{
String materialName = itemName.substring( itemName.indexOf( "." ) + 1 );
MaterialType mt = MaterialType.valueOf( materialName );
// itemName = itemName.substring( 0, itemName.indexOf( "." ) );
if ( mt.itemInstance == ItemMultiMaterial.instance && mt.damageValue >= 0 && mt.isRegistered() )
return new ResolverResult( "ItemMultiMaterial", mt.damageValue );
}
if ( itemName.startsWith( "ItemPart." ) )
{
String partName = itemName.substring( itemName.indexOf( "." ) + 1 );
PartType pt = PartType.valueOf( partName );
// itemName = itemName.substring( 0, itemName.indexOf( "." ) );
int dVal = ItemMultiPart.instance.getDamageByType( pt );
if ( dVal >= 0 )
return new ResolverResult( "ItemMultiPart", dVal );
}
}
return null;
}
private Object paintBall(AEColoredItemDefinition partType, String substring, boolean lumen)
{
AEColor col = AEColor.Transparent;
try
{
col = AEColor.valueOf( substring );
}
catch (Throwable t)
{
col = AEColor.Transparent;
}
if ( col == AEColor.Transparent )
return null;
ItemStack is = partType.stack( col, 1 );
return new ResolverResult( "ItemPaintBall", (lumen ? 20 : 0) + is.getItemDamage() );
}
private Object cableItem(AEColoredItemDefinition partType, String substring)
{
AEColor col = AEColor.Transparent;
try
{
col = AEColor.valueOf( substring );
}
catch (Throwable t)
{
col = AEColor.Transparent;
}
ItemStack is = partType.stack( col, 1 );
return new ResolverResult( "ItemMultiPart", is.getItemDamage() );
}
}
@@ -0,0 +1,121 @@
package appeng.recipes;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.IIngredient;
public class GroupIngredient implements IIngredient
{
int qty = 0;
final String name;
final List<IIngredient> ingredients;
ItemStack[] baked;
boolean isInside = false;
public GroupIngredient(String myName, List<IIngredient> ingredients) throws RecipeError {
name = myName;
for (IIngredient I : ingredients)
if ( I.isAir() )
throw new RecipeError( "Cannot include air in a group." );
this.ingredients = ingredients;
}
public IIngredient copy(int qty) throws RecipeError
{
GroupIngredient gi = new GroupIngredient( name, ingredients );
gi.qty = qty;
return gi;
}
public int getDamageValue()
{
return OreDictionary.WILDCARD_VALUE;
}
@Override
public String getItemName()
{
return name;
}
@Override
public ItemStack getItemStack() throws RegistrationError, MissingIngredientError
{
throw new RegistrationError( "Cannot pass group of items to a recipe which desires a single recipe item." );
}
@Override
public ItemStack[] getItemStackSet() throws RegistrationError, MissingIngredientError
{
if ( baked != null )
return baked;
if ( isInside )
return new ItemStack[0];
List<ItemStack> out = new LinkedList();
isInside = true;
try
{
for (IIngredient i : ingredients)
{
try
{
out.addAll( Arrays.asList( i.getItemStackSet() ) );
}
catch (MissingIngredientError mir)
{
// oh well this is a group!
}
}
}
finally
{
isInside = false;
}
if ( out.size() == 0 )
throw new MissingIngredientError( toString() + " - group could not be resolved to any items." );
for (ItemStack is : out)
is.stackSize = qty;
return out.toArray( new ItemStack[out.size()] );
}
public String getNameSpace()
{
return "";
}
@Override
public int getQty()
{
return 0;
}
@Override
public boolean isAir()
{
return false;
}
@Override
public void bake() throws RegistrationError, MissingIngredientError
{
baked = null;
baked = getItemStackSet();
}
}
@@ -0,0 +1,236 @@
package appeng.recipes;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.AEApi;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.IIngredient;
import appeng.api.recipes.ResolverResult;
import appeng.api.recipes.ResolverResultSet;
import cpw.mods.fml.common.registry.GameRegistry;
public class Ingredient implements IIngredient
{
final public boolean isAir;
final public String nameSpace;
final public String itemName;
final public int meta;
NBTTagCompound nbt = null;
final public int qty;
ItemStack[] baked;
public Ingredient(RecipeHandler handler, String input, int qty) throws RecipeError, MissedIngredientSet {
// works no matter wat!
this.qty = qty;
if ( input.equals( "_" ) )
{
isAir = true;
nameSpace = "";
itemName = "";
meta = OreDictionary.WILDCARD_VALUE;
return;
}
isAir = false;
String[] parts = input.split( ":" );
if ( parts.length >= 2 )
{
nameSpace = handler.alias( parts[0] );
String tmpName = handler.alias( parts[1] );
if ( parts.length != 3 )
{
int sel = 0;
if ( nameSpace.equals( "oreDictionary" ) )
{
if ( parts.length == 3 )
throw new RecipeError( "Cannot specify meta when using ore dictionary." );
sel = OreDictionary.WILDCARD_VALUE;
}
else
{
try
{
Object ro = AEApi.instance().registries().recipes().resolveItem( nameSpace, tmpName );
if ( ro instanceof ResolverResult )
{
ResolverResult rr = (ResolverResult) ro;
tmpName = rr.itemName;
sel = rr.damageValue;
nbt = rr.compound;
}
else if ( ro instanceof ResolverResultSet )
{
throw new MissedIngredientSet( (ResolverResultSet) ro );
}
}
catch (IllegalArgumentException e)
{
throw new RecipeError( tmpName + " is not a valid ae2 item definition." );
}
}
meta = sel;
}
else
{
if ( parts[2].equals( "*" ) )
{
meta = OreDictionary.WILDCARD_VALUE;
}
else
{
try
{
meta = Integer.parseInt( parts[2] );
}
catch (NumberFormatException e)
{
throw new RecipeError( "Invalid Metadata." );
}
}
}
itemName = tmpName;
}
else
throw new RecipeError( input + " : Needs at least Namespace and Name." );
handler.data.knownItem.add( toString() );
}
@Override
public ItemStack getItemStack() throws RegistrationError, MissingIngredientError
{
if ( isAir )
throw new RegistrationError( "Found blank item and expected a real item." );
if ( nameSpace.equalsIgnoreCase( "oreDictionary" ) )
throw new RegistrationError( "Recipe format expected a single item, but got a set of items." );
Block blk = GameRegistry.findBlock( nameSpace, itemName );
if ( blk == null )
blk = GameRegistry.findBlock( nameSpace, "tile." + itemName );
if ( blk != null )
{
Item it = Item.getItemFromBlock( blk );
if ( it != null )
return MakeItemStack( it, qty, meta, nbt );
}
Item it = GameRegistry.findItem( nameSpace, itemName );
if ( it == null )
it = GameRegistry.findItem( nameSpace, "item." + itemName );
if ( it != null )
return MakeItemStack( it, qty, meta, nbt );
/*
* Object o = Item.itemRegistry.getObject( nameSpace + ":" + itemName ); if ( o instanceof Item ) return new
* ItemStack( (Item) o, qty, meta );
*
* if ( o instanceof Block ) return new ItemStack( (Block) o, qty, meta );
*
* o = Item.itemRegistry.getObject( nameSpace + ":item." + itemName ); if ( o instanceof Item ) return new
* ItemStack( (Item) o, qty, meta );
*
* o = Block.blockRegistry.getObject( nameSpace + ":tile." + itemName ); if ( o instanceof Block && (!(o
* instanceof BlockAir)) ) return new ItemStack( (Block) o, qty, meta );
*/
throw new MissingIngredientError( "Unable to find item: " + toString() );
}
private ItemStack MakeItemStack(Item it, int quantity, int damageValue, NBTTagCompound compound)
{
ItemStack is = new ItemStack( it, quantity, damageValue );
is.setTagCompound( compound );
return is;
}
@Override
public String toString()
{
return nameSpace + ":" + itemName + ":" + meta;
}
@Override
public ItemStack[] getItemStackSet() throws RegistrationError, MissingIngredientError
{
if ( baked != null )
return baked;
if ( nameSpace.equalsIgnoreCase( "oreDictionary" ) )
{
List<ItemStack> ores = OreDictionary.getOres( itemName );
ItemStack[] set = ores.toArray( new ItemStack[ores.size()] );
// clone and set qty.
for (int x = 0; x < set.length; x++)
{
ItemStack is = set[x].copy();
is.stackSize = qty;
set[x] = is;
}
if ( set.length == 0 )
throw new MissingIngredientError( getItemName() + " - ore dictionary could not be resolved to any items." );
return set;
}
return new ItemStack[] { getItemStack() };
}
@Override
public String getNameSpace()
{
return nameSpace;
}
@Override
public String getItemName()
{
return itemName;
}
@Override
public int getDamageValue()
{
return meta;
}
@Override
public int getQty()
{
return qty;
}
@Override
public boolean isAir()
{
return isAir;
}
@Override
public void bake() throws RegistrationError, MissingIngredientError
{
baked = null;
baked = getItemStackSet();
}
}
@@ -0,0 +1,90 @@
package appeng.recipes;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.IIngredient;
import appeng.api.recipes.ResolverResultSet;
public class IngredientSet implements IIngredient
{
int qty = 0;
final String name;
final List<ItemStack> items;
ItemStack[] baked;
public IngredientSet(ResolverResultSet rr) {
name = rr.name;
items = rr.results;
}
boolean isInside = false;
public int getDamageValue()
{
return OreDictionary.WILDCARD_VALUE;
}
@Override
public String getItemName()
{
return name;
}
@Override
public ItemStack getItemStack() throws RegistrationError, MissingIngredientError
{
throw new RegistrationError( "Cannot pass group of items to a recipe which desires a single recipe item." );
}
@Override
public ItemStack[] getItemStackSet() throws RegistrationError, MissingIngredientError
{
if ( baked != null )
return baked;
if ( isInside )
return new ItemStack[0];
List<ItemStack> out = new LinkedList();
out.addAll( items );
if ( out.size() == 0 )
throw new MissingIngredientError( toString() + " - group could not be resolved to any items." );
for (ItemStack is : out)
is.stackSize = qty;
return out.toArray( new ItemStack[out.size()] );
}
public String getNameSpace()
{
return "";
}
@Override
public int getQty()
{
return 0;
}
@Override
public boolean isAir()
{
return false;
}
@Override
public void bake() throws RegistrationError, MissingIngredientError
{
baked = null;
baked = getItemStackSet();
}
}
@@ -0,0 +1,15 @@
package appeng.recipes;
import appeng.api.recipes.ResolverResultSet;
public class MissedIngredientSet extends Throwable
{
private static final long serialVersionUID = 2672951714376345807L;
final ResolverResultSet rrs;
public MissedIngredientSet(ResolverResultSet ro) {
rrs = ro;
}
}
@@ -0,0 +1,25 @@
package appeng.recipes;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import appeng.api.recipes.ICraftHandler;
public class RecipeData
{
final public HashMap<String, String> aliases = new HashMap<String, String>();
final public HashMap<String, GroupIngredient> groups = new HashMap<String, GroupIngredient>();
final public List<ICraftHandler> Handlers = new LinkedList<ICraftHandler>();
public boolean crash = true;
public boolean exceptions = true;
public boolean erroronmissing = true;
public Set<String> knownItem = new HashSet();
}
@@ -0,0 +1,642 @@
package appeng.recipes;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import appeng.recipes.handlers.IWebsiteSerializer;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
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;
import appeng.api.recipes.IRecipeHandler;
import appeng.api.recipes.IRecipeLoader;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.features.AEFeature;
import appeng.items.materials.ItemMultiMaterial;
import appeng.items.misc.ItemCrystalSeed;
import appeng.items.parts.ItemMultiPart;
import appeng.recipes.handlers.OreRegistration;
import com.google.common.collect.HashMultimap;
import cpw.mods.fml.common.LoaderState;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
public class RecipeHandler implements IRecipeHandler
{
final public List<String> tokens = new LinkedList<String>();
final RecipeData data;
public RecipeHandler() {
data = new RecipeData();
}
RecipeHandler(RecipeHandler parent) {
data = parent.data;
}
private void addCrafting(ICraftHandler ch)
{
data.Handlers.add( ch );
}
public List<IWebsiteSerializer> findRecipe(ItemStack output)
{
List<IWebsiteSerializer> out = new LinkedList<IWebsiteSerializer>();
for (ICraftHandler ch : data.Handlers)
{
try
{
if ( ch instanceof IWebsiteSerializer && ((IWebsiteSerializer) ch).canCraft( output ) )
{
out.add( (IWebsiteSerializer) ch );
}
}
catch (Throwable t)
{
AELog.error( t );
}
}
return out;
}
@Override
public void injectRecipes()
{
if ( cpw.mods.fml.common.Loader.instance().hasReachedState( LoaderState.POSTINITIALIZATION ) )
throw new RuntimeException( "Recipes must now be loaded in Init." );
HashMap<Class, Integer> processed = new HashMap<Class, Integer>();
try
{
for (ICraftHandler ch : data.Handlers)
{
try
{
ch.register();
Class clz = ch.getClass();
Integer i = processed.get( clz );
if ( i == null )
processed.put( clz, 1 );
else
processed.put( clz, i + 1 );
}
catch (RegistrationError e)
{
AELog.warning( "Unable to register a recipe: " + e.getMessage() );
if ( data.exceptions )
AELog.error( e );
if ( data.crash )
throw e;
}
catch (MissingIngredientError e)
{
if ( data.erroronmissing )
{
AELog.warning( "Unable to register a recipe:" + e.getMessage() );
if ( data.exceptions )
AELog.error( e );
if ( data.crash )
throw e;
}
}
}
}
catch (Throwable e)
{
if ( data.exceptions )
AELog.error( e );
if ( data.crash )
throw new RuntimeException( e );
}
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 : data.knownItem)
{
try
{
Ingredient i = new Ingredient( this, s, 1 );
for (ItemStack is : i.getItemStackSet())
{
String realName = getName( is );
List<IWebsiteSerializer> recipes = findRecipe( is );
if ( !recipes.isEmpty() )
combined.putAll( realName, recipes );
}
}
catch (RecipeError e1)
{
}
catch (MissedIngredientSet e1)
{
}
catch (RegistrationError e1)
{
}
catch (MissingIngredientError e1)
{
}
}
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 String getName(IIngredient i)
{
try
{
for (ItemStack is : i.getItemStackSet())
{
try
{
return getName( is );
}
catch (RecipeError notappicable)
{
}
}
}
catch (Throwable t)
{
t.printStackTrace();
// :P
}
return i.getNameSpace() + ":" + i.getItemName();
}
public String getName(ItemStack is) throws RecipeError
{
UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor( is.getItem() );
String realName = id.modId + ":" + id.name;
if ( !id.modId.equals( AppEng.modid ) && !id.modId.equals( "minecraft" ) )
throw new RecipeError( "Not applicable for website" );
if ( is.getItem() == AEApi.instance().items().itemCrystalSeed.item() )
{
int dmg = is.getItemDamage();
if ( dmg < ItemCrystalSeed.Nether )
realName += ".Certus";
else if ( dmg < ItemCrystalSeed.Fluix )
realName += ".Nether";
else if ( dmg < ItemCrystalSeed.END )
realName += ".Fluix";
}
else if ( is.getItem() == AEApi.instance().blocks().blockSkyStone.item() )
{
switch (is.getItemDamage())
{
case 1:
realName += ".Block";
break;
case 2:
realName += ".Brick";
break;
case 3:
realName += ".SmallBrick";
break;
default:
}
}
else if ( is.getItem() == AEApi.instance().blocks().blockCraftingStorage1k.item() )
{
switch (is.getItemDamage())
{
case 1:
realName += "4k";
break;
case 2:
realName += "16k";
break;
case 3:
realName += "64k";
break;
default:
}
}
else if ( is.getItem() == AEApi.instance().blocks().blockCraftingUnit.item() )
{
switch (is.getItemDamage())
{
case 1:
realName = realName.replace( "Unit", "Accelerator" );
break;
default:
}
}
else if ( is.getItem() == AEApi.instance().blocks().blockSkyChest.item() )
{
switch (is.getItemDamage())
{
case 1:
realName += ".Block";
break;
default:
}
}
else if ( is.getItem() instanceof ItemMultiMaterial )
{
realName = realName.replace( "ItemMultiMaterial", "ItemMaterial" );
realName += "." + ((ItemMultiMaterial) is.getItem()).getTypeByStack( is ).name();
}
else if ( is.getItem() instanceof ItemMultiPart )
{
realName = realName.replace( "ItemMultiPart", "ItemPart" );
realName += "." + ((ItemMultiPart) is.getItem()).getTypeByStack( is ).name();
}
else if ( is.getItemDamage() > 0 )
realName += "." + is.getItemDamage();
return realName;
}
public String alias(String in)
{
String out = data.aliases.get( in );
if ( out != null )
return out;
return in;
}
@Override
public void parseRecipes(IRecipeLoader loader, String path)
{
try
{
BufferedReader reader = null;
try
{
reader = loader.getFile( path );
}
catch (Exception err)
{
AELog.warning( "Error Loading Recipe File:" + path );
if ( data.exceptions )
AELog.error( err );
return;
}
boolean inQuote = false;
boolean inComment = false;
String token = "";
int line = 0;
int val = -1;
while ((val = reader.read()) != -1)
{
char c = (char) val;
if ( c == '\n' )
line++;
if ( inComment )
{
if ( c == '\n' || c == '\r' )
inComment = false;
}
else if ( inQuote )
{
switch (c)
{
case '"':
inQuote = !inQuote;
break;
default:
token = token + c;
}
}
else
{
switch (c)
{
case '"':
inQuote = !inQuote;
break;
case ',':
if ( token.length() > 0 )
{
tokens.add( token );
tokens.add( "," );
}
token = "";
break;
case '=':
processTokens( loader, path, line );
if ( token.length() > 0 )
tokens.add( token );
token = "";
break;
case '#':
inComment = true;
// then add a token if you can...
case '\n':
case '\t':
case '\r':
case ' ':
if ( token.length() > 0 )
tokens.add( token );
token = "";
break;
default:
token = token + c;
}
}
}
if ( token.length() > 0 )
tokens.add( token );
reader.close();
processTokens( loader, path, line );
}
catch (Throwable e)
{
AELog.error( e );
if ( data.crash )
throw new RuntimeException( e );
}
}
private void processTokens(IRecipeLoader loader, String file, int line) throws RecipeError
{
try
{
IRecipeHandlerRegistry cr = AEApi.instance().registries().recipes();
if ( tokens.isEmpty() )
return;
int split = tokens.indexOf( "->" );
if ( split != -1 )
{
String operation = tokens.remove( 0 ).toLowerCase();
if ( operation.equals( "alias" ) )
{
if ( tokens.size() == 3 && tokens.indexOf( "->" ) == 1 )
data.aliases.put( tokens.get( 0 ), tokens.get( 2 ) );
else
throw new RecipeError( "Alias must have exactly 1 input and 1 output." );
}
else if ( operation.equals( "group" ) )
{
List<String> pre = tokens.subList( 0, split - 1 );
List<String> post = tokens.subList( split, tokens.size() );
List<List<IIngredient>> inputs = parseLines( pre );
if ( inputs.size() == 1 && inputs.get( 0 ).size() > 0 && post.size() == 1 )
{
data.groups.put( post.get( 0 ), new GroupIngredient( post.get( 0 ), inputs.get( 0 ) ) );
}
else
throw new RecipeError( "Group must have exactly 1 output, and 1 or more inputs." );
}
else if ( operation.equals( "ore" ) )
{
List<String> pre = tokens.subList( 0, split - 1 );
List<String> post = tokens.subList( split, tokens.size() );
List<List<IIngredient>> inputs = parseLines( pre );
if ( inputs.size() == 1 && inputs.get( 0 ).size() > 0 && post.size() == 1 )
{
ICraftHandler ch = new OreRegistration( inputs.get( 0 ), post.get( 0 ) );
addCrafting( ch );
}
else
throw new RecipeError( "Group must have exactly 1 output, and 1 or more inputs in a single row." );
}
else
{
List<String> pre = tokens.subList( 0, split - 1 );
List<String> post = tokens.subList( split, tokens.size() );
List<List<IIngredient>> inputs = parseLines( pre );
List<List<IIngredient>> outputs = parseLines( post );
ICraftHandler ch = cr.getCraftHandlerFor( operation );
if ( ch != null )
{
ch.setup( inputs, outputs );
addCrafting( ch );
}
else
throw new RecipeError( "Invalid crafting type: " + operation );
}
}
else
{
String operation = tokens.remove( 0 ).toLowerCase();
if ( operation.equals( "exceptions" ) && (tokens.get( 0 ).equals( "true" ) || tokens.get( 0 ).equals( "false" )) )
{
if ( tokens.size() == 1 )
{
data.exceptions = tokens.get( 0 ).equals( "true" );
}
else
throw new RecipeError( "exceptions must be true or false explicitly." );
}
else if ( operation.equals( "crash" ) && (tokens.get( 0 ).equals( "true" ) || tokens.get( 0 ).equals( "false" )) )
{
if ( tokens.size() == 1 )
{
data.crash = tokens.get( 0 ).equals( "true" );
}
else
throw new RecipeError( "crash must be true or false explicitly." );
}
else if ( operation.equals( "erroronmissing" ) )
{
if ( tokens.size() == 1 && (tokens.get( 0 ).equals( "true" ) || tokens.get( 0 ).equals( "false" )) )
{
data.erroronmissing = tokens.get( 0 ).equals( "true" );
}
else
throw new RecipeError( "erroronmissing must be true or false explicitly." );
}
else if ( operation.equals( "import" ) )
{
if ( tokens.size() == 1 )
(new RecipeHandler( this )).parseRecipes( loader, tokens.get( 0 ) );
else
throw new RecipeError( "Import must have exactly 1 input." );
}
else
throw new RecipeError( operation + ": " + tokens.toString() + "; recipe without an output." );
}
}
catch (RecipeError e)
{
AELog.warning( "Recipe Error '" + e.getMessage() + "' near line:" + line + " in " + file + " with: " + tokens.toString() );
if ( data.exceptions )
AELog.error( e );
if ( data.crash )
throw e;
}
tokens.clear();
}
private List<List<IIngredient>> parseLines(List<String> subList) throws RecipeError
{
List<List<IIngredient>> out = new LinkedList<List<IIngredient>>();
List<IIngredient> cList = new LinkedList<IIngredient>();
boolean hasQty = false;
int qty = 1;
for (String v : subList)
{
if ( v.equals( "," ) )
{
if ( hasQty )
throw new RecipeError( "Qty found with no item." );
if ( !cList.isEmpty() )
out.add( cList );
cList = new LinkedList<IIngredient>();
}
else
{
if ( isNumber( v ) )
{
if ( hasQty )
throw new RecipeError( "Qty found with no item." );
hasQty = true;
qty = Integer.parseInt( v );
}
else
{
if ( hasQty )
{
cList.add( findIngredient( v, qty ) );
hasQty = false;
}
else
cList.add( findIngredient( v, 1 ) );
}
}
}
if ( !cList.isEmpty() )
out.add( cList );
return out;
}
private IIngredient findIngredient(String v, int qty) throws RecipeError
{
GroupIngredient gi = data.groups.get( v );
if ( gi != null )
return gi.copy( qty );
try
{
return new Ingredient( this, v, qty );
}
catch (MissedIngredientSet grp)
{
return new IngredientSet( grp.rrs );
}
}
private boolean isNumber(String v)
{
if ( v.length() <= 0 )
return false;
int l = v.length();
for (int x = 0; x < l; x++)
{
if ( !Character.isDigit( v.charAt( x ) ) )
return false;
}
return true;
}
}
@@ -0,0 +1,106 @@
package appeng.recipes.game;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.definitions.Blocks;
import appeng.api.definitions.Items;
import appeng.api.definitions.Materials;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
public class DisassembleRecipe implements IRecipe
{
private Materials mats = AEApi.instance().materials();
private Items items = AEApi.instance().items();
private Blocks blks = AEApi.instance().blocks();
private ItemStack getOutput(InventoryCrafting inv, boolean createFacade)
{
ItemStack hasCell = null;
for (int x = 0; x < inv.getSizeInventory(); x++)
{
ItemStack is = inv.getStackInSlot( x );
if ( is != null )
{
if ( hasCell != null )
return null;
if ( items.itemCell1k.sameAsStack( is ) )
hasCell = mats.materialCell1kPart.stack( 1 );
if ( items.itemCell4k.sameAsStack( is ) )
hasCell = mats.materialCell4kPart.stack( 1 );
if ( items.itemCell16k.sameAsStack( is ) )
hasCell = mats.materialCell16kPart.stack( 1 );
if ( items.itemCell64k.sameAsStack( is ) )
hasCell = mats.materialCell64kPart.stack( 1 );
// make sure the storage cell is empty...
if ( hasCell != null )
{
IMEInventory<IAEItemStack> cellInv = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
if ( cellInv != null )
{
IItemList<IAEItemStack> list = cellInv.getAvailableItems( StorageChannel.ITEMS.createList() );
if ( !list.isEmpty() )
return null;
}
}
if ( items.itemEncodedPattern.sameAsStack( is ) )
hasCell = mats.materialBlankPattern.stack( 1 );
if ( blks.blockCraftingStorage1k.sameAsStack( is ) )
hasCell = mats.materialCell1kPart.stack( 1 );
if ( blks.blockCraftingStorage4k.sameAsStack( is ) )
hasCell = mats.materialCell4kPart.stack( 1 );
if ( blks.blockCraftingStorage16k.sameAsStack( is ) )
hasCell = mats.materialCell16kPart.stack( 1 );
if ( blks.blockCraftingStorage64k.sameAsStack( is ) )
hasCell = mats.materialCell64kPart.stack( 1 );
if ( hasCell == null )
return null;
}
}
return hasCell;
}
@Override
public boolean matches(InventoryCrafting inv, World w)
{
return getOutput( inv, false ) != null;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inv)
{
return getOutput( inv, true );
}
@Override
public int getRecipeSize()
{
return 1;
}
@Override
public ItemStack getRecipeOutput() // no default output..
{
return null;
}
}
@@ -0,0 +1,57 @@
package appeng.recipes.game;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.util.AEItemDefinition;
import appeng.items.parts.ItemFacade;
public class FacadeRecipe implements IRecipe
{
private AEItemDefinition anchor = AEApi.instance().parts().partCableAnchor;
private ItemFacade facade = (ItemFacade) AEApi.instance().items().itemFacade.item();
private ItemStack getOutput(InventoryCrafting inv, boolean createFacade)
{
if ( inv.getStackInSlot( 0 ) == null && inv.getStackInSlot( 2 ) == null && inv.getStackInSlot( 6 ) == null && inv.getStackInSlot( 8 ) == null )
{
if ( anchor.sameAsStack( inv.getStackInSlot( 1 ) ) && anchor.sameAsStack( inv.getStackInSlot( 3 ) ) && anchor.sameAsStack( inv.getStackInSlot( 5 ) )
&& anchor.sameAsStack( inv.getStackInSlot( 7 ) ) )
{
ItemStack facades = facade.createFacadeForItem( inv.getStackInSlot( 4 ), !createFacade );
if ( facades != null && createFacade )
facades.stackSize = 4;
return facades;
}
}
return null;
}
@Override
public boolean matches(InventoryCrafting inv, World w)
{
return getOutput( inv, false ) != null;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inv)
{
return getOutput( inv, true );
}
@Override
public int getRecipeSize()
{
return 9;
}
@Override
public ItemStack getRecipeOutput() // no default output..
{
return null;
}
}
@@ -0,0 +1,12 @@
package appeng.recipes.game;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RegistrationError;
public interface IRecipeBakeable
{
void bake() throws RegistrationError, MissingIngredientError;
}
@@ -0,0 +1,298 @@
package appeng.recipes.game;
import java.util.ArrayList;
import java.util.HashMap;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.IIngredient;
public class ShapedRecipe implements IRecipe, IRecipeBakeable
{
// Added in for future ease of change, but hard coded for now.
private static final int MAX_CRAFT_GRID_WIDTH = 3;
private static final int MAX_CRAFT_GRID_HEIGHT = 3;
private ItemStack output = null;
private Object[] input = null;
private int width = 0;
private int height = 0;
private boolean mirrored = true;
private boolean disable = false;
public boolean isEnabled()
{
return !disable;
}
public ShapedRecipe(ItemStack result, Object... recipe) {
output = result.copy();
String shape = "";
int idx = 0;
if ( recipe[idx] instanceof Boolean )
{
mirrored = (Boolean) recipe[idx];
if ( recipe[idx + 1] instanceof Object[] )
{
recipe = (Object[]) recipe[idx + 1];
}
else
{
idx = 1;
}
}
if ( recipe[idx] instanceof String[] )
{
String[] parts = ((String[]) recipe[idx++]);
for (String s : parts)
{
width = s.length();
shape += s;
}
height = parts.length;
}
else
{
while (recipe[idx] instanceof String)
{
String s = (String) recipe[idx++];
shape += s;
width = s.length();
height++;
}
}
if ( width * height != shape.length() )
{
String ret = "Invalid shaped ore recipe: ";
for (Object tmp : recipe)
{
ret += tmp + ", ";
}
ret += output;
throw new RuntimeException( ret );
}
HashMap<Character, Object> itemMap = new HashMap<Character, Object>();
for (; idx < recipe.length; idx += 2)
{
Character chr = (Character) recipe[idx];
Object in = recipe[idx + 1];
if ( in instanceof IIngredient )
{
itemMap.put( chr, in );
}
else
{
String ret = "Invalid shaped ore recipe: ";
for (Object tmp : recipe)
{
ret += tmp + ", ";
}
ret += output;
throw new RuntimeException( ret );
}
}
input = new Object[width * height];
int x = 0;
for (char chr : shape.toCharArray())
{
input[x++] = itemMap.get( chr );
}
}
@Override
public ItemStack getCraftingResult(InventoryCrafting var1)
{
return output.copy();
}
@Override
public int getRecipeSize()
{
return input.length;
}
@Override
public ItemStack getRecipeOutput()
{
return output;
}
@Override
public boolean matches(InventoryCrafting inv, World world)
{
if ( disable )
return false;
for (int x = 0; x <= MAX_CRAFT_GRID_WIDTH - width; x++)
{
for (int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - height; ++y)
{
if ( checkMatch( inv, x, y, false ) )
{
return true;
}
if ( mirrored && checkMatch( inv, x, y, true ) )
{
return true;
}
}
}
return false;
}
@SuppressWarnings("unchecked")
private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror)
{
if ( disable )
return false;
for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++)
{
for (int y = 0; y < MAX_CRAFT_GRID_HEIGHT; y++)
{
int subX = x - startX;
int subY = y - startY;
Object target = null;
if ( subX >= 0 && subY >= 0 && subX < width && subY < height )
{
if ( mirror )
{
target = input[width - subX - 1 + subY * width];
}
else
{
target = input[subX + subY * width];
}
}
ItemStack slot = inv.getStackInRowAndColumn( x, y );
if ( target instanceof IIngredient )
{
boolean matched = false;
try
{
for (ItemStack item : ((IIngredient) target).getItemStackSet())
{
matched = matched || checkItemEquals( item, slot );
}
}
catch (RegistrationError e)
{
// :P
}
catch (MissingIngredientError e)
{
// :P
}
if ( !matched )
{
return false;
}
}
else if ( target instanceof ArrayList )
{
boolean matched = false;
for (ItemStack item : (ArrayList<ItemStack>) target)
{
matched = matched || checkItemEquals( item, slot );
}
if ( !matched )
{
return false;
}
}
else if ( target == null && slot != null )
{
return false;
}
}
}
return true;
}
private boolean checkItemEquals(ItemStack target, ItemStack input)
{
if ( input == null && target != null || input != null && target == null )
{
return false;
}
return (target.getItem() == input.getItem() && (target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input
.getItemDamage()));
}
public ShapedRecipe setMirrored(boolean mirror)
{
mirrored = mirror;
return this;
}
/**
* Returns the input for this recipe, any mod accessing this value should never manipulate the values in this array
* as it will effect the recipe itself.
*
* @return The recipes input vales.
*/
public Object[] getInput()
{
return this.input;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public Object[] getIngredients()
{
return input;
}
@Override
public void bake() throws RegistrationError
{
try
{
disable = false;
for (Object o : getInput())
{
if ( o instanceof IIngredient )
((IIngredient) o).bake();
}
}
catch (MissingIngredientError err)
{
disable = true;
}
}
}
@@ -0,0 +1,161 @@
package appeng.recipes.game;
import java.util.ArrayList;
import java.util.Iterator;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.IIngredient;
public class ShapelessRecipe implements IRecipe, IRecipeBakeable
{
private ItemStack output = null;
private ArrayList<Object> input = new ArrayList<Object>();
private boolean disable = false;
public boolean isEnabled()
{
return !disable;
}
public ShapelessRecipe(ItemStack result, Object... recipe) {
output = result.copy();
for (Object in : recipe)
{
if ( in instanceof IIngredient )
{
input.add( in );
}
else
{
String ret = "Invalid shapeless ore recipe: ";
for (Object tmp : recipe)
{
ret += tmp + ", ";
}
ret += output;
throw new RuntimeException( ret );
}
}
}
@Override
public int getRecipeSize()
{
return input.size();
}
@Override
public ItemStack getRecipeOutput()
{
return output;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting var1)
{
return output.copy();
}
@SuppressWarnings("unchecked")
@Override
public boolean matches(InventoryCrafting var1, World world)
{
if ( disable )
return false;
ArrayList<Object> required = new ArrayList<Object>( input );
for (int x = 0; x < var1.getSizeInventory(); x++)
{
ItemStack slot = var1.getStackInSlot( x );
if ( slot != null )
{
boolean inRecipe = false;
Iterator<Object> req = required.iterator();
while (req.hasNext())
{
boolean match = false;
Object next = req.next();
if ( next instanceof IIngredient )
{
try
{
for (ItemStack item : ((IIngredient) next).getItemStackSet())
{
match = match || checkItemEquals( item, slot );
}
}
catch (RegistrationError e)
{
// :P
}
catch (MissingIngredientError e)
{
// :P
}
}
if ( match )
{
inRecipe = true;
required.remove( next );
break;
}
}
if ( !inRecipe )
{
return false;
}
}
}
return required.isEmpty();
}
private boolean checkItemEquals(ItemStack target, ItemStack input)
{
return (target.getItem() == input.getItem() && (target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input
.getItemDamage()));
}
/**
* Returns the input for this recipe, any mod accessing this value should never manipulate the values in this array
* as it will effect the recipe itself.
*
* @return The recipes input vales.
*/
public ArrayList<Object> getInput()
{
return this.input;
}
@Override
public void bake() throws RegistrationError, MissingIngredientError
{
try
{
disable = false;
for (Object o : getInput())
{
if ( o instanceof IIngredient )
((IIngredient) o).bake();
}
}
catch (MissingIngredientError e)
{
disable = true;
}
}
}
@@ -0,0 +1,72 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IRC;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Crusher implements ICraftHandler, IWebsiteSerializer
{
IIngredient pro_input;
IIngredient pro_output[];
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
{
pro_input = input.get( 0 ).get( 0 );
pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
new RecipeError( "Crusher must have a single input, and single output." );
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.RC ) )
{
IRC rc = (IRC) AppEng.instance.getIntegration( IntegrationType.RC );
for (ItemStack is : pro_input.getItemStackSet())
{
try
{
rc.rockCrusher( is, pro_output[0].getItemStack() );
}
catch (java.lang.RuntimeException err)
{
AELog.info( "RC not happy - " + err.getMessage() );
}
}
}
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
{
return null;
}
}
@@ -0,0 +1,56 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Grind implements ICraftHandler, IWebsiteSerializer
{
IIngredient pro_input;
IIngredient pro_output[];
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
{
pro_input = input.get( 0 ).get( 0 );
pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
new RecipeError( "Grind must have a single input, and single output." );
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
for (ItemStack is : pro_input.getItemStackSet())
AEApi.instance().registries().grinder().addRecipe( is, pro_output[0].getItemStack(), 8 );
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError {
return Platform.isSameItemPrecise( pro_output[0].getItemStack(),output );
}
@Override
public String getPattern( RecipeHandler h ) {
return "grind\n"+
h.getName(pro_input)+"\n"+
h.getName(pro_output[0]);
}
}
@@ -0,0 +1,72 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IFZ;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class GrindFZ implements ICraftHandler, IWebsiteSerializer
{
IIngredient pro_input;
IIngredient pro_output[];
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
{
pro_input = input.get( 0 ).get( 0 );
pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
new RecipeError( "Grind must have a single input, and single output." );
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.FZ ) )
{
IFZ fz = (IFZ) AppEng.instance.getIntegration( IntegrationType.FZ );
for (ItemStack is : pro_input.getItemStackSet())
{
try
{
fz.grinderRecipe( is, pro_output[0].getItemStack() );
}
catch (java.lang.RuntimeException err)
{
AELog.info( "FZ not happy - " + err.getMessage() );
}
}
}
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
{
return null;
}
}
@@ -0,0 +1,82 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
import cpw.mods.fml.common.event.FMLInterModComms;
public class HCCrusher implements ICraftHandler, IWebsiteSerializer
{
IIngredient pro_input;
IIngredient pro_output[];
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
{
pro_input = input.get( 0 ).get( 0 );
pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
new RecipeError( "Crusher must have a single input, and single output." );
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
for (ItemStack is : pro_input.getItemStackSet())
{
try
{
NBTTagCompound toRegister = new NBTTagCompound();
ItemStack beginStack = is;
ItemStack endStack = pro_output[0].getItemStack();
NBTTagCompound itemFrom = new NBTTagCompound();
NBTTagCompound itemTo = new NBTTagCompound();
beginStack.writeToNBT(itemFrom);
endStack.writeToNBT(itemTo);
toRegister.setTag("itemFrom", itemFrom);
toRegister.setTag("itemTo", itemTo);
toRegister.setFloat("pressureRatio", 1.0F);
FMLInterModComms.sendMessage("HydCraft", "registerCrushingRecipe", toRegister);
}
catch (java.lang.RuntimeException err)
{
AELog.info( "Hydraulicraft not happy - " + err.getMessage() );
}
}
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
{
return null;
}
}
@@ -0,0 +1,15 @@
package appeng.recipes.handlers;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RegistrationError;
import appeng.recipes.RecipeHandler;
public interface IWebsiteSerializer
{
String getPattern(RecipeHandler han);
boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError;
}
@@ -0,0 +1,119 @@
package appeng.recipes.handlers;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Inscribe implements ICraftHandler, IWebsiteSerializer
{
public static class InscriberRecipe
{
public InscriberRecipe(ItemStack[] imprintable, ItemStack plateA, ItemStack plateB, ItemStack out, boolean usePlates) {
this.imprintable = imprintable;
this.usePlates = usePlates;
this.plateA = plateA;
this.plateB = plateB;
output = out;
}
final public boolean usePlates;
final public ItemStack plateA;
final public ItemStack[] imprintable;
final public ItemStack plateB;
final public ItemStack output;
};
public boolean usePlates = false;
public static HashSet<ItemStack> plates = new HashSet();
public static HashSet<ItemStack> inputs = new HashSet();
public static LinkedList<InscriberRecipe> recipes = new LinkedList();
IIngredient imprintable;
IIngredient plateA;
IIngredient plateB;
IIngredient output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( output.size() == 1 && output.get( 0 ).size() == 1 )
{
if ( input.size() == 1 && input.get( 0 ).size() > 1 )
{
imprintable = input.get( 0 ).get( 0 );
plateA = input.get( 0 ).get( 1 );
if ( input.get( 0 ).size() > 2 )
plateB = input.get( 0 ).get( 2 );
this.output = output.get( 0 ).get( 0 );
}
else
throw new RecipeError( "Inscriber recipes cannot have rows, and must have more then one input." );
}
else
throw new RecipeError( "Inscriber recipes must produce a single output." );
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( imprintable != null )
for (ItemStack s : imprintable.getItemStackSet())
inputs.add( s );
if ( plateA != null )
for (ItemStack s : plateA.getItemStackSet())
plates.add( s );
if ( plateB != null )
for (ItemStack s : plateB.getItemStackSet())
plates.add( s );
InscriberRecipe ir = new InscriberRecipe( imprintable.getItemStackSet(), plateA == null ? null : plateA.getItemStack(), plateB == null ? null
: plateB.getItemStack(), output.getItemStack(), usePlates );
recipes.add( ir );
}
@Override
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( output.getItemStack(), reqOutput );
}
@Override
public String getPattern(RecipeHandler h)
{
String o = "inscriber " + output.getQty() + "\n";
o += h.getName( output ) + "\n";
if ( plateA != null )
o += h.getName( plateA )+"\n";
o += h.getName(imprintable);
if ( plateB != null )
o += "\n"+h.getName( plateB );
return o;
}
}
@@ -0,0 +1,72 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IIC2;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Macerator implements ICraftHandler, IWebsiteSerializer
{
IIngredient pro_input;
IIngredient pro_output[];
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
{
pro_input = input.get( 0 ).get( 0 );
pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
new RecipeError( "Grind must have a single input, and single output." );
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) )
{
IIC2 ic2 = (IIC2) AppEng.instance.getIntegration( IntegrationType.IC2 );
for (ItemStack is : pro_input.getItemStackSet())
{
try
{
ic2.maceratorRecipe( is, pro_output[0].getItemStack() );
}
catch (java.lang.RuntimeException err)
{
AELog.info( "IC2 not happy - " + err.getMessage() );
}
}
}
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
{
return null;
}
}
@@ -0,0 +1,72 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IMekanism;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class MekCrusher implements ICraftHandler, IWebsiteSerializer
{
IIngredient pro_input;
IIngredient pro_output[];
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
{
pro_input = input.get( 0 ).get( 0 );
pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
new RecipeError( "MekCrusher must have a single input, and single output." );
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.Mekanism ) )
{
IMekanism rc = (IMekanism) AppEng.instance.getIntegration( IntegrationType.Mekanism );
for (ItemStack is : pro_input.getItemStackSet())
{
try
{
rc.addCrusherRecipe( is, pro_output[0].getItemStack() );
}
catch (java.lang.RuntimeException err)
{
AELog.info( "Mekanism not happy - " + err.getMessage() );
}
}
}
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
{
return null;
}
}
@@ -0,0 +1,72 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IMekanism;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class MekEnrichment implements ICraftHandler, IWebsiteSerializer
{
IIngredient pro_input;
IIngredient pro_output[];
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
{
pro_input = input.get( 0 ).get( 0 );
pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
new RecipeError( "MekCrusher must have a single input, and single output." );
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.Mekanism ) )
{
IMekanism rc = (IMekanism) AppEng.instance.getIntegration( IntegrationType.Mekanism );
for (ItemStack is : pro_input.getItemStackSet())
{
try
{
rc.addEnrichmentChamberRecipe( is, pro_output[0].getItemStack() );
}
catch (java.lang.RuntimeException err)
{
AELog.info( "Mekanism not happy - " + err.getMessage() );
}
}
}
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
{
return null;
}
}
@@ -0,0 +1,42 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
public class OreRegistration implements ICraftHandler
{
List<IIngredient> inputs;
String name;
public OreRegistration(List<IIngredient> in, String out) {
inputs = in;
name = out;
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
for (IIngredient i : inputs)
{
for (ItemStack is : i.getItemStackSet())
{
OreDictionary.registerOre( name, is );
}
}
}
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
}
}
@@ -0,0 +1,10 @@
package appeng.recipes.handlers;
public class Press extends Inscribe
{
public Press() {
usePlates = true;
}
}
@@ -0,0 +1,67 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
import cpw.mods.fml.common.event.FMLInterModComms;
public class Pulverizer implements ICraftHandler, IWebsiteSerializer
{
IIngredient pro_input;
IIngredient pro_output[];
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
{
pro_input = input.get( 0 ).get( 0 );
pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
new RecipeError( "Grind must have a single input, and single output." );
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
NBTTagCompound toSend = new NBTTagCompound();
toSend.setInteger( "energy", 800 );
toSend.setTag( "primaryOutput", new NBTTagCompound() );
pro_output[0].getItemStack().writeToNBT( toSend.getCompoundTag( "primaryOutput" ) );
for (ItemStack is : pro_input.getItemStackSet())
{
toSend.setTag( "input", new NBTTagCompound() );
is.writeToNBT( toSend.getCompoundTag( "input" ) );
FMLInterModComms.sendMessage( "ThermalExpansion", "PulverizerRecipe", toSend );
}
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
{
return null;
}
}
@@ -0,0 +1,134 @@
package appeng.recipes.handlers;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.recipes.RecipeHandler;
import appeng.recipes.game.ShapedRecipe;
import appeng.util.Platform;
import cpw.mods.fml.common.registry.GameRegistry;
public class Shaped implements ICraftHandler, IWebsiteSerializer
{
private int rows;
private int cols;
List<List<IIngredient>> inputs;
IIngredient output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( output.size() == 1 && output.get( 0 ).size() == 1 )
{
rows = input.size();
if ( rows > 0 && input.size() <= 3 )
{
cols = input.get( 0 ).size();
if ( cols <= 3 && cols >= 1 )
{
for (int x = 0; x < input.size(); x++)
if ( input.get( x ).size() != cols )
throw new RecipeError( "all rows in a shaped crafting recipe must contain the same number of ingredients." );
inputs = input;
this.output = output.get( 0 ).get( 0 );
}
else
throw new RecipeError( "Crafting recipes must have 1-3 columns." );
}
else
throw new RecipeError( "shaped crafting recipes must have 1-3 rows." );
}
else
throw new RecipeError( "Crafting must produce a single output." );
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
char first = 'A';
List<Object> args = new ArrayList<Object>();
for (int y = 0; y < rows; y++)
{
String row = "";
for (int x = 0; x < cols; x++)
{
if ( inputs.get( y ).get( x ).isAir() )
row = row + " ";
else
{
row = row + first;
args.add( first );
args.add( inputs.get( y ).get( x ) );
first++;
}
}
args.add( y, new String( row ) );
}
ItemStack outIS = output.getItemStack();
try
{
GameRegistry.addRecipe( new ShapedRecipe( outIS, args.toArray( new Object[args.size()] ) ) );
}
catch (Throwable e)
{
AELog.error( e );
throw new RegistrationError( "Error while adding shaped recipe." );
}
}
@Override
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError
{
for (int y = 0; y < rows; y++)
for (int x = 0; x < cols; x++)
{
IIngredient i = inputs.get( y ).get( x );
if ( !i.isAir() )
{
for ( ItemStack r : i.getItemStackSet() )
{
if ( Platform.isSameItemPrecise( r, reqOutput) )
return false;
}
}
}
return Platform.isSameItemPrecise( output.getItemStack(), reqOutput );
}
@Override
public String getPattern(RecipeHandler h)
{
String o = "shaped " + output.getQty() + " " + cols + "x" + rows + "\n";
o += h.getName( output ) + "\n";
for (int y = 0; y < rows; y++)
for (int x = 0; x < cols; x++)
{
IIngredient i = inputs.get( y ).get( x );
if ( i.isAir() )
o += "air" + (x + 1 == cols ? "\n" : " ");
else
o += h.getName( i ) + (x + 1 == cols ? "\n" : " ");
}
return o.trim();
}
}
@@ -0,0 +1,98 @@
package appeng.recipes.handlers;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.recipes.RecipeHandler;
import appeng.recipes.game.ShapelessRecipe;
import appeng.util.Platform;
import cpw.mods.fml.common.registry.GameRegistry;
public class Shapeless implements ICraftHandler, IWebsiteSerializer
{
List<IIngredient> inputs;
IIngredient output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( output.size() == 1 && output.get( 0 ).size() == 1 )
{
if ( input.size() == 1 )
{
inputs = input.get( 0 );
this.output = output.get( 0 ).get( 0 );
}
else
throw new RecipeError( "Shapeless crafting recipes cannot have rows." );
}
else
throw new RecipeError( "Crafting must produce a single output." );
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
List<Object> args = new ArrayList<Object>();
for (IIngredient i : inputs)
args.add( i );
ItemStack outIS = output.getItemStack();
try
{
GameRegistry.addRecipe( new ShapelessRecipe( outIS, args.toArray( new Object[args.size()] ) ) );
}
catch (Throwable e)
{
AELog.error( e );
throw new RegistrationError( "Error while adding shapeless recipe." );
}
}
@Override
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError {
for ( int y = 0; y < inputs.size(); y++ )
{
IIngredient i = inputs.get(y);
if ( !i.isAir() )
{
for ( ItemStack r : i.getItemStackSet() )
{
if ( Platform.isSameItemPrecise( r, reqOutput) )
return false;
}
}
}
return Platform.isSameItemPrecise( output.getItemStack(),reqOutput );
}
@Override
public String getPattern( RecipeHandler h) {
String o = "shapeless "+output.getQty()+"\n";
o += h.getName(output)+"\n";
for ( int y = 0; y < inputs.size(); y++ )
{
IIngredient i = inputs.get(y);
if ( i.isAir() )
o += "air"+( y +1 == inputs.size() ? "\n" : " " );
else
o += h.getName(i)+( y +1 == inputs.size() ? "\n" : " " );
}
return o.trim();
}
}
@@ -0,0 +1,61 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RecipeError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
import cpw.mods.fml.common.registry.GameRegistry;
public class Smelt implements ICraftHandler, IWebsiteSerializer
{
IIngredient in;
IIngredient out;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
{
List<IIngredient> inputList = input.get( 0 );
List<IIngredient> outputList = output.get( 0 );
if ( inputList.size() == 1 && outputList.size() == 1 )
{
in = inputList.get( 0 );
out = outputList.get( 0 );
return;
}
}
throw new RecipeError( "Smelting recipe can only have a single input and output." );
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( in.getItemStack().getItem() == null )
throw new RegistrationError( in.toString() + ": Smelting Input is not a valid item." );
if ( out.getItemStack().getItem() == null )
throw new RegistrationError( out.toString() + ": Smelting Output is not a valid item." );
GameRegistry.addSmelting( in.getItemStack(), out.getItemStack(), 0 );
}
@Override
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError {
return Platform.isSameItemPrecise( out.getItemStack(),reqOutput );
}
@Override
public String getPattern( RecipeHandler h ) {
return "smelt "+out.getQty()+"\n"+
h.getName(out)+"\n"+
h.getName(in);
}
}
@@ -0,0 +1,25 @@
package appeng.recipes.loader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import appeng.api.recipes.IRecipeLoader;
public class ConfigLoader implements IRecipeLoader
{
private String rootPath;
public ConfigLoader(String s) {
rootPath = s;
}
@Override
public BufferedReader getFile(String s) throws Exception
{
File f = new File( rootPath + s );
return new BufferedReader( new InputStreamReader( new FileInputStream( f ), "UTF-8" ) );
}
}
@@ -0,0 +1,23 @@
package appeng.recipes.loader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import appeng.api.recipes.IRecipeLoader;
public class JarLoader implements IRecipeLoader
{
private String rootPath;
public JarLoader(String s) {
rootPath = s;
}
@Override
public BufferedReader getFile(String s) throws Exception
{
return new BufferedReader( new InputStreamReader( getClass().getResourceAsStream( rootPath + s ), "UTF-8" ) );
}
}
@@ -0,0 +1,17 @@
package appeng.recipes.ores;
import net.minecraft.item.ItemStack;
public interface IOreListener
{
/**
* Called with various items registered in the dictionary.
* AppEng.oreDictionary.observe(...) to register them.
*
* @param Name
* @param item
*/
void oreRegistered(String Name, ItemStack item);
}
@@ -0,0 +1,93 @@
package appeng.recipes.ores;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraftforge.oredict.OreDictionary;
import appeng.core.AELog;
import appeng.recipes.game.IRecipeBakeable;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class OreDictionaryHandler
{
public static final OreDictionaryHandler instance = new OreDictionaryHandler();
private List<IOreListener> ol = new ArrayList<IOreListener>();
private boolean enableRebaking = false;
/**
* Just limit what items are sent to the final listeners, I got sick of strange items showing up...
*
* @param name
* @return
*/
private boolean shouldCare(String name)
{
return true;
}
@SubscribeEvent
public void onOreDictionaryRegister(OreDictionary.OreRegisterEvent event)
{
if ( event.Name == null || event.Ore == null )
return;
if ( shouldCare( event.Name ) )
{
for (IOreListener v : ol)
v.oreRegistered( event.Name, event.Ore );
}
if ( enableRebaking )
bakeRecipes();
}
/**
* Adds a new IOreListener and immediately notifies it of any previous ores, any ores added latter will be added at
* that point.
*
* @param n
*/
public void observe(IOreListener n)
{
ol.add( n );
// notify the listener of any ore already in existence.
for (String name : OreDictionary.getOreNames())
{
if ( name != null && shouldCare( name ) )
{
for (ItemStack item : OreDictionary.getOres( name ))
{
if ( item != null )
n.oreRegistered( name, item );
}
}
}
}
public void bakeRecipes()
{
enableRebaking = true;
for (Object o : CraftingManager.getInstance().getRecipeList())
{
if ( o instanceof IRecipeBakeable )
{
try
{
((IRecipeBakeable) o).bake();
}
catch (Throwable e)
{
AELog.error( e );
}
}
}
}
}