Basic reformat, hit once, hope never again

This commit is contained in:
thatsIch
2015-04-03 08:54:31 +02:00
parent 4ff1631f89
commit d34c988c88
886 changed files with 31400 additions and 30990 deletions
@@ -45,90 +45,90 @@ public class AEItemResolver implements ISubItemResolver
public Object resolveItemByName( String nameSpace, String itemName )
{
if ( nameSpace.equals( AppEng.MOD_ID ) )
if( nameSpace.equals( AppEng.MOD_ID ) )
{
final IDefinitions definitions = AEApi.instance().definitions();
final IItems items = definitions.items();
final IParts parts = definitions.parts();
if ( itemName.startsWith( "PaintBall." ) )
if( itemName.startsWith( "PaintBall." ) )
{
return this.paintBall( items.coloredPaintBall(), itemName.substring( itemName.indexOf( '.' ) + 1 ), false );
}
if ( itemName.startsWith( "LumenPaintBall." ) )
if( itemName.startsWith( "LumenPaintBall." ) )
{
return this.paintBall( items.coloredLumenPaintBall(), itemName.substring( itemName.indexOf( '.' ) + 1 ), true );
}
if ( itemName.equals( "CableGlass" ) )
if( itemName.equals( "CableGlass" ) )
{
return new ResolverResultSet( "CableGlass", parts.cableGlass().allStacks( 1 ) );
}
if ( itemName.startsWith( "CableGlass." ) )
if( itemName.startsWith( "CableGlass." ) )
{
return this.cableItem( parts.cableGlass(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
}
if ( itemName.equals( "CableCovered" ) )
if( itemName.equals( "CableCovered" ) )
{
return new ResolverResultSet( "CableCovered", parts.cableCovered().allStacks( 1 ) );
}
if ( itemName.startsWith( "CableCovered." ) )
if( itemName.startsWith( "CableCovered." ) )
{
return this.cableItem( parts.cableCovered(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
}
if ( itemName.equals( "CableSmart" ) )
if( itemName.equals( "CableSmart" ) )
{
return new ResolverResultSet( "CableSmart", parts.cableSmart().allStacks( 1 ) );
}
if ( itemName.startsWith( "CableSmart." ) )
if( itemName.startsWith( "CableSmart." ) )
{
return this.cableItem( parts.cableSmart(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
}
if ( itemName.equals( "CableDense" ) )
if( itemName.equals( "CableDense" ) )
{
return new ResolverResultSet( "CableDense", parts.cableDense().allStacks( 1 ) );
}
if ( itemName.startsWith( "CableDense." ) )
if( itemName.startsWith( "CableDense." ) )
{
return this.cableItem( parts.cableDense(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
}
if ( itemName.startsWith( "ItemCrystalSeed." ) )
if( itemName.startsWith( "ItemCrystalSeed." ) )
{
if ( itemName.equalsIgnoreCase( "ItemCrystalSeed.Certus" ) )
if( itemName.equalsIgnoreCase( "ItemCrystalSeed.Certus" ) )
return ItemCrystalSeed.getResolver( ItemCrystalSeed.Certus );
if ( itemName.equalsIgnoreCase( "ItemCrystalSeed.Nether" ) )
if( itemName.equalsIgnoreCase( "ItemCrystalSeed.Nether" ) )
return new ResolverResult( "ItemCrystalSeed", ItemCrystalSeed.Nether );
if ( itemName.equalsIgnoreCase( "ItemCrystalSeed.Fluix" ) )
if( itemName.equalsIgnoreCase( "ItemCrystalSeed.Fluix" ) )
return new ResolverResult( "ItemCrystalSeed", ItemCrystalSeed.Fluix );
return null;
}
if ( itemName.startsWith( "ItemMaterial." ) )
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() )
if( mt.itemInstance == ItemMultiMaterial.instance && mt.damageValue >= 0 && mt.isRegistered() )
return new ResolverResult( "ItemMultiMaterial", mt.damageValue );
}
if ( itemName.startsWith( "ItemPart." ) )
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 )
if( dVal >= 0 )
return new ResolverResult( "ItemMultiPart", dVal );
}
}
@@ -144,12 +144,12 @@ public class AEItemResolver implements ISubItemResolver
{
col = AEColor.valueOf( substring );
}
catch ( Throwable t )
catch( Throwable t )
{
col = AEColor.Transparent;
}
if ( col == AEColor.Transparent )
if( col == AEColor.Transparent )
return null;
ItemStack is = partType.stack( col, 1 );
@@ -164,7 +164,7 @@ public class AEItemResolver implements ISubItemResolver
{
col = AEColor.valueOf( substring );
}
catch ( Throwable t )
catch( Throwable t )
{
col = AEColor.Transparent;
}
@@ -18,6 +18,7 @@
package appeng.recipes;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
@@ -30,45 +31,35 @@ 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;
int qty = 0;
ItemStack[] baked;
boolean isInside = false;
public GroupIngredient(String myName, List<IIngredient> ingredients) throws RecipeError {
public GroupIngredient( String myName, List<IIngredient> ingredients ) throws RecipeError
{
this.name = myName;
for (IIngredient I : ingredients)
if ( I.isAir() )
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
public IIngredient copy( int qty ) throws RecipeError
{
GroupIngredient gi = new GroupIngredient( this.name, this.ingredients );
gi.qty = qty;
return gi;
}
@Override
public int getDamageValue()
{
return OreDictionary.WILDCARD_VALUE;
}
@Override
public String getItemName()
{
return this.name;
}
@Override
public ItemStack getItemStack() throws RegistrationError, MissingIngredientError
{
@@ -78,23 +69,23 @@ public class GroupIngredient implements IIngredient
@Override
public ItemStack[] getItemStackSet() throws RegistrationError, MissingIngredientError
{
if ( this.baked != null )
if( this.baked != null )
return this.baked;
if ( this.isInside )
if( this.isInside )
return new ItemStack[0];
List<ItemStack> out = new LinkedList<ItemStack>();
this.isInside = true;
try
{
for (IIngredient i : this.ingredients)
for( IIngredient i : this.ingredients )
{
try
{
out.addAll( Arrays.asList( i.getItemStackSet() ) );
}
catch (MissingIngredientError mir)
catch( MissingIngredientError mir )
{
// oh well this is a group!
}
@@ -105,38 +96,49 @@ public class GroupIngredient implements IIngredient
this.isInside = false;
}
if ( out.size() == 0 )
if( out.size() == 0 )
throw new MissingIngredientError( this.toString() + " - group could not be resolved to any items." );
for (ItemStack is : out)
for( ItemStack is : out )
is.stackSize = this.qty;
return out.toArray( new ItemStack[out.size()] );
}
@Override
public String getNameSpace()
{
return "";
}
@Override
public int getQty()
{
return 0;
}
@Override
public boolean isAir()
{
return false;
}
@Override
public String getNameSpace()
{
return "";
}
@Override
public String getItemName()
{
return this.name;
}
@Override
public int getDamageValue()
{
return OreDictionary.WILDCARD_VALUE;
}
@Override
public int getQty()
{
return 0;
}
@Override
public void bake() throws RegistrationError, MissingIngredientError
{
this.baked = null;
this.baked = this.getItemStackSet();
}
}
+32 -33
View File
@@ -37,6 +37,7 @@ import appeng.api.recipes.IIngredient;
import appeng.api.recipes.ResolverResult;
import appeng.api.recipes.ResolverResultSet;
public class Ingredient implements IIngredient
{
@@ -45,18 +46,17 @@ public class Ingredient implements IIngredient
final public String nameSpace;
final public String itemName;
final public int meta;
NBTTagCompound nbt = null;
final public int qty;
NBTTagCompound nbt = null;
ItemStack[] baked;
public Ingredient(RecipeHandler handler, String input, int qty) throws RecipeError, MissedIngredientSet {
public Ingredient( RecipeHandler handler, String input, int qty ) throws RecipeError, MissedIngredientSet
{
// works no matter wat!
this.qty = qty;
if ( input.equals( "_" ) )
if( input.equals( "_" ) )
{
this.isAir = true;
this.nameSpace = "";
@@ -67,18 +67,18 @@ public class Ingredient implements IIngredient
this.isAir = false;
String[] parts = input.split( ":" );
if ( parts.length >= 2 )
if( parts.length >= 2 )
{
this.nameSpace = handler.alias( parts[0] );
String tmpName = handler.alias( parts[1] );
if ( parts.length != 3 )
if( parts.length != 3 )
{
int sel = 0;
if ( this.nameSpace.equals( "oreDictionary" ) )
if( this.nameSpace.equals( "oreDictionary" ) )
{
if ( parts.length == 3 )
if( parts.length == 3 )
throw new RecipeError( "Cannot specify meta when using ore dictionary." );
sel = OreDictionary.WILDCARD_VALUE;
}
@@ -87,19 +87,19 @@ public class Ingredient implements IIngredient
try
{
Object ro = AEApi.instance().registries().recipes().resolveItem( this.nameSpace, tmpName );
if ( ro instanceof ResolverResult )
if( ro instanceof ResolverResult )
{
ResolverResult rr = (ResolverResult) ro;
tmpName = rr.itemName;
sel = rr.damageValue;
this.nbt = rr.compound;
}
else if ( ro instanceof ResolverResultSet )
else if( ro instanceof ResolverResultSet )
{
throw new MissedIngredientSet( (ResolverResultSet) ro );
}
}
catch (IllegalArgumentException e)
catch( IllegalArgumentException e )
{
throw new RecipeError( tmpName + " is not a valid ae2 item definition." );
}
@@ -109,7 +109,7 @@ public class Ingredient implements IIngredient
}
else
{
if ( parts[2].equals( "*" ) )
if( parts[2].equals( "*" ) )
{
this.meta = OreDictionary.WILDCARD_VALUE;
}
@@ -119,7 +119,7 @@ public class Ingredient implements IIngredient
{
this.meta = Integer.parseInt( parts[2] );
}
catch (NumberFormatException e)
catch( NumberFormatException e )
{
throw new RecipeError( "Invalid Metadata." );
}
@@ -133,31 +133,37 @@ public class Ingredient implements IIngredient
handler.data.knownItem.add( this.toString() );
}
@Override
public String toString()
{
return this.nameSpace + ':' + this.itemName + ':' + this.meta;
}
@Override
public ItemStack getItemStack() throws RegistrationError, MissingIngredientError
{
if ( this.isAir )
if( this.isAir )
throw new RegistrationError( "Found blank item and expected a real item." );
if ( this.nameSpace.equalsIgnoreCase( "oreDictionary" ) )
if( this.nameSpace.equalsIgnoreCase( "oreDictionary" ) )
throw new RegistrationError( "Recipe format expected a single item, but got a set of items." );
Block blk = GameRegistry.findBlock( this.nameSpace, this.itemName );
if ( blk == null )
if( blk == null )
blk = GameRegistry.findBlock( this.nameSpace, "tile." + this.itemName );
if ( blk != null )
if( blk != null )
{
Item it = Item.getItemFromBlock( blk );
if ( it != null )
if( it != null )
return this.MakeItemStack( it, this.qty, this.meta, this.nbt );
}
Item it = GameRegistry.findItem( this.nameSpace, this.itemName );
if ( it == null )
if( it == null )
it = GameRegistry.findItem( this.nameSpace, "item." + this.itemName );
if ( it != null )
if( it != null )
return this.MakeItemStack( it, this.qty, this.meta, this.nbt );
/*
@@ -176,39 +182,33 @@ public class Ingredient implements IIngredient
throw new MissingIngredientError( "Unable to find item: " + this.toString() );
}
private ItemStack MakeItemStack(Item it, int quantity, int damageValue, NBTTagCompound compound)
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 this.nameSpace + ':' + this.itemName + ':' + this.meta;
}
@Override
public ItemStack[] getItemStackSet() throws RegistrationError, MissingIngredientError
{
if ( this.baked != null )
if( this.baked != null )
return this.baked;
if ( this.nameSpace.equalsIgnoreCase( "oreDictionary" ) )
if( this.nameSpace.equalsIgnoreCase( "oreDictionary" ) )
{
List<ItemStack> ores = OreDictionary.getOres( this.itemName );
ItemStack[] set = ores.toArray( new ItemStack[ores.size()] );
// clone and set qty.
for (int x = 0; x < set.length; x++)
for( int x = 0; x < set.length; x++ )
{
ItemStack is = set[x].copy();
is.stackSize = this.qty;
set[x] = is;
}
if ( set.length == 0 )
if( set.length == 0 )
throw new MissingIngredientError( this.itemName + " - ore dictionary could not be resolved to any items." );
return set;
@@ -253,5 +253,4 @@ public class Ingredient implements IIngredient
this.baked = null;
this.baked = this.getItemStackSet();
}
}
+33 -32
View File
@@ -18,6 +18,7 @@
package appeng.recipes;
import java.util.LinkedList;
import java.util.List;
@@ -29,33 +30,22 @@ import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.IIngredient;
import appeng.api.recipes.ResolverResultSet;
public class IngredientSet implements IIngredient
{
final int qty = 0;
final String name;
final List<ItemStack> items;
final boolean isInside = false;
ItemStack[] baked;
public IngredientSet(ResolverResultSet rr) {
public IngredientSet( ResolverResultSet rr )
{
this.name = rr.name;
this.items = rr.results;
}
final boolean isInside = false;
@Override
public int getDamageValue()
{
return OreDictionary.WILDCARD_VALUE;
}
@Override
public String getItemName()
{
return this.name;
}
@Override
public ItemStack getItemStack() throws RegistrationError, MissingIngredientError
{
@@ -65,47 +55,58 @@ public class IngredientSet implements IIngredient
@Override
public ItemStack[] getItemStackSet() throws RegistrationError, MissingIngredientError
{
if ( this.baked != null )
if( this.baked != null )
return this.baked;
if ( this.isInside )
if( this.isInside )
return new ItemStack[0];
List<ItemStack> out = new LinkedList<ItemStack>();
out.addAll( this.items );
if ( out.size() == 0 )
if( out.size() == 0 )
throw new MissingIngredientError( this.toString() + " - group could not be resolved to any items." );
for (ItemStack is : out)
for( ItemStack is : out )
is.stackSize = this.qty;
return out.toArray( new ItemStack[out.size()] );
}
@Override
public String getNameSpace()
{
return "";
}
@Override
public int getQty()
{
return 0;
}
@Override
public boolean isAir()
{
return false;
}
@Override
public String getNameSpace()
{
return "";
}
@Override
public String getItemName()
{
return this.name;
}
@Override
public int getDamageValue()
{
return OreDictionary.WILDCARD_VALUE;
}
@Override
public int getQty()
{
return 0;
}
@Override
public void bake() throws RegistrationError, MissingIngredientError
{
this.baked = null;
this.baked = this.getItemStackSet();
}
}
@@ -18,16 +18,18 @@
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) {
public MissedIngredientSet( ResolverResultSet ro )
{
this.rrs = ro;
}
}
+3 -4
View File
@@ -18,6 +18,7 @@
package appeng.recipes;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
@@ -26,6 +27,7 @@ import java.util.Set;
import appeng.api.recipes.ICraftHandler;
public class RecipeData
{
@@ -33,11 +35,8 @@ public class RecipeData
final public HashMap<String, GroupIngredient> groups = new HashMap<String, GroupIngredient>();
final public List<ICraftHandler> Handlers = new LinkedList<ICraftHandler>();
public final Set<String> knownItem = new HashSet<String>();
public boolean crash = true;
public boolean exceptions = true;
public boolean errorOnMissing = true;
public final Set<String> knownItem = new HashSet<String>();
}
+293 -296
View File
@@ -62,191 +62,44 @@ import appeng.items.parts.ItemMultiPart;
import appeng.recipes.handlers.IWebsiteSerializer;
import appeng.recipes.handlers.OreRegistration;
public class RecipeHandler implements IRecipeHandler
{
final public List<String> tokens = new LinkedList<String>();
final RecipeData data;
public RecipeHandler() {
public RecipeHandler()
{
this.data = new RecipeData();
}
RecipeHandler(RecipeHandler parent) {
RecipeHandler( RecipeHandler parent )
{
this.data = parent.data;
}
private void addCrafting(ICraftHandler ch)
private void addCrafting( ICraftHandler ch )
{
this.data.Handlers.add( ch );
}
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;
}
@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 : this.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 ( this.data.exceptions )
AELog.error( e );
if ( this.data.crash )
throw e;
}
catch (MissingIngredientError e)
{
if ( this.data.errorOnMissing )
{
AELog.warning( "Unable to register a recipe:" + e.getMessage() );
if ( this.data.exceptions )
AELog.error( e );
if ( this.data.crash )
throw e;
}
}
}
}
catch (Throwable e)
{
if ( this.data.exceptions )
AELog.error( e );
if ( this.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 : 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() )
combined.putAll( realName, recipes );
}
}
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 String getName(IIngredient i)
public String getName( IIngredient i )
{
try
{
for (ItemStack is : i.getItemStackSet())
for( ItemStack is : i.getItemStackSet() )
{
try
{
return this.getName( is );
}
catch (RecipeError ignored)
catch( RecipeError ignored )
{
}
}
}
catch (Throwable t)
catch( Throwable t )
{
t.printStackTrace();
// :P
@@ -255,12 +108,12 @@ public class RecipeHandler implements IRecipeHandler
return i.getNameSpace() + ':' + i.getItemName();
}
public String getName(ItemStack is) throws RecipeError
public String getName( ItemStack is ) throws RecipeError
{
UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor( is.getItem() );
String realName = id.modId + ':' + id.name;
if ( !id.modId.equals( AppEng.MOD_ID ) && !id.modId.equals( "minecraft" ) )
if( !id.modId.equals( AppEng.MOD_ID ) && !id.modId.equals( "minecraft" ) )
throw new RecipeError( "Not applicable for website" );
final IDefinitions definitions = AEApi.instance().definitions();
@@ -273,97 +126,96 @@ public class RecipeHandler implements IRecipeHandler
final Optional<Item> maybeCraftingUnitItem = blocks.craftingUnit().maybeItem();
final Optional<Item> maybeSkyChestItem = blocks.skyChest().maybeItem();
if ( maybeCrystalSeedItem.isPresent() && is.getItem() == maybeCrystalSeedItem.get() )
if( maybeCrystalSeedItem.isPresent() && is.getItem() == maybeCrystalSeedItem.get() )
{
int dmg = is.getItemDamage();
if ( dmg < ItemCrystalSeed.Nether )
if( dmg < ItemCrystalSeed.Nether )
realName += ".Certus";
else if ( dmg < ItemCrystalSeed.Fluix )
else if( dmg < ItemCrystalSeed.Fluix )
realName += ".Nether";
else if ( dmg < ItemCrystalSeed.END )
else if( dmg < ItemCrystalSeed.END )
realName += ".Fluix";
}
else if ( maybeSkyStoneItem.isPresent() && is.getItem() == maybeSkyStoneItem.get() )
else if( maybeSkyStoneItem.isPresent() && is.getItem() == maybeSkyStoneItem.get() )
{
switch (is.getItemDamage())
switch( is.getItemDamage() )
{
case 1:
realName += ".Block";
break;
case 2:
realName += ".Brick";
break;
case 3:
realName += ".SmallBrick";
break;
default:
case 1:
realName += ".Block";
break;
case 2:
realName += ".Brick";
break;
case 3:
realName += ".SmallBrick";
break;
default:
}
}
else if ( maybeCraftingStorageItem.isPresent() && is.getItem() == maybeCraftingStorageItem.get() )
else if( maybeCraftingStorageItem.isPresent() && is.getItem() == maybeCraftingStorageItem.get() )
{
switch (is.getItemDamage())
switch( is.getItemDamage() )
{
case 1:
realName += "4k";
break;
case 2:
realName += "16k";
break;
case 3:
realName += "64k";
break;
default:
case 1:
realName += "4k";
break;
case 2:
realName += "16k";
break;
case 3:
realName += "64k";
break;
default:
}
}
else if ( maybeCraftingUnitItem.isPresent() && is.getItem() == maybeCraftingUnitItem.get() )
else if( maybeCraftingUnitItem.isPresent() && is.getItem() == maybeCraftingUnitItem.get() )
{
switch (is.getItemDamage())
switch( is.getItemDamage() )
{
case 1:
realName = realName.replace( "Unit", "Accelerator" );
break;
default:
case 1:
realName = realName.replace( "Unit", "Accelerator" );
break;
default:
}
}
else if ( maybeSkyChestItem.isPresent() && is.getItem() == maybeSkyChestItem.get() )
else if( maybeSkyChestItem.isPresent() && is.getItem() == maybeSkyChestItem.get() )
{
switch (is.getItemDamage())
switch( is.getItemDamage() )
{
case 1:
realName += ".Block";
break;
default:
case 1:
realName += ".Block";
break;
default:
}
}
else if ( is.getItem() instanceof ItemMultiMaterial )
else if( is.getItem() instanceof ItemMultiMaterial )
{
realName = realName.replace( "ItemMultiMaterial", "ItemMaterial" );
realName += '.' + ((ItemMultiMaterial) is.getItem()).getTypeByStack( is ).name();
realName += '.' + ( (ItemMultiMaterial) is.getItem() ).getTypeByStack( is ).name();
}
else if ( is.getItem() instanceof ItemMultiPart )
else if( is.getItem() instanceof ItemMultiPart )
{
realName = realName.replace( "ItemMultiPart", "ItemPart" );
realName += '.' + ((ItemMultiPart) is.getItem()).getTypeByStack( is ).name();
realName += '.' + ( (ItemMultiPart) is.getItem() ).getTypeByStack( is ).name();
}
else if ( is.getItemDamage() > 0 )
else if( is.getItemDamage() > 0 )
realName += "." + is.getItemDamage();
return realName;
}
public String alias(String in)
public String alias( String in )
{
String out = this.data.aliases.get( in );
if ( out != null )
if( out != null )
return out;
return in;
}
@Override
public void parseRecipes(IRecipeLoader loader, String path)
public void parseRecipes( IRecipeLoader loader, String path )
{
try
{
@@ -372,10 +224,10 @@ public class RecipeHandler implements IRecipeHandler
{
reader = loader.getFile( path );
}
catch (Exception err)
catch( Exception err )
{
AELog.warning( "Error Loading Recipe File:" + path );
if ( this.data.exceptions )
if( this.data.exceptions )
AELog.error( err );
return;
}
@@ -387,134 +239,281 @@ public class RecipeHandler implements IRecipeHandler
int line = 0;
int val = -1;
while ((val = reader.read()) != -1)
while( ( val = reader.read() ) != -1 )
{
char c = (char) val;
if ( c == '\n' )
if( c == '\n' )
line++;
if ( inComment )
if( inComment )
{
if ( c == '\n' || c == '\r' )
if( c == '\n' || c == '\r' )
inComment = false;
}
else if ( inQuote )
else if( inQuote )
{
switch (c)
switch( c )
{
case '"':
inQuote = !inQuote;
break;
default:
token += c;
case '"':
inQuote = !inQuote;
break;
default:
token += c;
}
}
else
{
switch (c)
switch( c )
{
case '"':
inQuote = !inQuote;
break;
case ',':
case '"':
inQuote = !inQuote;
break;
case ',':
if ( token.length() > 0 )
{
this.tokens.add( token );
this.tokens.add( "," );
}
token = "";
break;
if( token.length() > 0 )
{
this.tokens.add( token );
this.tokens.add( "," );
}
token = "";
break;
case '=':
case '=':
this.processTokens( loader, path, line );
this.processTokens( loader, path, line );
if ( token.length() > 0 )
this.tokens.add( token );
token = "";
if( token.length() > 0 )
this.tokens.add( token );
token = "";
break;
break;
case '#':
inComment = true;
// then add a token if you can...
case '#':
inComment = true;
// then add a token if you can...
case '\n':
case '\t':
case '\r':
case ' ':
case '\n':
case '\t':
case '\r':
case ' ':
if ( token.length() > 0 )
this.tokens.add( token );
token = "";
if( token.length() > 0 )
this.tokens.add( token );
token = "";
break;
default:
token += c;
break;
default:
token += c;
}
}
}
if ( token.length() > 0 )
if( token.length() > 0 )
this.tokens.add( token );
reader.close();
this.processTokens( loader, path, line );
}
catch (Throwable e)
catch( Throwable e )
{
AELog.error( e );
if ( this.data.crash )
if( this.data.crash )
throw new RuntimeException( e );
}
}
private void processTokens(IRecipeLoader loader, String file, int line) throws RecipeError
@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 : this.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( this.data.exceptions )
AELog.error( e );
if( this.data.crash )
throw e;
}
catch( MissingIngredientError e )
{
if( this.data.errorOnMissing )
{
AELog.warning( "Unable to register a recipe:" + e.getMessage() );
if( this.data.exceptions )
AELog.error( e );
if( this.data.crash )
throw e;
}
}
}
}
catch( Throwable e )
{
if( this.data.exceptions )
AELog.error( e );
if( this.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 : 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() )
combined.putAll( realName, recipes );
}
}
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
{
try
{
IRecipeHandlerRegistry cr = AEApi.instance().registries().recipes();
if ( this.tokens.isEmpty() )
if( this.tokens.isEmpty() )
return;
int split = this.tokens.indexOf( "->" );
if ( split != -1 )
if( split != -1 )
{
String operation = this.tokens.remove( 0 ).toLowerCase();
if ( operation.equals( "alias" ) )
if( operation.equals( "alias" ) )
{
if ( this.tokens.size() == 3 && this.tokens.indexOf( "->" ) == 1 )
if( this.tokens.size() == 3 && this.tokens.indexOf( "->" ) == 1 )
this.data.aliases.put( this.tokens.get( 0 ), this.tokens.get( 2 ) );
else
throw new RecipeError( "Alias must have exactly 1 input and 1 output." );
}
else if ( operation.equals( "group" ) )
else if( operation.equals( "group" ) )
{
List<String> pre = this.tokens.subList( 0, split - 1 );
List<String> post = this.tokens.subList( split, this.tokens.size() );
List<List<IIngredient>> inputs = this.parseLines( pre );
if ( inputs.size() == 1 && inputs.get( 0 ).size() > 0 && post.size() == 1 )
if( inputs.size() == 1 && inputs.get( 0 ).size() > 0 && post.size() == 1 )
{
this.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" ) )
else if( operation.equals( "ore" ) )
{
List<String> pre = this.tokens.subList( 0, split - 1 );
List<String> post = this.tokens.subList( split, this.tokens.size() );
List<List<IIngredient>> inputs = this.parseLines( pre );
if ( inputs.size() == 1 && inputs.get( 0 ).size() > 0 && post.size() == 1 )
if( inputs.size() == 1 && inputs.get( 0 ).size() > 0 && post.size() == 1 )
{
ICraftHandler ch = new OreRegistration( inputs.get( 0 ), post.get( 0 ) );
this.addCrafting( ch );
@@ -532,7 +531,7 @@ public class RecipeHandler implements IRecipeHandler
ICraftHandler ch = cr.getCraftHandlerFor( operation );
if ( ch != null )
if( ch != null )
{
ch.setup( inputs, outputs );
this.addCrafting( ch );
@@ -545,58 +544,57 @@ public class RecipeHandler implements IRecipeHandler
{
String operation = this.tokens.remove( 0 ).toLowerCase();
if ( operation.equals( "exceptions" ) && (this.tokens.get( 0 ).equals( "true" ) || this.tokens.get( 0 ).equals( "false" )) )
if( operation.equals( "exceptions" ) && ( this.tokens.get( 0 ).equals( "true" ) || this.tokens.get( 0 ).equals( "false" ) ) )
{
if ( this.tokens.size() == 1 )
if( this.tokens.size() == 1 )
{
this.data.exceptions = this.tokens.get( 0 ).equals( "true" );
}
else
throw new RecipeError( "exceptions must be true or false explicitly." );
}
else if ( operation.equals( "crash" ) && (this.tokens.get( 0 ).equals( "true" ) || this.tokens.get( 0 ).equals( "false" )) )
else if( operation.equals( "crash" ) && ( this.tokens.get( 0 ).equals( "true" ) || this.tokens.get( 0 ).equals( "false" ) ) )
{
if ( this.tokens.size() == 1 )
if( this.tokens.size() == 1 )
{
this.data.crash = this.tokens.get( 0 ).equals( "true" );
}
else
throw new RecipeError( "crash must be true or false explicitly." );
}
else if ( operation.equals( "erroronmissing" ) )
else if( operation.equals( "erroronmissing" ) )
{
if ( this.tokens.size() == 1 && (this.tokens.get( 0 ).equals( "true" ) || this.tokens.get( 0 ).equals( "false" )) )
if( this.tokens.size() == 1 && ( this.tokens.get( 0 ).equals( "true" ) || this.tokens.get( 0 ).equals( "false" ) ) )
{
this.data.errorOnMissing = this.tokens.get( 0 ).equals( "true" );
}
else
throw new RecipeError( "erroronmissing must be true or false explicitly." );
}
else if ( operation.equals( "import" ) )
else if( operation.equals( "import" ) )
{
if ( this.tokens.size() == 1 )
(new RecipeHandler( this )).parseRecipes( loader, this.tokens.get( 0 ) );
if( this.tokens.size() == 1 )
( new RecipeHandler( this ) ).parseRecipes( loader, this.tokens.get( 0 ) );
else
throw new RecipeError( "Import must have exactly 1 input." );
}
else
throw new RecipeError( operation + ": " + this.tokens.toString() + "; recipe without an output." );
}
}
catch (RecipeError e)
catch( RecipeError e )
{
AELog.warning( "Recipe Error '" + e.getMessage() + "' near line:" + line + " in " + file + " with: " + this.tokens.toString() );
if ( this.data.exceptions )
if( this.data.exceptions )
AELog.error( e );
if ( this.data.crash )
if( this.data.crash )
throw e;
}
this.tokens.clear();
}
private List<List<IIngredient>> parseLines(List<String> subList) throws RecipeError
private List<List<IIngredient>> parseLines( List<String> subList ) throws RecipeError
{
List<List<IIngredient>> out = new LinkedList<List<IIngredient>>();
List<IIngredient> cList = new LinkedList<IIngredient>();
@@ -604,28 +602,28 @@ public class RecipeHandler implements IRecipeHandler
boolean hasQty = false;
int qty = 1;
for (String v : subList)
for( String v : subList )
{
if ( v.equals( "," ) )
if( v.equals( "," ) )
{
if ( hasQty )
if( hasQty )
throw new RecipeError( "Qty found with no item." );
if ( !cList.isEmpty() )
if( !cList.isEmpty() )
out.add( cList );
cList = new LinkedList<IIngredient>();
}
else
{
if ( this.isNumber( v ) )
if( this.isNumber( v ) )
{
if ( hasQty )
if( hasQty )
throw new RecipeError( "Qty found with no item." );
hasQty = true;
qty = Integer.parseInt( v );
}
else
{
if ( hasQty )
if( hasQty )
{
cList.add( this.findIngredient( v, qty ) );
hasQty = false;
@@ -636,42 +634,41 @@ public class RecipeHandler implements IRecipeHandler
}
}
if ( !cList.isEmpty() )
if( !cList.isEmpty() )
out.add( cList );
return out;
}
private IIngredient findIngredient(String v, int qty) throws RecipeError
private IIngredient findIngredient( String v, int qty ) throws RecipeError
{
GroupIngredient gi = this.data.groups.get( v );
if ( gi != null )
if( gi != null )
return gi.copy( qty );
try
{
return new Ingredient( this, v, qty );
}
catch (MissedIngredientSet grp)
catch( MissedIngredientSet grp )
{
return new IngredientSet( grp.rrs );
}
}
private boolean isNumber(String v)
private boolean isNumber( String v )
{
if ( v.length() <= 0 )
if( v.length() <= 0 )
return false;
int l = v.length();
for (int x = 0; x < l; x++)
for( int x = 0; x < l; x++ )
{
if ( !Character.isDigit( v.charAt( x ) ) )
if( !Character.isDigit( v.charAt( x ) ) )
return false;
}
return true;
}
}
@@ -80,31 +80,31 @@ public class DisassembleRecipe implements IRecipe
{
ItemStack hasCell = null;
for ( int x = 0; x < inv.getSizeInventory(); x++ )
for( int x = 0; x < inv.getSizeInventory(); x++ )
{
ItemStack is = inv.getStackInSlot( x );
if ( is != null )
if( is != null )
{
if ( hasCell != null )
if( hasCell != null )
return null;
hasCell = this.getCellOutput( is );
// make sure the storage cell is empty...
if ( hasCell != null )
if( hasCell != null )
{
IMEInventory<IAEItemStack> cellInv = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
if ( cellInv != null )
if( cellInv != null )
{
IItemList<IAEItemStack> list = cellInv.getAvailableItems( StorageChannel.ITEMS.createList() );
if ( !list.isEmpty() )
if( !list.isEmpty() )
return null;
}
}
hasCell = this.getNonCellOutput( is );
if ( hasCell == null )
if( hasCell == null )
return null;
}
}
@@ -114,9 +114,9 @@ public class DisassembleRecipe implements IRecipe
private ItemStack getCellOutput( ItemStack compared )
{
for ( Map.Entry<IItemDefinition, IItemDefinition> entry : this.cellMappings.entrySet() )
for( Map.Entry<IItemDefinition, IItemDefinition> entry : this.cellMappings.entrySet() )
{
if ( entry.getKey().isSameAs( compared ) )
if( entry.getKey().isSameAs( compared ) )
{
return entry.getValue().maybeStack( 1 ).get();
}
@@ -127,9 +127,9 @@ public class DisassembleRecipe implements IRecipe
private ItemStack getNonCellOutput( ItemStack compared )
{
for ( Map.Entry<IItemDefinition, IItemDefinition> entry : this.nonCellMappings.entrySet() )
for( Map.Entry<IItemDefinition, IItemDefinition> entry : this.nonCellMappings.entrySet() )
{
if ( entry.getKey().isSameAs( compared ) )
if( entry.getKey().isSameAs( compared ) )
{
return entry.getValue().maybeStack( 1 ).get();
}
@@ -59,16 +59,16 @@ public final class FacadeRecipe implements IRecipe
@Nullable
private ItemStack getOutput( IInventory inv, boolean createFacade )
{
if ( inv.getStackInSlot( 0 ) == null && inv.getStackInSlot( 2 ) == null && inv.getStackInSlot( 6 ) == null && inv.getStackInSlot( 8 ) == null )
if( inv.getStackInSlot( 0 ) == null && inv.getStackInSlot( 2 ) == null && inv.getStackInSlot( 6 ) == null && inv.getStackInSlot( 8 ) == null )
{
if ( this.anchor.isSameAs( inv.getStackInSlot( 1 ) ) && this.anchor.isSameAs( inv.getStackInSlot( 3 ) ) && this.anchor.isSameAs( inv.getStackInSlot( 5 ) ) && this.anchor.isSameAs( inv.getStackInSlot( 7 ) ) )
if( this.anchor.isSameAs( inv.getStackInSlot( 1 ) ) && this.anchor.isSameAs( inv.getStackInSlot( 3 ) ) && this.anchor.isSameAs( inv.getStackInSlot( 5 ) ) && this.anchor.isSameAs( inv.getStackInSlot( 7 ) ) )
{
for ( Item facadeItemDefinition : this.maybeFacade.asSet() )
for( Item facadeItemDefinition : this.maybeFacade.asSet() )
{
final ItemFacade facade = (ItemFacade) facadeItemDefinition;
ItemStack facades = facade.createFacadeForItem( inv.getStackInSlot( 4 ), !createFacade );
if ( facades != null && createFacade )
if( facades != null && createFacade )
facades.stackSize = 4;
return facades;
}
@@ -18,6 +18,7 @@
package appeng.recipes.game;
import java.util.ArrayList;
import java.util.HashMap;
@@ -31,6 +32,7 @@ import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.IIngredient;
public class ShapedRecipe implements IRecipe, IRecipeBakeable
{
@@ -45,22 +47,17 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
private boolean mirrored = true;
private boolean disable = false;
public boolean isEnabled()
{
return !this.disable;
}
public ShapedRecipe(ItemStack result, Object... recipe)
public ShapedRecipe( ItemStack result, Object... recipe )
{
this.output = result.copy();
StringBuilder shape = new StringBuilder();
int idx = 0;
if ( recipe[idx] instanceof Boolean )
if( recipe[idx] instanceof Boolean )
{
this.mirrored = (Boolean) recipe[idx];
if ( recipe[idx + 1] instanceof Object[] )
if( recipe[idx + 1] instanceof Object[] )
{
recipe = (Object[]) recipe[idx + 1];
}
@@ -70,12 +67,12 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
}
}
if ( recipe[idx] instanceof String[] )
if( recipe[idx] instanceof String[] )
{
String[] parts = ((String[]) recipe[idx]);
String[] parts = ( (String[]) recipe[idx] );
idx++;
for (String s : parts)
for( String s : parts )
{
this.width = s.length();
shape.append( s );
@@ -85,7 +82,7 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
}
else
{
while (recipe[idx] instanceof String)
while( recipe[idx] instanceof String )
{
String s = (String) recipe[idx];
idx++;
@@ -95,10 +92,10 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
}
}
if ( this.width * this.height != shape.length() )
if( this.width * this.height != shape.length() )
{
StringBuilder ret = new StringBuilder( "Invalid shaped ore recipe: " );
for (Object tmp : recipe)
for( Object tmp : recipe )
{
ret.append( tmp ).append( ", " );
}
@@ -108,19 +105,19 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
HashMap<Character, Object> itemMap = new HashMap<Character, Object>();
for (; idx < recipe.length; idx += 2)
for(; idx < recipe.length; idx += 2 )
{
Character chr = (Character) recipe[idx];
Object in = recipe[idx + 1];
if ( in instanceof IIngredient )
if( in instanceof IIngredient )
{
itemMap.put( chr, in );
}
else
{
StringBuilder ret = new StringBuilder( "Invalid shaped ore recipe: " );
for (Object tmp : recipe)
for( Object tmp : recipe )
{
ret.append( tmp ).append( ", " );
}
@@ -131,15 +128,45 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
this.input = new Object[this.width * this.height];
int x = 0;
for (char chr : shape.toString().toCharArray())
for( char chr : shape.toString().toCharArray() )
{
this.input[x] = itemMap.get( chr );
x++;
}
}
public boolean isEnabled()
{
return !this.disable;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting var1)
public boolean matches( InventoryCrafting inv, World world )
{
if( this.disable )
return false;
for( int x = 0; x <= MAX_CRAFT_GRID_WIDTH - this.width; x++ )
{
for( int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - this.height; ++y )
{
if( this.checkMatch( inv, x, y, false ) )
{
return true;
}
if( this.mirrored && this.checkMatch( inv, x, y, true ) )
{
return true;
}
}
}
return false;
}
@Override
public ItemStack getCraftingResult( InventoryCrafting var1 )
{
return this.output.copy();
}
@@ -156,48 +183,23 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
return this.output;
}
@Override
public boolean matches(InventoryCrafting inv, World world)
@SuppressWarnings( "unchecked" )
private boolean checkMatch( InventoryCrafting inv, int startX, int startY, boolean mirror )
{
if ( this.disable )
if( this.disable )
return false;
for (int x = 0; x <= MAX_CRAFT_GRID_WIDTH - this.width; x++)
for( int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++ )
{
for (int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - this.height; ++y)
{
if ( this.checkMatch( inv, x, y, false ) )
{
return true;
}
if ( this.mirrored && this.checkMatch( inv, x, y, true ) )
{
return true;
}
}
}
return false;
}
@SuppressWarnings("unchecked")
private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror)
{
if ( this.disable )
return false;
for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++)
{
for (int y = 0; y < MAX_CRAFT_GRID_HEIGHT; y++)
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 < this.width && subY < this.height )
if( subX >= 0 && subY >= 0 && subX < this.width && subY < this.height )
{
if ( mirror )
if( mirror )
{
target = this.input[this.width - subX - 1 + subY * this.width];
}
@@ -209,46 +211,46 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
ItemStack slot = inv.getStackInRowAndColumn( x, y );
if ( target instanceof IIngredient )
if( target instanceof IIngredient )
{
boolean matched = false;
try
{
for (ItemStack item : ((IIngredient) target).getItemStackSet())
for( ItemStack item : ( (IIngredient) target ).getItemStackSet() )
{
matched = matched || this.checkItemEquals( item, slot );
}
}
catch (RegistrationError e)
catch( RegistrationError e )
{
// :P
}
catch (MissingIngredientError e)
catch( MissingIngredientError e )
{
// :P
}
if ( !matched )
if( !matched )
{
return false;
}
}
else if ( target instanceof ArrayList )
else if( target instanceof ArrayList )
{
boolean matched = false;
for (ItemStack item : (ArrayList<ItemStack>) target)
for( ItemStack item : (ArrayList<ItemStack>) target )
{
matched = matched || this.checkItemEquals( item, slot );
}
if ( !matched )
if( !matched )
{
return false;
}
}
else if ( target == null && slot != null )
else if( target == null && slot != null )
{
return false;
}
@@ -258,17 +260,16 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
return true;
}
private boolean checkItemEquals(ItemStack target, ItemStack input)
private boolean checkItemEquals( ItemStack target, ItemStack input )
{
if ( input == null && target != null || input != null && target == null )
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()));
return ( target.getItem() == input.getItem() && ( target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input.getItemDamage() ) );
}
public ShapedRecipe setMirrored(boolean mirror)
public ShapedRecipe setMirrored( boolean mirror )
{
this.mirrored = mirror;
return this;
@@ -306,16 +307,15 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
try
{
this.disable = false;
for (Object o : this.input )
for( Object o : this.input )
{
if ( o instanceof IIngredient )
((IIngredient) o).bake();
if( o instanceof IIngredient )
( (IIngredient) o ).bake();
}
}
catch (MissingIngredientError err)
catch( MissingIngredientError err )
{
this.disable = true;
}
}
}
@@ -18,6 +18,7 @@
package appeng.recipes.game;
import java.util.ArrayList;
import net.minecraft.inventory.InventoryCrafting;
@@ -30,31 +31,27 @@ 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 final ArrayList<Object> input = new ArrayList<Object>();
private ItemStack output = null;
private boolean disable = false;
public boolean isEnabled()
{
return !this.disable;
}
public ShapelessRecipe(ItemStack result, Object... recipe)
public ShapelessRecipe( ItemStack result, Object... recipe )
{
this.output = result.copy();
for (Object in : recipe)
for( Object in : recipe )
{
if ( in instanceof IIngredient )
if( in instanceof IIngredient )
{
this.input.add( in );
}
else
{
StringBuilder ret = new StringBuilder( "Invalid shapeless ore recipe: " );
for (Object tmp : recipe)
for( Object tmp : recipe )
{
ret.append( tmp ).append( ", " );
}
@@ -64,6 +61,75 @@ public class ShapelessRecipe implements IRecipe, IRecipeBakeable
}
}
public boolean isEnabled()
{
return !this.disable;
}
@SuppressWarnings( "unchecked" )
@Override
public boolean matches( InventoryCrafting var1, World world )
{
if( this.disable )
return false;
ArrayList<Object> required = new ArrayList<Object>( this.input );
for( int x = 0; x < var1.getSizeInventory(); x++ )
{
ItemStack slot = var1.getStackInSlot( x );
if( slot != null )
{
boolean inRecipe = false;
for( Object next : required )
{
boolean match = false;
if( next instanceof IIngredient )
{
try
{
for( ItemStack item : ( (IIngredient) next ).getItemStackSet() )
{
match = match || this.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();
}
@Override
public ItemStack getCraftingResult( InventoryCrafting var1 )
{
return this.output.copy();
}
@Override
public int getRecipeSize()
{
@@ -76,74 +142,9 @@ public class ShapelessRecipe implements IRecipe, IRecipeBakeable
return this.output;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting var1)
private boolean checkItemEquals( ItemStack target, ItemStack input )
{
return this.output.copy();
}
@SuppressWarnings("unchecked")
@Override
public boolean matches(InventoryCrafting var1, World world)
{
if ( this.disable )
return false;
ArrayList<Object> required = new ArrayList<Object>( this.input );
for (int x = 0; x < var1.getSizeInventory(); x++)
{
ItemStack slot = var1.getStackInSlot( x );
if ( slot != null )
{
boolean inRecipe = false;
for (Object next : required)
{
boolean match = false;
if ( next instanceof IIngredient )
{
try
{
for (ItemStack item : ((IIngredient) next).getItemStackSet())
{
match = match || this.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()));
return ( target.getItem() == input.getItem() && ( target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input.getItemDamage() ) );
}
/**
@@ -163,13 +164,13 @@ public class ShapelessRecipe implements IRecipe, IRecipeBakeable
try
{
this.disable = false;
for (Object o : this.input )
for( Object o : this.input )
{
if ( o instanceof IIngredient )
((IIngredient) o).bake();
if( o instanceof IIngredient )
( (IIngredient) o ).bake();
}
}
catch (MissingIngredientError e)
catch( MissingIngredientError e )
{
this.disable = true;
}
@@ -18,6 +18,7 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
@@ -34,6 +35,7 @@ import appeng.integration.abstraction.IRC;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Crusher implements ICraftHandler, IWebsiteSerializer
{
@@ -41,12 +43,12 @@ public class Crusher implements ICraftHandler, IWebsiteSerializer
IIngredient[] pro_output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
if( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
@@ -59,16 +61,16 @@ public class Crusher implements ICraftHandler, IWebsiteSerializer
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.RC ) )
if( AppEng.instance.isIntegrationEnabled( IntegrationType.RC ) )
{
IRC rc = (IRC) AppEng.instance.getIntegration( IntegrationType.RC );
for (ItemStack is : this.pro_input.getItemStackSet())
for( ItemStack is : this.pro_input.getItemStackSet() )
{
try
{
rc.rockCrusher( is, this.pro_output[0].getItemStack() );
}
catch (java.lang.RuntimeException err)
catch( java.lang.RuntimeException err )
{
AELog.info( "RC not happy - " + err.getMessage() );
}
@@ -77,15 +79,14 @@ public class Crusher implements ICraftHandler, IWebsiteSerializer
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
public String getPattern( RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( ItemStack output ) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
}
@@ -32,6 +32,7 @@ import appeng.api.recipes.IIngredient;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Grind implements ICraftHandler, IWebsiteSerializer
{
@@ -39,12 +40,12 @@ public class Grind implements ICraftHandler, IWebsiteSerializer
IIngredient[] pro_output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
if( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
@@ -57,20 +58,21 @@ public class Grind implements ICraftHandler, IWebsiteSerializer
@Override
public void register() throws RegistrationError, MissingIngredientError
{
for (ItemStack is : this.pro_input.getItemStackSet())
for( ItemStack is : this.pro_input.getItemStackSet() )
AEApi.instance().registries().grinder().addRecipe( is, this.pro_output[0].getItemStack(), 8 );
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError {
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(),output );
public String getPattern( RecipeHandler h )
{
return "grind\n" +
h.getName( this.pro_input ) + '\n' +
h.getName( this.pro_output[0] );
}
@Override
public String getPattern( RecipeHandler h ) {
return "grind\n"+
h.getName(this.pro_input)+ '\n' +
h.getName(this.pro_output[0]);
public boolean canCraft( ItemStack output ) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
}
@@ -18,6 +18,7 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
@@ -34,6 +35,7 @@ import appeng.integration.abstraction.IFZ;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class GrindFZ implements ICraftHandler, IWebsiteSerializer
{
@@ -41,12 +43,12 @@ public class GrindFZ implements ICraftHandler, IWebsiteSerializer
IIngredient[] pro_output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
if( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
@@ -59,16 +61,16 @@ public class GrindFZ implements ICraftHandler, IWebsiteSerializer
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.FZ ) )
if( AppEng.instance.isIntegrationEnabled( IntegrationType.FZ ) )
{
IFZ fz = (IFZ) AppEng.instance.getIntegration( IntegrationType.FZ );
for (ItemStack is : this.pro_input.getItemStackSet())
for( ItemStack is : this.pro_input.getItemStackSet() )
{
try
{
fz.grinderRecipe( is, this.pro_output[0].getItemStack() );
}
catch (java.lang.RuntimeException err)
catch( java.lang.RuntimeException err )
{
AELog.info( "FZ not happy - " + err.getMessage() );
}
@@ -77,15 +79,14 @@ public class GrindFZ implements ICraftHandler, IWebsiteSerializer
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
public String getPattern( RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( ItemStack output ) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
}
@@ -18,6 +18,7 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
@@ -34,6 +35,7 @@ import appeng.core.AELog;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class HCCrusher implements ICraftHandler, IWebsiteSerializer
{
@@ -41,12 +43,12 @@ public class HCCrusher implements ICraftHandler, IWebsiteSerializer
IIngredient[] pro_output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
if( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
@@ -59,7 +61,7 @@ public class HCCrusher implements ICraftHandler, IWebsiteSerializer
@Override
public void register() throws RegistrationError, MissingIngredientError
{
for (ItemStack beginStack : this.pro_input.getItemStackSet())
for( ItemStack beginStack : this.pro_input.getItemStackSet() )
{
try
{
@@ -71,15 +73,15 @@ public class HCCrusher implements ICraftHandler, IWebsiteSerializer
NBTTagCompound itemTo = new NBTTagCompound();
beginStack.writeToNBT( itemFrom );
endStack.writeToNBT(itemTo);
endStack.writeToNBT( itemTo );
toRegister.setTag("itemFrom", itemFrom);
toRegister.setTag("itemTo", itemTo);
toRegister.setFloat("pressureRatio", 1.0F);
toRegister.setTag( "itemFrom", itemFrom );
toRegister.setTag( "itemTo", itemTo );
toRegister.setFloat( "pressureRatio", 1.0F );
FMLInterModComms.sendMessage("HydCraft", "registerCrushingRecipe", toRegister);
FMLInterModComms.sendMessage( "HydCraft", "registerCrushingRecipe", toRegister );
}
catch (java.lang.RuntimeException err)
catch( java.lang.RuntimeException err )
{
AELog.info( "Hydraulicraft not happy - " + err.getMessage() );
}
@@ -87,15 +89,14 @@ public class HCCrusher implements ICraftHandler, IWebsiteSerializer
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
public String getPattern( RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( ItemStack output ) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
}
@@ -18,17 +18,18 @@
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;
String getPattern( RecipeHandler han );
boolean canCraft( ItemStack output ) throws RegistrationError, MissingIngredientError;
}
@@ -34,54 +34,31 @@ 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;
this.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 final HashSet<ItemStack> PLATES = new HashSet<ItemStack>();
public static final HashSet<ItemStack> INPUTS = new HashSet<ItemStack>();
public static final LinkedList<InscriberRecipe> RECIPES = new LinkedList<InscriberRecipe>();
public boolean usePlates = false;
IIngredient imprintable;
IIngredient plateA;
IIngredient plateB;
IIngredient output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
if ( output.size() == 1 && output.get( 0 ).size() == 1 )
if( output.size() == 1 && output.get( 0 ).size() == 1 )
{
if ( input.size() == 1 && input.get( 0 ).size() > 1 )
if( input.size() == 1 && input.get( 0 ).size() > 1 )
{
this.imprintable = input.get( 0 ).get( 0 );
this.plateA = input.get( 0 ).get( 1 );
if ( input.get( 0 ).size() > 2 )
if( input.get( 0 ).size() > 2 )
this.plateB = input.get( 0 ).get( 2 );
this.output = output.get( 0 ).get( 0 );
@@ -96,42 +73,59 @@ public class Inscribe implements ICraftHandler, IWebsiteSerializer
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( this.imprintable != null )
if( this.imprintable != null )
Collections.addAll( INPUTS, this.imprintable.getItemStackSet() );
if ( this.plateA != null )
if( this.plateA != null )
Collections.addAll( PLATES, this.plateA.getItemStackSet() );
if ( this.plateB != null )
if( this.plateB != null )
Collections.addAll( PLATES, this.plateB.getItemStackSet() );
InscriberRecipe ir = new InscriberRecipe( this.imprintable.getItemStackSet(), this.plateA == null ? null : this.plateA.getItemStack(), this.plateB == null ? null
: this.plateB.getItemStack(), this.output.getItemStack(), this.usePlates );
InscriberRecipe ir = new InscriberRecipe( this.imprintable.getItemStackSet(), this.plateA == null ? null : this.plateA.getItemStack(), this.plateB == null ? null : this.plateB.getItemStack(), this.output.getItemStack(), this.usePlates );
RECIPES.add( ir );
}
@Override
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.output.getItemStack(), reqOutput );
}
@Override
public String getPattern(RecipeHandler h)
public String getPattern( RecipeHandler h )
{
String o = "inscriber " + this.output.getQty() + '\n';
o += h.getName( this.output ) + '\n';
if ( this.plateA != null )
o += h.getName( this.plateA )+ '\n';
if( this.plateA != null )
o += h.getName( this.plateA ) + '\n';
o += h.getName(this.imprintable);
o += h.getName( this.imprintable );
if ( this.plateB != null )
o += '\n' +h.getName( this.plateB );
if( this.plateB != null )
o += '\n' + h.getName( this.plateB );
return o;
}
@Override
public boolean canCraft( ItemStack reqOutput ) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.output.getItemStack(), reqOutput );
}
public static class InscriberRecipe
{
final public boolean usePlates;
final public ItemStack plateA;
final public ItemStack[] imprintable;
final public ItemStack plateB;
final public ItemStack output;
public InscriberRecipe( ItemStack[] imprintable, ItemStack plateA, ItemStack plateB, ItemStack out, boolean usePlates )
{
this.imprintable = imprintable;
this.usePlates = usePlates;
this.plateA = plateA;
this.plateB = plateB;
this.output = out;
}
}
}
@@ -18,6 +18,7 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
@@ -34,6 +35,7 @@ import appeng.integration.abstraction.IIC2;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Macerator implements ICraftHandler, IWebsiteSerializer
{
@@ -41,12 +43,12 @@ public class Macerator implements ICraftHandler, IWebsiteSerializer
IIngredient[] pro_output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
if( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
@@ -59,16 +61,16 @@ public class Macerator implements ICraftHandler, IWebsiteSerializer
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) )
if( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) )
{
IIC2 ic2 = (IIC2) AppEng.instance.getIntegration( IntegrationType.IC2 );
for (ItemStack is : this.pro_input.getItemStackSet())
for( ItemStack is : this.pro_input.getItemStackSet() )
{
try
{
ic2.maceratorRecipe( is, this.pro_output[0].getItemStack() );
}
catch (java.lang.RuntimeException err)
catch( java.lang.RuntimeException err )
{
AELog.info( "IC2 not happy - " + err.getMessage() );
}
@@ -77,15 +79,14 @@ public class Macerator implements ICraftHandler, IWebsiteSerializer
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
public String getPattern( RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( ItemStack output ) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
}
@@ -18,6 +18,7 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
@@ -34,6 +35,7 @@ import appeng.integration.abstraction.IMekanism;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class MekCrusher implements ICraftHandler, IWebsiteSerializer
{
@@ -41,12 +43,12 @@ public class MekCrusher implements ICraftHandler, IWebsiteSerializer
IIngredient[] pro_output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
if( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
@@ -59,16 +61,16 @@ public class MekCrusher implements ICraftHandler, IWebsiteSerializer
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.Mekanism ) )
if( AppEng.instance.isIntegrationEnabled( IntegrationType.Mekanism ) )
{
IMekanism rc = (IMekanism) AppEng.instance.getIntegration( IntegrationType.Mekanism );
for (ItemStack is : this.pro_input.getItemStackSet())
for( ItemStack is : this.pro_input.getItemStackSet() )
{
try
{
rc.addCrusherRecipe( is, this.pro_output[0].getItemStack() );
}
catch (java.lang.RuntimeException err)
catch( java.lang.RuntimeException err )
{
AELog.info( "Mekanism not happy - " + err.getMessage() );
}
@@ -77,15 +79,14 @@ public class MekCrusher implements ICraftHandler, IWebsiteSerializer
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
public String getPattern( RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( ItemStack output ) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
}
@@ -18,6 +18,7 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
@@ -34,6 +35,7 @@ import appeng.integration.abstraction.IMekanism;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class MekEnrichment implements ICraftHandler, IWebsiteSerializer
{
@@ -41,12 +43,12 @@ public class MekEnrichment implements ICraftHandler, IWebsiteSerializer
IIngredient[] pro_output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
if( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
@@ -59,16 +61,16 @@ public class MekEnrichment implements ICraftHandler, IWebsiteSerializer
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.Mekanism ) )
if( AppEng.instance.isIntegrationEnabled( IntegrationType.Mekanism ) )
{
IMekanism rc = (IMekanism) AppEng.instance.getIntegration( IntegrationType.Mekanism );
for (ItemStack is : this.pro_input.getItemStackSet())
for( ItemStack is : this.pro_input.getItemStackSet() )
{
try
{
rc.addEnrichmentChamberRecipe( is, this.pro_output[0].getItemStack() );
}
catch (java.lang.RuntimeException err)
catch( java.lang.RuntimeException err )
{
AELog.info( "Mekanism not happy - " + err.getMessage() );
}
@@ -77,15 +79,14 @@ public class MekEnrichment implements ICraftHandler, IWebsiteSerializer
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
public String getPattern( RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( ItemStack output ) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
}
@@ -18,6 +18,7 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
@@ -29,33 +30,34 @@ import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
public class OreRegistration implements ICraftHandler
{
final List<IIngredient> inputs;
final String name;
public OreRegistration(List<IIngredient> in, String out) {
public OreRegistration( List<IIngredient> in, String out )
{
this.inputs = in;
this.name = out;
}
@Override
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
}
@Override
public void register() throws RegistrationError, MissingIngredientError
{
for (IIngredient i : this.inputs)
for( IIngredient i : this.inputs )
{
for (ItemStack is : i.getItemStackSet())
for( ItemStack is : i.getItemStackSet() )
{
OreDictionary.registerOre( this.name, is );
}
}
}
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
}
}
@@ -18,11 +18,12 @@
package appeng.recipes.handlers;
public class Press extends Inscribe
{
public Press() {
public Press()
{
this.usePlates = true;
}
}
@@ -18,6 +18,7 @@
package appeng.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
@@ -33,6 +34,7 @@ import appeng.api.recipes.IIngredient;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Pulverizer implements ICraftHandler, IWebsiteSerializer
{
@@ -40,12 +42,12 @@ public class Pulverizer implements ICraftHandler, IWebsiteSerializer
IIngredient[] pro_output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
if( input.size() == 1 && output.size() == 1 )
{
int outs = output.get( 0 ).size();
if ( input.get( 0 ).size() == 1 && outs == 1 )
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
@@ -64,7 +66,7 @@ public class Pulverizer implements ICraftHandler, IWebsiteSerializer
this.pro_output[0].getItemStack().writeToNBT( toSend.getCompoundTag( "primaryOutput" ) );
for (ItemStack is : this.pro_input.getItemStackSet())
for( ItemStack is : this.pro_input.getItemStackSet() )
{
toSend.setTag( "input", new NBTTagCompound() );
is.writeToNBT( toSend.getCompoundTag( "input" ) );
@@ -73,15 +75,14 @@ public class Pulverizer implements ICraftHandler, IWebsiteSerializer
}
@Override
public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
@Override
public String getPattern(RecipeHandler h)
public String getPattern( RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( ItemStack output ) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output );
}
}
@@ -36,29 +36,29 @@ import appeng.recipes.RecipeHandler;
import appeng.recipes.game.ShapedRecipe;
import appeng.util.Platform;
public class Shaped implements ICraftHandler, IWebsiteSerializer
{
List<List<IIngredient>> inputs;
IIngredient output;
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
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
if ( output.size() == 1 && output.get( 0 ).size() == 1 )
if( output.size() == 1 && output.get( 0 ).size() == 1 )
{
this.rows = input.size();
if ( this.rows > 0 && input.size() <= 3 )
if( this.rows > 0 && input.size() <= 3 )
{
this.cols = input.get( 0 ).size();
if ( this.cols <= 3 && this.cols >= 1 )
if( this.cols <= 3 && this.cols >= 1 )
{
for (List<IIngredient> anInput : input)
for( List<IIngredient> anInput : input )
{
if ( anInput.size() != this.cols )
if( anInput.size() != this.cols )
{
throw new RecipeError( "all rows in a shaped crafting recipe must contain the same number of ingredients." );
}
@@ -83,12 +83,12 @@ public class Shaped implements ICraftHandler, IWebsiteSerializer
char first = 'A';
List<Object> args = new ArrayList<Object>();
for (int y = 0; y < this.rows; y++)
for( int y = 0; y < this.rows; y++ )
{
StringBuilder row = new StringBuilder();
for (int x = 0; x < this.cols; x++)
for( int x = 0; x < this.cols; x++ )
{
if ( this.inputs.get( y ).get( x ).isAir() )
if( this.inputs.get( y ).get( x ).isAir() )
row.append( ' ' );
else
{
@@ -108,7 +108,7 @@ public class Shaped implements ICraftHandler, IWebsiteSerializer
{
GameRegistry.addRecipe( new ShapedRecipe( outIS, args.toArray( new Object[args.size()] ) ) );
}
catch (Throwable e)
catch( Throwable e )
{
AELog.error( e );
throw new RegistrationError( "Error while adding shaped recipe." );
@@ -116,18 +116,39 @@ public class Shaped implements ICraftHandler, IWebsiteSerializer
}
@Override
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError
public String getPattern( RecipeHandler h )
{
for (int y = 0; y < this.rows; y++)
for (int x = 0; x < this.cols; x++)
String o = "shaped " + this.output.getQty() + ' ' + this.cols + 'x' + this.rows + '\n';
o += h.getName( this.output ) + '\n';
for( int y = 0; y < this.rows; y++ )
for( int x = 0; x < this.cols; x++ )
{
IIngredient i = this.inputs.get( y ).get( x );
if ( !i.isAir() )
if( i.isAir() )
o += "air" + ( x + 1 == this.cols ? "\n" : " " );
else
o += h.getName( i ) + ( x + 1 == this.cols ? "\n" : " " );
}
return o.trim();
}
@Override
public boolean canCraft( ItemStack reqOutput ) throws RegistrationError, MissingIngredientError
{
for( int y = 0; y < this.rows; y++ )
for( int x = 0; x < this.cols; x++ )
{
IIngredient i = this.inputs.get( y ).get( x );
if( !i.isAir() )
{
for ( ItemStack r : i.getItemStackSet() )
for( ItemStack r : i.getItemStackSet() )
{
if ( Platform.isSameItemPrecise( r, reqOutput) )
if( Platform.isSameItemPrecise( r, reqOutput ) )
return false;
}
}
@@ -135,25 +156,4 @@ public class Shaped implements ICraftHandler, IWebsiteSerializer
return Platform.isSameItemPrecise( this.output.getItemStack(), reqOutput );
}
@Override
public String getPattern(RecipeHandler h)
{
String o = "shaped " + this.output.getQty() + ' ' + this.cols + 'x' + this.rows + '\n';
o += h.getName( this.output ) + '\n';
for (int y = 0; y < this.rows; y++)
for (int x = 0; x < this.cols; x++)
{
IIngredient i = this.inputs.get( y ).get( x );
if ( i.isAir() )
o += "air" + (x + 1 == this.cols ? "\n" : " ");
else
o += h.getName( i ) + (x + 1 == this.cols ? "\n" : " ");
}
return o.trim();
}
}
@@ -36,6 +36,7 @@ import appeng.recipes.RecipeHandler;
import appeng.recipes.game.ShapelessRecipe;
import appeng.util.Platform;
public class Shapeless implements ICraftHandler, IWebsiteSerializer
{
@@ -43,11 +44,11 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
IIngredient output;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
if ( output.size() == 1 && output.get( 0 ).size() == 1 )
if( output.size() == 1 && output.get( 0 ).size() == 1 )
{
if ( input.size() == 1 )
if( input.size() == 1 )
{
this.inputs = input.get( 0 );
this.output = output.get( 0 ).get( 0 );
@@ -63,7 +64,7 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
public void register() throws RegistrationError, MissingIngredientError
{
List<Object> args = new ArrayList<Object>();
for (IIngredient i : this.inputs)
for( IIngredient i : this.inputs )
args.add( i );
ItemStack outIS = this.output.getItemStack();
@@ -72,7 +73,7 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
{
GameRegistry.addRecipe( new ShapelessRecipe( outIS, args.toArray( new Object[args.size()] ) ) );
}
catch (Throwable e)
catch( Throwable e )
{
AELog.error( e );
throw new RegistrationError( "Error while adding shapeless recipe." );
@@ -80,38 +81,17 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
}
@Override
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError
{
for (IIngredient i : this.inputs)
{
if ( !i.isAir() )
{
for (ItemStack r : i.getItemStackSet())
{
if ( Platform.isSameItemPrecise( r, reqOutput ) )
{
return false;
}
}
}
}
return Platform.isSameItemPrecise( this.output.getItemStack(), reqOutput );
}
@Override
public String getPattern(RecipeHandler h)
public String getPattern( RecipeHandler h )
{
StringBuilder o = new StringBuilder( "shapeless " + this.output.getQty() + '\n' );
o.append( h.getName( this.output ) ).append( '\n' );
for (int y = 0; y < this.inputs.size(); y++)
for( int y = 0; y < this.inputs.size(); y++ )
{
IIngredient i = this.inputs.get( y );
if ( i.isAir() )
if( i.isAir() )
{
o.append( "air" );
}
@@ -120,7 +100,7 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
o.append( h.getName( i ) );
}
if ( y + 1 == this.inputs.size() )
if( y + 1 == this.inputs.size() )
{
o.append( '\n' );
}
@@ -133,4 +113,24 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
return o.toString().trim();
}
@Override
public boolean canCraft( ItemStack reqOutput ) throws RegistrationError, MissingIngredientError
{
for( IIngredient i : this.inputs )
{
if( !i.isAir() )
{
for( ItemStack r : i.getItemStackSet() )
{
if( Platform.isSameItemPrecise( r, reqOutput ) )
{
return false;
}
}
}
}
return Platform.isSameItemPrecise( this.output.getItemStack(), reqOutput );
}
}
@@ -33,6 +33,7 @@ import appeng.api.recipes.IIngredient;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Smelt implements ICraftHandler, IWebsiteSerializer
{
@@ -40,13 +41,13 @@ public class Smelt implements ICraftHandler, IWebsiteSerializer
IIngredient out;
@Override
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
public void setup( List<List<IIngredient>> input, List<List<IIngredient>> output ) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
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 )
if( inputList.size() == 1 && outputList.size() == 1 )
{
this.in = inputList.get( 0 );
this.out = outputList.get( 0 );
@@ -59,24 +60,26 @@ public class Smelt implements ICraftHandler, IWebsiteSerializer
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( this.in.getItemStack().getItem() == null )
if( this.in.getItemStack().getItem() == null )
throw new RegistrationError( this.in.toString() + ": Smelting Input is not a valid item." );
if ( this.out.getItemStack().getItem() == null )
if( this.out.getItemStack().getItem() == null )
throw new RegistrationError( this.out.toString() + ": Smelting Output is not a valid item." );
GameRegistry.addSmelting( this.in.getItemStack(), this.out.getItemStack(), 0 );
}
@Override
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError {
return Platform.isSameItemPrecise( this.out.getItemStack(),reqOutput );
public String getPattern( RecipeHandler h )
{
return "smelt " + this.out.getQty() + '\n' +
h.getName( this.out ) + '\n' +
h.getName( this.in );
}
@Override
public String getPattern( RecipeHandler h ) {
return "smelt "+this.out.getQty()+ '\n' +
h.getName(this.out)+ '\n' +
h.getName(this.in);
public boolean canCraft( ItemStack reqOutput ) throws RegistrationError, MissingIngredientError
{
return Platform.isSameItemPrecise( this.out.getItemStack(), reqOutput );
}
}
@@ -18,24 +18,26 @@
package appeng.recipes.loader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import appeng.api.recipes.IRecipeLoader;
public class JarLoader implements IRecipeLoader
{
private final String rootPath;
public JarLoader(String s) {
public JarLoader( String s )
{
this.rootPath = s;
}
@Override
public BufferedReader getFile(String s) throws Exception
public BufferedReader getFile( String s ) throws Exception
{
return new BufferedReader( new InputStreamReader( this.getClass().getResourceAsStream( this.rootPath + s ), "UTF-8" ) );
}
}
@@ -18,8 +18,10 @@
package appeng.recipes.ores;
import net.minecraft.item.ItemStack;
public interface IOreListener
{
@@ -30,6 +32,5 @@ public interface IOreListener
* @param name name of ore
* @param item item with name
*/
void oreRegistered(String name, ItemStack item);
void oreRegistered( String name, ItemStack item );
}
@@ -18,6 +18,7 @@
package appeng.recipes.ores;
import java.util.ArrayList;
import java.util.List;
@@ -30,6 +31,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import appeng.core.AELog;
import appeng.recipes.game.IRecipeBakeable;
public class OreDictionaryHandler
{
@@ -39,31 +41,52 @@ public class OreDictionaryHandler
private boolean enableRebaking = false;
@SubscribeEvent
public void onOreDictionaryRegister( OreDictionary.OreRegisterEvent event )
{
if( event.Name == null || event.Ore == null )
return;
if( this.shouldCare( event.Name ) )
{
for( IOreListener v : this.ol )
v.oreRegistered( event.Name, event.Ore );
}
if( this.enableRebaking )
this.bakeRecipes();
}
/**
* Just limit what items are sent to the final listeners, I got sick of strange items showing up...
*
* @param name name about cared item
*
* @return true if it should care
*/
private boolean shouldCare(String name)
private boolean shouldCare( String name )
{
return true;
}
@SubscribeEvent
public void onOreDictionaryRegister(OreDictionary.OreRegisterEvent event)
public void bakeRecipes()
{
if ( event.Name == null || event.Ore == null )
return;
this.enableRebaking = true;
if ( this.shouldCare( event.Name ) )
for( Object o : CraftingManager.getInstance().getRecipeList() )
{
for (IOreListener v : this.ol)
v.oreRegistered( event.Name, event.Ore );
if( o instanceof IRecipeBakeable )
{
try
{
( (IRecipeBakeable) o ).bake();
}
catch( Throwable e )
{
AELog.error( e );
}
}
}
if ( this.enableRebaking )
this.bakeRecipes();
}
/**
@@ -72,42 +95,21 @@ public class OreDictionaryHandler
*
* @param n to be added ore listener
*/
public void observe(IOreListener n)
public void observe( IOreListener n )
{
this.ol.add( n );
// notify the listener of any ore already in existence.
for (String name : OreDictionary.getOreNames())
for( String name : OreDictionary.getOreNames() )
{
if ( name != null && this.shouldCare( name ) )
if( name != null && this.shouldCare( name ) )
{
for (ItemStack item : OreDictionary.getOres( name ))
for( ItemStack item : OreDictionary.getOres( name ) )
{
if ( item != null )
if( item != null )
n.oreRegistered( name, item );
}
}
}
}
public void bakeRecipes()
{
this.enableRebaking = true;
for (Object o : CraftingManager.getInstance().getRecipeList())
{
if ( o instanceof IRecipeBakeable )
{
try
{
((IRecipeBakeable) o).bake();
}
catch (Throwable e)
{
AELog.error( e );
}
}
}
}
}