Recipe API Update.

This commit is contained in:
AlgorithmX2
2014-02-19 17:33:36 -06:00
parent 85b053f6b5
commit bea8f2cc07
26 changed files with 292 additions and 203 deletions
+33 -2
View File
@@ -6,13 +6,17 @@ import net.minecraft.block.Block;
import net.minecraft.item.Item;
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;
import appeng.core.AppEng;
import appeng.items.materials.MaterialType;
import appeng.items.parts.ItemPart;
import appeng.items.parts.PartType;
import cpw.mods.fml.common.registry.GameRegistry;
public class Ingredient
public class Ingredient implements IIngredient
{
final public boolean isAir;
@@ -106,6 +110,7 @@ public class Ingredient
throw new RecipeError( input + " : Needs at least Namespace and Name." );
}
@Override
public ItemStack getItemStack() throws RegistrationError, MissingIngredientError
{
if ( isAir )
@@ -150,7 +155,8 @@ public class Ingredient
return nameSpace + ":" + itemName + ":" + meta;
}
public ItemStack[] getSet() throws RegistrationError, MissingIngredientError
@Override
public ItemStack[] getItemStackSet() throws RegistrationError, MissingIngredientError
{
if ( nameSpace.equalsIgnoreCase( "oreDictionary" ) )
{
@@ -171,4 +177,29 @@ public class Ingredient
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;
}
}
-11
View File
@@ -1,11 +0,0 @@
package appeng.recipes;
public class MissingIngredientError extends Exception {
private static final long serialVersionUID = -998858343831371697L;
public MissingIngredientError(String n) {
super( n );
}
}
+2 -2
View File
@@ -4,13 +4,13 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import appeng.recipes.handlers.CraftHandler;
import appeng.api.recipes.ICraftHandler;
public class RecipeData
{
final public HashMap<String, String> aliases = new HashMap<String, String>();
final public List<CraftHandler> Handlers = new LinkedList<CraftHandler>();
final public List<ICraftHandler> Handlers = new LinkedList<ICraftHandler>();
public boolean crash = true;
public boolean erroronmissing = true;
-12
View File
@@ -1,12 +0,0 @@
package appeng.recipes;
public class RecipeError extends Exception
{
private static final long serialVersionUID = -6602870588617670262L;
public RecipeError(String n) {
super( n );
}
}
+21 -24
View File
@@ -6,10 +6,16 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
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.AELog;
import appeng.recipes.handlers.CraftHandler;
import appeng.recipes.handlers.Grind;
import appeng.recipes.handlers.OreRegistration;
import appeng.recipes.handlers.Pureify;
@@ -31,7 +37,7 @@ public class RecipeHandler implements IRecipeHandler
data = parent.data;
}
private void addCrafting(CraftHandler ch)
private void addCrafting(ICraftHandler ch)
{
data.Handlers.add( ch );
}
@@ -42,7 +48,7 @@ public class RecipeHandler implements IRecipeHandler
HashMap<Class, Integer> processed = new HashMap<Class, Integer>();
try
{
for (CraftHandler ch : data.Handlers)
for (ICraftHandler ch : data.Handlers)
{
try
{
@@ -206,6 +212,8 @@ public class RecipeHandler implements IRecipeHandler
{
try
{
IRecipeHandlerRegistry cr = AEApi.instance().registries().recipes();
if ( tokens.isEmpty() )
return;
@@ -226,7 +234,7 @@ public class RecipeHandler implements IRecipeHandler
List<String> pre = tokens.subList( 0, split - 1 );
List<String> post = tokens.subList( split, tokens.size() );
List<List<Ingredient>> inputs = parseLines( pre );
List<List<IIngredient>> inputs = parseLines( pre );
if ( inputs.size() >= 1 && post.size() == 1 )
{
@@ -240,11 +248,11 @@ public class RecipeHandler implements IRecipeHandler
List<String> pre = tokens.subList( 0, split - 1 );
List<String> post = tokens.subList( split, tokens.size() );
List<List<Ingredient>> inputs = parseLines( pre );
List<List<IIngredient>> inputs = parseLines( pre );
if ( inputs.size() == 1 && inputs.get( 0 ).size() > 0 && post.size() == 1 )
{
CraftHandler ch = new OreRegistration( inputs.get( 0 ), post.get( 0 ) );
ICraftHandler ch = new OreRegistration( inputs.get( 0 ), post.get( 0 ) );
addCrafting( ch );
}
else
@@ -255,21 +263,10 @@ public class RecipeHandler implements IRecipeHandler
List<String> pre = tokens.subList( 0, split - 1 );
List<String> post = tokens.subList( split, tokens.size() );
List<List<Ingredient>> inputs = parseLines( pre );
List<List<Ingredient>> outputs = parseLines( post );
List<List<IIngredient>> inputs = parseLines( pre );
List<List<IIngredient>> outputs = parseLines( post );
CraftHandler ch = null;
if ( operation.equals( "shaped" ) )
ch = new Shaped();
else if ( operation.equals( "shapeless" ) )
ch = new Shapeless();
else if ( operation.equals( "smelt" ) )
ch = new Smelt();
else if ( operation.equals( "pureify" ) )
ch = new Pureify();
else if ( operation.equals( "grind" ) )
ch = new Grind();
ICraftHandler ch = cr.getCraftHandlerFor(operation);
if ( ch != null )
{
@@ -325,10 +322,10 @@ public class RecipeHandler implements IRecipeHandler
tokens.clear();
}
private List<List<Ingredient>> parseLines(List<String> subList) throws RecipeError
private List<List<IIngredient>> parseLines(List<String> subList) throws RecipeError
{
List<List<Ingredient>> out = new LinkedList<List<Ingredient>>();
List<Ingredient> cList = new LinkedList<Ingredient>();
List<List<IIngredient>> out = new LinkedList<List<IIngredient>>();
List<IIngredient> cList = new LinkedList<IIngredient>();
boolean hasQty = false;
int qty = 1;
@@ -341,7 +338,7 @@ public class RecipeHandler implements IRecipeHandler
throw new RecipeError( "Qty found with no item." );
if ( !cList.isEmpty() )
out.add( cList );
cList = new LinkedList<Ingredient>();
cList = new LinkedList<IIngredient>();
}
else
{
-12
View File
@@ -1,12 +0,0 @@
package appeng.recipes;
public class RegistrationError extends Exception
{
private static final long serialVersionUID = -6602870588617670263L;
public RegistrationError(String n) {
super( n );
}
}
-21
View File
@@ -1,21 +0,0 @@
package appeng.recipes.handlers;
import java.util.List;
import appeng.recipes.Ingredient;
import appeng.recipes.MissingIngredientError;
import appeng.recipes.RecipeError;
import appeng.recipes.RegistrationError;
public class CraftHandler
{
public void setup(List<List<Ingredient>> input, List<List<Ingredient>> output) throws RecipeError
{
}
public void register() throws RegistrationError, MissingIngredientError
{
}
}
+22 -1
View File
@@ -1,6 +1,27 @@
package appeng.recipes.handlers;
public class Grind extends CraftHandler
import java.util.List;
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 Grind implements ICraftHandler
{
@Override
public void setup(List<List<IIngredient>> input,
List<List<IIngredient>> output) throws RecipeError {
// TODO Auto-generated method stub
}
@Override
public void register() throws RegistrationError, MissingIngredientError {
// TODO Auto-generated method stub
}
}
+16 -8
View File
@@ -4,17 +4,19 @@ import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import appeng.recipes.Ingredient;
import appeng.recipes.MissingIngredientError;
import appeng.recipes.RegistrationError;
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 extends CraftHandler
public class OreRegistration implements ICraftHandler
{
List<Ingredient> inputs;
List<IIngredient> inputs;
String name;
public OreRegistration(List<Ingredient> in, String out) {
public OreRegistration(List<IIngredient> in, String out) {
inputs = in;
name = out;
}
@@ -22,12 +24,18 @@ public class OreRegistration extends CraftHandler
@Override
public void register() throws RegistrationError, MissingIngredientError
{
for (Ingredient i : inputs)
for (IIngredient i : inputs)
{
for (ItemStack is : i.getSet())
for (ItemStack is : i.getItemStackSet())
{
OreDictionary.registerOre( name, is );
}
}
}
@Override
public void setup(List<List<IIngredient>> input,
List<List<IIngredient>> output) throws RecipeError {
}
}
+12 -11
View File
@@ -2,24 +2,25 @@ package appeng.recipes.handlers;
import java.util.List;
import appeng.recipes.Ingredient;
import appeng.recipes.MissingIngredientError;
import appeng.recipes.RecipeError;
import appeng.recipes.RegistrationError;
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 Pureify extends CraftHandler
public class Pureify implements ICraftHandler
{
Ingredient in;
Ingredient out;
IIngredient in;
IIngredient out;
@Override
public void setup(List<List<Ingredient>> input, List<List<Ingredient>> output) throws RecipeError
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
{
List<Ingredient> inputList = input.get( 0 );
List<Ingredient> outputList = output.get( 0 );
List<IIngredient> inputList = input.get( 0 );
List<IIngredient> outputList = output.get( 0 );
if ( inputList.size() == 1 && outputList.size() == 1 )
{
in = inputList.get( 0 );
@@ -33,7 +34,7 @@ public class Pureify extends CraftHandler
@Override
public void register() throws RegistrationError, MissingIngredientError
{
if ( in.getSet() == null )
if ( in.getItemStackSet() == null )
throw new RegistrationError( in.toString() + ": Pureify Input is not a valid item." );
if ( out.getItemStack().getItem() == null )
+12 -11
View File
@@ -4,25 +4,26 @@ 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.Ingredient;
import appeng.recipes.MissingIngredientError;
import appeng.recipes.RecipeError;
import appeng.recipes.RegistrationError;
import appeng.recipes.Recipes.ShapedRecipe;
import cpw.mods.fml.common.registry.GameRegistry;
public class Shaped extends CraftHandler
public class Shaped implements ICraftHandler
{
private int rows;
private int cols;
List<List<Ingredient>> inputs;
Ingredient output;
List<List<IIngredient>> inputs;
IIngredient output;
@Override
public void setup(List<List<Ingredient>> input, List<List<Ingredient>> 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 )
{
@@ -48,20 +49,20 @@ public class Shaped extends CraftHandler
public void register() throws RegistrationError, MissingIngredientError
{
char first = 'A';
List<Object> args = new ArrayList();
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 )
if ( inputs.get( y ).get( x ).isAir() )
row = row + " ";
else
{
row = row + first;
args.add( first );
args.add( inputs.get( y ).get( x ).getSet() );
args.add( inputs.get( y ).get( x ).getItemStackSet() );
first++;
}
+12 -11
View File
@@ -4,22 +4,23 @@ 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.Ingredient;
import appeng.recipes.MissingIngredientError;
import appeng.recipes.RecipeError;
import appeng.recipes.RegistrationError;
import appeng.recipes.Recipes.ShapelessRecipe;
import cpw.mods.fml.common.registry.GameRegistry;
public class Shapeless extends CraftHandler
public class Shapeless implements ICraftHandler
{
List<Ingredient> inputs;
Ingredient output;
List<IIngredient> inputs;
IIngredient output;
@Override
public void setup(List<List<Ingredient>> input, List<List<Ingredient>> 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 )
{
@@ -38,9 +39,9 @@ public class Shapeless extends CraftHandler
@Override
public void register() throws RegistrationError, MissingIngredientError
{
List<Object> args = new ArrayList();
for (Ingredient i : inputs)
args.add( i.getSet() );
List<Object> args = new ArrayList<Object>();
for (IIngredient i : inputs)
args.add( i.getItemStackSet() );
ItemStack outIS = output.getItemStack();
+11 -10
View File
@@ -2,25 +2,26 @@ package appeng.recipes.handlers;
import java.util.List;
import appeng.recipes.Ingredient;
import appeng.recipes.MissingIngredientError;
import appeng.recipes.RecipeError;
import appeng.recipes.RegistrationError;
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 cpw.mods.fml.common.registry.GameRegistry;
public class Smelt extends CraftHandler
public class Smelt implements ICraftHandler
{
Ingredient in;
Ingredient out;
IIngredient in;
IIngredient out;
@Override
public void setup(List<List<Ingredient>> input, List<List<Ingredient>> output) throws RecipeError
public void setup(List<List<IIngredient>> input, List<List<IIngredient>> output) throws RecipeError
{
if ( input.size() == 1 && output.size() == 1 )
{
List<Ingredient> inputList = input.get( 0 );
List<Ingredient> outputList = output.get( 0 );
List<IIngredient> inputList = input.get( 0 );
List<IIngredient> outputList = output.get( 0 );
if ( inputList.size() == 1 && outputList.size() == 1 )
{
in = inputList.get( 0 );
+1 -1
View File
@@ -12,7 +12,7 @@ public class OreDictionaryHandler
public static final OreDictionaryHandler instance = new OreDictionaryHandler();
private List<IOreListener> ol = new ArrayList();
private List<IOreListener> ol = new ArrayList<IOreListener>();
/**
* Just limit what items are sent to the final listeners, I got sick of strange items showing up...