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.ShapedRecipe;
|
|
|
|
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 Shaped implements ICraftHandler, IWebsiteSeralizer
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
private int rows;
|
|
|
|
private int cols;
|
|
|
|
|
2014-02-20 00:33:36 +01:00
|
|
|
List<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
|
|
|
rows = input.size();
|
|
|
|
if ( rows > 0 && input.size() <= 3 )
|
2014-02-10 04:16:36 +01:00
|
|
|
{
|
2014-02-11 06:51:25 +01:00
|
|
|
cols = input.get( 0 ).size();
|
2014-02-27 04:56:33 +01:00
|
|
|
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." );
|
2014-02-10 04:16:36 +01:00
|
|
|
|
2014-02-27 04:56:33 +01:00
|
|
|
inputs = input;
|
|
|
|
this.output = output.get( 0 ).get( 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw new RecipeError( "Crafting recipes must have 1-3 columns." );
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
throw new RecipeError( "shaped crafting recpies must have 1-3 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-11 06:51:25 +01:00
|
|
|
char first = 'A';
|
2014-02-20 00:33:36 +01:00
|
|
|
List<Object> args = new ArrayList<Object>();
|
2014-02-10 04:16:36 +01:00
|
|
|
|
2014-02-11 06:51:25 +01:00
|
|
|
for (int y = 0; y < rows; y++)
|
|
|
|
{
|
|
|
|
String row = "";
|
|
|
|
for (int x = 0; x < cols; x++)
|
|
|
|
{
|
2014-02-20 00:33:36 +01:00
|
|
|
if ( inputs.get( y ).get( x ).isAir() )
|
2014-02-11 06:51:25 +01:00
|
|
|
row = row + " ";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
row = row + first;
|
|
|
|
args.add( first );
|
2014-02-20 00:33:36 +01:00
|
|
|
args.add( inputs.get( y ).get( x ).getItemStackSet() );
|
2014-02-11 06:51:25 +01:00
|
|
|
|
|
|
|
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." );
|
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|
2014-03-05 20:34:56 +01:00
|
|
|
|
|
|
|
@Override
|
2014-03-09 04:35:53 +01:00
|
|
|
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError
|
|
|
|
{
|
|
|
|
return Platform.isSameItemPrecise( output.getItemStack(), reqOutput );
|
2014-03-05 20:34:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-09 04:35:53 +01:00
|
|
|
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" : " ");
|
|
|
|
}
|
2014-03-05 20:34:56 +01:00
|
|
|
|
|
|
|
return o.trim();
|
|
|
|
}
|
2014-02-10 04:16:36 +01:00
|
|
|
}
|