2014-02-10 04:16:36 +01:00
|
|
|
package appeng.recipes.handlers;
|
|
|
|
|
2014-02-11 06:51:25 +01:00
|
|
|
import java.util.ArrayList;
|
2014-02-10 04:16:36 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2014-02-11 06:51:25 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-02-20 00:33:36 +01:00
|
|
|
import appeng.api.exceptions.MissingIngredientError;
|
|
|
|
import appeng.api.exceptions.RecipeError;
|
|
|
|
import appeng.api.exceptions.RegistrationError;
|
|
|
|
import appeng.api.recipes.ICraftHandler;
|
|
|
|
import appeng.api.recipes.IIngredient;
|
2014-02-11 06:51:25 +01:00
|
|
|
import appeng.core.AELog;
|
2014-03-05 20:34:56 +01:00
|
|
|
import appeng.recipes.RecipeHandler;
|
|
|
|
import appeng.recipes.game.ShapelessRecipe;
|
|
|
|
import appeng.util.Platform;
|
2014-02-11 06:51:25 +01:00
|
|
|
import cpw.mods.fml.common.registry.GameRegistry;
|
2014-02-10 04:16:36 +01:00
|
|
|
|
2014-03-05 20:34:56 +01:00
|
|
|
public class Shapeless implements ICraftHandler, IWebsiteSeralizer
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
|
|
|
|
2014-02-20 00:33:36 +01:00
|
|
|
List<IIngredient> inputs;
|
|
|
|
IIngredient output;
|
2014-02-10 04:16:36 +01:00
|
|
|
|
|
|
|
@Override
|
2014-02-20 00:33:36 +01:00
|
|
|
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
|
|
|
if ( output.size() == 1 && output.get( 0 ).size() == 1 )
|
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
if ( input.size() == 1 )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
|
|
|
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
|
2014-02-11 06:51:25 +01:00
|
|
|
public void register() throws RegistrationError, MissingIngredientError
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2014-02-20 00:33:36 +01:00
|
|
|
List<Object> args = new ArrayList<Object>();
|
|
|
|
for (IIngredient i : inputs)
|
|
|
|
args.add( i.getItemStackSet() );
|
2014-02-10 04:16:36 +01:00
|
|
|
|
2014-02-11 06:51:25 +01:00
|
|
|
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( "Erro while adding shapeless recipe." );
|
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
2014-03-05 20:34:56 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|