From 4a87ceac4fab84e46fc9dd7cb497ec57362f763b Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sun, 9 Feb 2014 21:16:36 -0600 Subject: [PATCH] Recipe Engine Added, not quite done yet tho. --- core/Registration.java | 7 + items/materials/ItemMaterial.java | 3 + items/parts/ItemPart.java | 13 ++ recipes/AEShapedOreRecipe.java | 13 -- recipes/AEShapedQuartzRecipe.java | 286 ----------------------------- recipes/AEShapelessOreRecipe.java | 12 -- recipes/Ingredient.java | 129 +++++++++++++ recipes/Recipe.java | 36 ---- recipes/RecipeHandler.java | 212 +++++++++++++++++++++ recipes/RecipeItem.java | 36 ---- recipes/RecipeParser.java | 7 - recipes/RecipeType.java | 51 ----- recipes/RegistrationError.java | 12 ++ recipes/handlers/CraftHandler.java | 20 ++ recipes/handlers/Grind.java | 6 + recipes/handlers/Shaped.java | 46 +++++ recipes/handlers/Shapeless.java | 37 ++++ recipes/handlers/Smelt.java | 45 +++++ 18 files changed, 530 insertions(+), 441 deletions(-) delete mode 100644 recipes/AEShapedOreRecipe.java delete mode 100644 recipes/AEShapedQuartzRecipe.java delete mode 100644 recipes/AEShapelessOreRecipe.java create mode 100644 recipes/Ingredient.java delete mode 100644 recipes/Recipe.java create mode 100644 recipes/RecipeHandler.java delete mode 100644 recipes/RecipeItem.java delete mode 100644 recipes/RecipeParser.java delete mode 100644 recipes/RecipeType.java create mode 100644 recipes/RegistrationError.java create mode 100644 recipes/handlers/CraftHandler.java create mode 100644 recipes/handlers/Grind.java create mode 100644 recipes/handlers/Shaped.java create mode 100644 recipes/handlers/Shapeless.java create mode 100644 recipes/handlers/Smelt.java diff --git a/core/Registration.java b/core/Registration.java index db40aa76..42d8d8a7 100644 --- a/core/Registration.java +++ b/core/Registration.java @@ -108,6 +108,7 @@ import appeng.me.cache.SecurityCache; import appeng.me.cache.SpatialPylonCache; import appeng.me.cache.TickManagerCache; import appeng.me.storage.AEExternalHandler; +import appeng.recipes.RecipeHandler; import appeng.recipes.ores.OreDictionaryHandler; import com.google.common.collect.ArrayListMultimap; @@ -125,9 +126,11 @@ public class Registration final public static Registration instance = new Registration(); + public RecipeHandler recipeHandler; public BiomeGenBase storageBiome; private Registration() { + recipeHandler = new RecipeHandler(); } final private Multimap featuresToEntities = ArrayListMultimap.create(); @@ -304,6 +307,7 @@ public class Registration addFeature( ToolReplicatorCard.class ); addFeature( BlockItemGen.class ); addFeature( BlockChunkloader.class ); + } private AEItemDefinition addFeature(Class c, Object... Args) @@ -398,6 +402,8 @@ public class Registration public void Init(FMLInitializationEvent event) { + recipeHandler.parseRecipes( "" ); + IPartHelper ph = AEApi.instance().partHelper(); ph.registerNewLayer( "appeng.api.parts.layers.LayerIEnergySink", "ic2.api.energy.tile.IEnergySink" ); ph.registerNewLayer( "appeng.api.parts.layers.LayerISidedInventory", "net.minecraft.inventory.ISidedInventory" ); @@ -501,5 +507,6 @@ public class Registration if ( AEConfig.instance.isFeatureEnabled( AEFeature.CertusQuartzWorldGen ) ) GameRegistry.registerWorldGenerator( new QuartzWorldGen(), 0 ); + recipeHandler.registerHandlers(); } } diff --git a/items/materials/ItemMaterial.java b/items/materials/ItemMaterial.java index 11fb9df2..0bf1b23d 100644 --- a/items/materials/ItemMaterial.java +++ b/items/materials/ItemMaterial.java @@ -36,10 +36,13 @@ public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgr HashMap dmgToMaterial = new HashMap(); + public static ItemMaterial instance; + public ItemMaterial() { super( ItemMaterial.class ); setfeature( EnumSet.of( AEFeature.Core ) ); setHasSubtypes( true ); + instance = this; } class SlightlyBetterSort implements Comparator diff --git a/items/parts/ItemPart.java b/items/parts/ItemPart.java index 18513d65..d12027dd 100644 --- a/items/parts/ItemPart.java +++ b/items/parts/ItemPart.java @@ -41,11 +41,14 @@ public class ItemPart extends AEBaseItem implements IPartItem, IItemGroup HashMap dmgToPart = new HashMap(); + public static ItemPart instance; + public ItemPart() { super( ItemPart.class ); setfeature( EnumSet.of( AEFeature.Core ) ); AEApi.instance().partHelper().setItemBusRenderer( this ); setHasSubtypes( true ); + instance = this; } public ItemStackSrc createPart(PartType mat, Enum varient) @@ -91,6 +94,16 @@ public class ItemPart extends AEBaseItem implements IPartItem, IItemGroup return null; } + public int getDamageByType(PartType t) + { + for (Entry pt : dmgToPart.entrySet()) + { + if ( pt.getValue().part == t ) + return pt.getKey(); + } + return -1; + } + public PartType getTypeByStack(ItemStack is) { if ( is == null ) diff --git a/recipes/AEShapedOreRecipe.java b/recipes/AEShapedOreRecipe.java deleted file mode 100644 index b7e7ce92..00000000 --- a/recipes/AEShapedOreRecipe.java +++ /dev/null @@ -1,13 +0,0 @@ -package appeng.recipes; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.ShapedOreRecipe; - -public class AEShapedOreRecipe extends ShapedOreRecipe -{ - - public AEShapedOreRecipe(ItemStack result, Object... recipe) { - super( result, recipe ); - - } -} diff --git a/recipes/AEShapedQuartzRecipe.java b/recipes/AEShapedQuartzRecipe.java deleted file mode 100644 index 88a501c1..00000000 --- a/recipes/AEShapedQuartzRecipe.java +++ /dev/null @@ -1,286 +0,0 @@ -package appeng.recipes; - -import java.util.ArrayList; -import java.util.HashMap; - -import net.minecraft.block.Block; -import net.minecraft.init.Items; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.world.World; -import net.minecraftforge.oredict.OreDictionary; -import appeng.api.AEApi; - -/* - * Basically the ore dictionary crafting recipe, with a slight twist - * of adding quartz to the lists even tho they are not in the ore dictionary. - * - * Yes this is silly, but it seemed simpler then re-writing half the class to make a simple alteration. - */ - -public class AEShapedQuartzRecipe implements IRecipe -{ - - // Added in for future ease of change, but hard coded for now. - private static final int MAX_CRAFT_GRID_WIDTH = 3; - private static final int MAX_CRAFT_GRID_HEIGHT = 3; - - private ItemStack output = null; - private Object[] input = null; - private int width = 0; - private int height = 0; - private boolean mirrored = true; - - public int getWidth() - { - return width; - } - - public int getHeight() - { - return height; - } - - public Object[] getIngredients() - { - return input; - } - - public AEShapedQuartzRecipe(ItemStack result, boolean dust, Object... recipe) { - output = result.copy(); - - String shape = ""; - int idx = 0; - - if ( recipe[idx] instanceof Boolean ) - { - mirrored = (Boolean) recipe[idx]; - if ( recipe[idx + 1] instanceof Object[] ) - { - recipe = (Object[]) recipe[idx + 1]; - } - else - { - idx = 1; - } - } - - if ( recipe[idx] instanceof String[] ) - { - String[] parts = ((String[]) recipe[idx++]); - - for (String s : parts) - { - width = s.length(); - shape += s; - } - - height = parts.length; - } - else - { - while (recipe[idx] instanceof String) - { - String s = (String) recipe[idx++]; - shape += s; - width = s.length(); - height++; - } - } - - if ( width * height != shape.length() ) - { - String ret = "Invalid shaped ore recipe: "; - for (Object tmp : recipe) - { - ret += tmp + ", "; - } - ret += output; - throw new RuntimeException( ret ); - } - - HashMap itemMap = new HashMap(); - - for (; idx < recipe.length; idx += 2) - { - Character chr = (Character) recipe[idx]; - Object in = recipe[idx + 1]; - - if ( in instanceof ItemStack ) - { - itemMap.put( chr, ((ItemStack) in).copy() ); - } - else if ( in instanceof Item ) - { - itemMap.put( chr, new ItemStack( (Item) in ) ); - } - else if ( in instanceof Block ) - { - itemMap.put( chr, new ItemStack( (Block) in, 1, OreDictionary.WILDCARD_VALUE ) ); - } - else if ( in instanceof String ) - { - ArrayList is = OreDictionary.getOres( (String) in ); - ArrayList copy = new ArrayList(); - copy.addAll( is ); - - if ( in.equals( "crystalQuartz" ) || in.equals( "dustQuartz" ) ) - { - if ( dust ) - { - copy.add( AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ) ); - copy.add( AEApi.instance().materials().materialNetherQuartzDust.stack( 1 ) ); - } - else - { - copy.add( AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ) ); - copy.add( new ItemStack( Items.quartz ) ); - } - } - - itemMap.put( chr, copy ); - } - else - { - String ret = "Invalid shaped ore recipe: "; - for (Object tmp : recipe) - { - ret += tmp + ", "; - } - ret += output; - throw new RuntimeException( ret ); - } - } - - input = new Object[width * height]; - int x = 0; - for (char chr : shape.toCharArray()) - { - input[x++] = itemMap.get( chr ); - } - } - - @Override - public ItemStack getCraftingResult(InventoryCrafting var1) - { - return output.copy(); - } - - @Override - public int getRecipeSize() - { - return input.length; - } - - @Override - public ItemStack getRecipeOutput() - { - return output; - } - - @Override - public boolean matches(InventoryCrafting inv, World world) - { - for (int x = 0; x <= MAX_CRAFT_GRID_WIDTH - width; x++) - { - for (int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - height; ++y) - { - if ( checkMatch( inv, x, y, false ) ) - { - return true; - } - - if ( mirrored && checkMatch( inv, x, y, true ) ) - { - return true; - } - } - } - - return false; - } - - private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror) - { - for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++) - { - for (int y = 0; y < MAX_CRAFT_GRID_HEIGHT; y++) - { - int subX = x - startX; - int subY = y - startY; - Object target = null; - - if ( subX >= 0 && subY >= 0 && subX < width && subY < height ) - { - if ( mirror ) - { - target = input[width - subX - 1 + subY * width]; - } - else - { - target = input[subX + subY * width]; - } - } - - ItemStack slot = inv.getStackInRowAndColumn( x, y ); - - if ( target instanceof ItemStack ) - { - if ( !checkItemEquals( (ItemStack) target, slot ) ) - { - return false; - } - } - else if ( target instanceof ArrayList ) - { - boolean matched = false; - - for (ItemStack item : (ArrayList) target) - { - matched = matched || checkItemEquals( item, slot ); - } - - if ( !matched ) - { - return false; - } - } - else if ( target == null && slot != null ) - { - return false; - } - } - } - - return true; - } - - private boolean checkItemEquals(ItemStack target, ItemStack input) - { - if ( input == null && target != null || input != null && target == null ) - { - return false; - } - return (target.getItem() == input.getItem() && (target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input - .getItemDamage())); - } - - public AEShapedQuartzRecipe setMirrored(boolean mirror) - { - mirrored = mirror; - return this; - } - - /** - * Returns the input for this recipe, any mod accessing this value should never manipulate the values in this array - * as it will effect the recipe itself. - * - * @return The recipes input vales. - */ - public Object[] getInput() - { - return this.input; - } -} diff --git a/recipes/AEShapelessOreRecipe.java b/recipes/AEShapelessOreRecipe.java deleted file mode 100644 index c1528173..00000000 --- a/recipes/AEShapelessOreRecipe.java +++ /dev/null @@ -1,12 +0,0 @@ -package appeng.recipes; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.ShapelessOreRecipe; - -public class AEShapelessOreRecipe extends ShapelessOreRecipe -{ - - public AEShapelessOreRecipe(ItemStack output, Object... t) { - super( output, t ); - } -} diff --git a/recipes/Ingredient.java b/recipes/Ingredient.java new file mode 100644 index 00000000..6f596c23 --- /dev/null +++ b/recipes/Ingredient.java @@ -0,0 +1,129 @@ +package appeng.recipes; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; +import appeng.core.AppEng; +import appeng.items.materials.MaterialType; +import appeng.items.parts.ItemPart; +import appeng.items.parts.PartType; + +public class Ingredient +{ + + final public boolean isAir; + + final public String nameSpace; + final public String itemName; + final public int meta; + + public Ingredient(RecipeHandler handler, String input) throws RecipeError { + + if ( input.equals( "_" ) ) + { + isAir = true; + nameSpace = ""; + itemName = ""; + meta = OreDictionary.WILDCARD_VALUE; + return; + } + + isAir = false; + String[] parts = input.split( ":" ); + if ( parts.length >= 2 ) + { + nameSpace = handler.alias( parts[0] ); + String tmpName = handler.alias( parts[1] ); + + if ( parts.length != 3 ) + { + int sel = 0; + + if ( nameSpace.equals( "oreDictionary" ) ) + { + if ( parts.length == 3 ) + throw new RecipeError( "Cannot specify meta when using ore dictionary." ); + sel = OreDictionary.WILDCARD_VALUE; + } + else if ( nameSpace.equals( AppEng.modid ) ) + { + try + { + if ( tmpName.startsWith( "ItemMaterial." ) ) + { + String materialName = tmpName.substring( tmpName.indexOf( "." ) + 1 ); + MaterialType mt = MaterialType.valueOf( materialName ); + tmpName = tmpName.substring( 0, tmpName.indexOf( "." ) ); + sel = mt.damageValue; + } + + if ( tmpName.startsWith( "ItemPart." ) ) + { + String partName = tmpName.substring( tmpName.indexOf( "." ) + 1 ); + PartType pt = PartType.valueOf( partName ); + tmpName = tmpName.substring( 0, tmpName.indexOf( "." ) ); + sel = ItemPart.instance.getDamageByType( pt ); + } + } + catch (IllegalArgumentException e) + { + throw new RecipeError( tmpName + " is not a valid ae2 item defintion." ); + } + } + + meta = sel; + } + else + { + if ( parts[2].equals( "*" ) ) + { + meta = OreDictionary.WILDCARD_VALUE; + } + else + { + try + { + meta = Integer.parseInt( parts[2] ); + } + catch (NumberFormatException e) + { + throw new RecipeError( "Invalid Metadata." ); + } + } + } + itemName = tmpName; + } + else + throw new RecipeError( input + " : Needs at least Namespace and Name." ); + } + + public ItemStack getItemStack() throws RegistrationError + { + if ( isAir ) + throw new RegistrationError( "Found blank item and expected a real item." ); + + Object o = Item.itemRegistry.getObject( nameSpace + ":" + itemName ); + if ( o instanceof Item ) + return new ItemStack( (Item) o, 1, meta ); + if ( o instanceof Block ) + return new ItemStack( (Block) o, 1, meta ); + + o = Item.itemRegistry.getObject( nameSpace + ":item." + itemName ); + if ( o instanceof Item ) + return new ItemStack( (Item) o, 1, meta ); + + o = Item.itemRegistry.getObject( nameSpace + ":tile." + itemName ); + if ( o instanceof Block ) + return new ItemStack( (Block) o, 1, meta ); + + throw new RegistrationError( "Unable to find item: " + toString() ); + } + + @Override + public String toString() + { + return nameSpace + ":" + itemName + ":" + meta; + } + +} diff --git a/recipes/Recipe.java b/recipes/Recipe.java deleted file mode 100644 index 359e4556..00000000 --- a/recipes/Recipe.java +++ /dev/null @@ -1,36 +0,0 @@ -package appeng.recipes; - -import java.util.Iterator; - -public class Recipe -{ - - final int size; - final RecipeType type; - final RecipeItem items[]; - - public Recipe(RecipeType rt, Iterator ilist) throws RecipeError { - type = rt; - items = new RecipeItem[rt.getSize()]; - - int itemCount = 0; - while (itemCount < rt.getSize() && ilist.hasNext()) - { - items[itemCount++] = ilist.next(); - } - - if ( ilist.hasNext() ) - throw new RecipeError( "Invalid Number of Items in recipe." ); - - if ( rt.isShaped() ) - { - if ( itemCount != rt.getSize() ) - throw new RecipeError( "Invalid Number of Items in recipe." ); - - size = rt.getSize(); - } - else - size = itemCount; - } - -} diff --git a/recipes/RecipeHandler.java b/recipes/RecipeHandler.java new file mode 100644 index 00000000..899dc405 --- /dev/null +++ b/recipes/RecipeHandler.java @@ -0,0 +1,212 @@ +package appeng.recipes; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +import appeng.core.AELog; +import appeng.recipes.handlers.CraftHandler; +import appeng.recipes.handlers.Grind; +import appeng.recipes.handlers.Shaped; +import appeng.recipes.handlers.Smelt; + +public class RecipeHandler +{ + + HashMap aliases = new HashMap(); + List Handlers = new LinkedList(); + + private void addCrafting(CraftHandler ch) + { + Handlers.add( ch ); + } + + public void registerHandlers() + { + for (CraftHandler ch : Handlers) + { + try + { + ch.register(); + } + catch (RegistrationError e) + { + AELog.warning( "Unable to regsiter a recipe." ); + AELog.error( e ); + } + } + } + + public String alias(String in) + { + String out = aliases.get( in ); + + if ( out != null ) + return out; + + return in; + } + + List tokens = new LinkedList(); + + public void parseRecipes(String file) + { + file = org.apache.commons.lang3.StringUtils.join( new String[] { "", "alias=", " mc", " -> minecraft", "", "alias=", " ae2", " -> appliedenergistics2", + "", "smelt=", " ae2:ItemMaterial.IronDust", " -> mc:iron_ingot", "", "smelt=", " ae2:ItemMaterial.GoldDust", " -> mc:gold_ingot", "", "craft=", + " mc:stick mc:stick mc:stick,", " _ _ mc:stick,", " _ _ mc:stick", " -> ae2:BlockGrinder", "" }, "\n" ); + + int len = file.length(); + + boolean inQuote = false; + + String token = ""; + int line = 0; + + for (int x = 0; x < len; x++) + { + char c = file.charAt( x ); + + if ( c == '\n' ) + line++; + + if ( inQuote ) + { + switch (c) + { + case '"': + inQuote = !inQuote; + break; + default: + token = token + c; + } + } + else + { + switch (c) + { + case '"': + inQuote = !inQuote; + break; + case ',': + + if ( token.length() > 0 ) + { + tokens.add( token ); + tokens.add( "," ); + } + token = ""; + break; + + case '=': + + processTokens( line ); + + if ( token.length() > 0 ) + tokens.add( token ); + token = ""; + + break; + + case '\n': + case '\t': + case '\r': + case ' ': + + if ( token.length() > 0 ) + tokens.add( token ); + token = ""; + + break; + default: + token = token + c; + } + } + + } + processTokens( line ); + + } + + private void processTokens(int line) + { + try + { + if ( tokens.isEmpty() ) + return; + + int split = tokens.indexOf( "->" ); + if ( split != -1 ) + { + String operation = tokens.remove( 0 ); + + if ( operation.equals( "alias" ) ) + { + if ( tokens.size() == 3 && tokens.indexOf( "->" ) == 1 ) + aliases.put( tokens.get( 0 ), tokens.get( 2 ) ); + else + throw new RecipeError( "Alias must have exactly 1 input and 1 output." ); + } + else + { + List pre = tokens.subList( 0, split - 1 ); + List post = tokens.subList( split, tokens.size() ); + + List> inputs = parseLines( pre ); + List> outputs = parseLines( post ); + + CraftHandler ch = null; + + if ( operation.equals( "shaped" ) ) + ch = new Shaped(); + else if ( operation.equals( "smelt" ) ) + ch = new Smelt(); + else if ( operation.equals( "grind" ) ) + ch = new Grind(); + + if ( ch != null ) + { + ch.setup( inputs, outputs ); + addCrafting( ch ); + } + else + throw new RecipeError( "Invalid crafting type: " + operation ); + } + } + else + throw new RecipeError( tokens.toString() + "; recipe without an output." ); + + } + catch (RecipeError e) + { + AELog.warning( "Recipe Error near line:" + line + " with: " + tokens.toString() ); + AELog.error( e ); + } + + tokens.clear(); + } + + private List> parseLines(List subList) throws RecipeError + { + List> out = new LinkedList>(); + List cList = new LinkedList(); + + for (String v : subList) + { + if ( v.equals( "," ) ) + { + if ( !cList.isEmpty() ) + out.add( cList ); + cList = new LinkedList(); + } + else + { + cList.add( new Ingredient( this, v ) ); + } + } + + if ( !cList.isEmpty() ) + out.add( cList ); + + return out; + } +} diff --git a/recipes/RecipeItem.java b/recipes/RecipeItem.java deleted file mode 100644 index 8a35520d..00000000 --- a/recipes/RecipeItem.java +++ /dev/null @@ -1,36 +0,0 @@ -package appeng.recipes; - -import java.util.List; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; - -public class RecipeItem -{ - - final private ItemStack is[]; - final private int oreID; - - RecipeItem(ItemStack in) { - oreID = -1; - is = new ItemStack[1]; - is[0] = in; - } - - RecipeItem(String oreName) { - oreID = OreDictionary.getOreID( oreName ); - List ores = OreDictionary.getOres( oreID ); - is = ores.toArray( new ItemStack[ores.size()] ); - } - - int getOreID() - { - return oreID; - } - - ItemStack[] getValidItems() - { - return is; - } - -} diff --git a/recipes/RecipeParser.java b/recipes/RecipeParser.java deleted file mode 100644 index d9a4deff..00000000 --- a/recipes/RecipeParser.java +++ /dev/null @@ -1,7 +0,0 @@ -package appeng.recipes; - - -public class RecipeParser -{ - -} diff --git a/recipes/RecipeType.java b/recipes/RecipeType.java deleted file mode 100644 index 14d4c5ee..00000000 --- a/recipes/RecipeType.java +++ /dev/null @@ -1,51 +0,0 @@ -package appeng.recipes; - -public enum RecipeType -{ - // Shapeless - Shape0x0, - // Shaped 1x1 - Shape1x1(1, 1), - // Shaped 2x2 - Shape1x2(1, 2), Shape2x1(2, 1), Shape2x2(2, 2), - // Shaped 3x3 - Shape2x3(2, 3), Shape3x2(3, 2), Shape3x3(3, 3); - - boolean shapeless; - final int width; - final int height; - final int size; - - private RecipeType(int w, int h) { - width = w; - height = h; - size = w * h; - shapeless = false; - } - - private RecipeType() { - this( 3, 3 ); - shapeless = true; - } - - public boolean isShaped() - { - return shapeless; - } - - public int getWidth() - { - return width; - } - - public int getHeight() - { - return height; - } - - public int getSize() - { - return size; - } - -} diff --git a/recipes/RegistrationError.java b/recipes/RegistrationError.java new file mode 100644 index 00000000..5cfccc8d --- /dev/null +++ b/recipes/RegistrationError.java @@ -0,0 +1,12 @@ +package appeng.recipes; + +public class RegistrationError extends Exception +{ + + private static final long serialVersionUID = -6602870588617670263L; + + public RegistrationError(String n) { + super( n ); + } + +} diff --git a/recipes/handlers/CraftHandler.java b/recipes/handlers/CraftHandler.java new file mode 100644 index 00000000..cc1733fd --- /dev/null +++ b/recipes/handlers/CraftHandler.java @@ -0,0 +1,20 @@ +package appeng.recipes.handlers; + +import java.util.List; + +import appeng.recipes.Ingredient; +import appeng.recipes.RecipeError; +import appeng.recipes.RegistrationError; + +public class CraftHandler +{ + + public void setup(List> input, List> output) throws RecipeError + { + } + + public void register() throws RegistrationError + { + } + +} diff --git a/recipes/handlers/Grind.java b/recipes/handlers/Grind.java new file mode 100644 index 00000000..58ea29cc --- /dev/null +++ b/recipes/handlers/Grind.java @@ -0,0 +1,6 @@ +package appeng.recipes.handlers; + +public class Grind extends CraftHandler +{ + +} diff --git a/recipes/handlers/Shaped.java b/recipes/handlers/Shaped.java new file mode 100644 index 00000000..2e695ed7 --- /dev/null +++ b/recipes/handlers/Shaped.java @@ -0,0 +1,46 @@ +package appeng.recipes.handlers; + +import java.util.List; + +import appeng.recipes.Ingredient; +import appeng.recipes.RecipeError; +import appeng.recipes.RegistrationError; + +public class Shaped extends CraftHandler +{ + + private int rows; + private int cols; + + List> inputs; + Ingredient output; + + @Override + public void setup(List> input, List> output) throws RecipeError + { + if ( output.size() == 1 && output.get( 0 ).size() == 1 ) + { + rows = inputs.size(); + if ( rows > 0 && inputs.size() <= 3 ) + { + cols = inputs.get( 0 ).size(); + for (int x = 0; x < inputs.size(); x++) + if ( inputs.get( x ).size() != cols ) + throw new RecipeError( "all rows in a shaped crafting recipe must contain the same number of ingredients." ); + + inputs = input; + this.output = output.get( 0 ).get( 0 ); + } + else + throw new RecipeError( "shaped crafting recpies must have 1-3 rows." ); + } + else + throw new RecipeError( "Crafting must produce a single output." ); + } + + @Override + public void register() throws RegistrationError + { + + } +} diff --git a/recipes/handlers/Shapeless.java b/recipes/handlers/Shapeless.java new file mode 100644 index 00000000..0505698d --- /dev/null +++ b/recipes/handlers/Shapeless.java @@ -0,0 +1,37 @@ +package appeng.recipes.handlers; + +import java.util.List; + +import appeng.recipes.Ingredient; +import appeng.recipes.RecipeError; +import appeng.recipes.RegistrationError; + +public class Shapeless extends CraftHandler +{ + + List inputs; + Ingredient output; + + @Override + public void setup(List> input, List> output) throws RecipeError + { + if ( output.size() == 1 && output.get( 0 ).size() == 1 ) + { + if ( inputs.size() == 1 ) + { + inputs = input.get( 0 ); + this.output = output.get( 0 ).get( 0 ); + } + else + throw new RecipeError( "Shapeless crafting recipes cannot have rows." ); + } + else + throw new RecipeError( "Crafting must produce a single output." ); + } + + @Override + public void register() throws RegistrationError + { + + } +} diff --git a/recipes/handlers/Smelt.java b/recipes/handlers/Smelt.java new file mode 100644 index 00000000..12f7c586 --- /dev/null +++ b/recipes/handlers/Smelt.java @@ -0,0 +1,45 @@ +package appeng.recipes.handlers; + +import java.util.List; + +import appeng.recipes.Ingredient; +import appeng.recipes.RecipeError; +import appeng.recipes.RegistrationError; +import cpw.mods.fml.common.registry.GameRegistry; + +public class Smelt extends CraftHandler +{ + + Ingredient in; + Ingredient out; + + @Override + public void setup(List> input, List> output) throws RecipeError + { + if ( input.size() == 1 && output.size() == 1 ) + { + List inputList = input.get( 0 ); + List outputList = output.get( 0 ); + if ( inputList.size() == 1 && outputList.size() == 1 ) + { + in = inputList.get( 0 ); + out = outputList.get( 0 ); + return; + } + } + throw new RecipeError( "Smelting recipe can only have a single input and output." ); + } + + @Override + public void register() throws RegistrationError + { + if ( in.getItemStack().getItem() == null ) + throw new RegistrationError( in.toString() + ": Smelting Input is not a valid item." ); + + if ( out.getItemStack().getItem() == null ) + throw new RegistrationError( out.toString() + ": Smelting Output is not a valid item." ); + + GameRegistry.addSmelting( in.getItemStack(), out.getItemStack(), 0 ); + } + +}