From d5748eb804dfcb6317e9478aec46d6dedd01e43e Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sun, 9 Mar 2014 21:11:29 -0500 Subject: [PATCH] Cables now work in Recipes. Added Ingredient Resolver Sets. Shrunk MC Chest Battery. --- core/features/ColoredItemDefinition.java | 9 +++ .../registries/RecipeHandlerRegistry.java | 5 +- recipes/AEItemResolver.java | 75 ++++++++++++++++-- recipes/Ingredient.java | 14 +++- recipes/IngredientSet.java | 78 +++++++++++++++++++ recipes/MissedIngredientSet.java | 15 ++++ recipes/RecipeHandler.java | 9 ++- tile/storage/TileChest.java | 2 +- 8 files changed, 191 insertions(+), 16 deletions(-) create mode 100644 recipes/IngredientSet.java create mode 100644 recipes/MissedIngredientSet.java diff --git a/core/features/ColoredItemDefinition.java b/core/features/ColoredItemDefinition.java index 8febc393..65bd9fd7 100644 --- a/core/features/ColoredItemDefinition.java +++ b/core/features/ColoredItemDefinition.java @@ -62,4 +62,13 @@ public class ColoredItemDefinition implements AEColoredItemDefinition return null; } + @Override + public ItemStack[] allStacks(int stackSize) + { + ItemStack is[] = new ItemStack[colors.length]; + for (int x = 0; x < is.length; x++) + is[x] = colors[x].stack( 1 ); + return is; + } + } diff --git a/core/features/registries/RecipeHandlerRegistry.java b/core/features/registries/RecipeHandlerRegistry.java index 99a1ebf1..7c262662 100644 --- a/core/features/registries/RecipeHandlerRegistry.java +++ b/core/features/registries/RecipeHandlerRegistry.java @@ -7,7 +7,6 @@ import appeng.api.features.IRecipeHandlerRegistry; import appeng.api.recipes.ICraftHandler; import appeng.api.recipes.IRecipeHandler; import appeng.api.recipes.ISubItemResolver; -import appeng.api.recipes.ResolveResult; import appeng.core.AELog; import appeng.recipes.RecipeHandler; @@ -55,11 +54,11 @@ public class RecipeHandlerRegistry implements IRecipeHandlerRegistry } @Override - public ResolveResult resolveItem(String nameSpace, String itemName) + public Object resolveItem(String nameSpace, String itemName) { for (ISubItemResolver sir : resolvers) { - ResolveResult rr = null; + Object rr = null; try { diff --git a/recipes/AEItemResolver.java b/recipes/AEItemResolver.java index 25387ce8..351fad93 100644 --- a/recipes/AEItemResolver.java +++ b/recipes/AEItemResolver.java @@ -1,7 +1,12 @@ package appeng.recipes; +import net.minecraft.item.ItemStack; +import appeng.api.AEApi; import appeng.api.recipes.ISubItemResolver; -import appeng.api.recipes.ResolveResult; +import appeng.api.recipes.ResolverResult; +import appeng.api.recipes.ResolverResultSet; +import appeng.api.util.AEColor; +import appeng.api.util.AEColoredItemDefinition; import appeng.core.AppEng; import appeng.items.materials.MaterialType; import appeng.items.misc.ItemCrystalSeed; @@ -12,19 +17,59 @@ public class AEItemResolver implements ISubItemResolver { @Override - public ResolveResult resolveItemByName(String nameSpace, String itemName) + public Object resolveItemByName(String nameSpace, String itemName) { if ( nameSpace.equals( AppEng.modid ) ) { + if ( itemName.equals( "CableGlass" ) ) + { + return new ResolverResultSet( "CableGlass", AEApi.instance().parts().partCableGlass.allStacks( 1 ) ); + } + + if ( itemName.startsWith( "CableGlass." ) ) + { + return cableItem( AEApi.instance().parts().partCableGlass, itemName.substring( itemName.indexOf( "." ) + 1 ) ); + } + + if ( itemName.equals( "CableCovered" ) ) + { + return new ResolverResultSet( "CableCovered", AEApi.instance().parts().partCableCovered.allStacks( 1 ) ); + } + + if ( itemName.startsWith( "CableCovered." ) ) + { + return cableItem( AEApi.instance().parts().partCableCovered, itemName.substring( itemName.indexOf( "." ) + 1 ) ); + } + + if ( itemName.equals( "CableSmart" ) ) + { + return new ResolverResultSet( "CableSmart", AEApi.instance().parts().partCableSmart.allStacks( 1 ) ); + } + + if ( itemName.startsWith( "CableSmart." ) ) + { + return cableItem( AEApi.instance().parts().partCableSmart, itemName.substring( itemName.indexOf( "." ) + 1 ) ); + } + + if ( itemName.equals( "CableDense" ) ) + { + return new ResolverResultSet( "CableDense", AEApi.instance().parts().partCableDense.allStacks( 1 ) ); + } + + if ( itemName.startsWith( "CableDense." ) ) + { + return cableItem( AEApi.instance().parts().partCableDense, itemName.substring( itemName.indexOf( "." ) + 1 ) ); + } + if ( itemName.startsWith( "ItemCrystalSeed." ) ) { if ( itemName.equalsIgnoreCase( "ItemCrystalSeed.Certus" ) ) - return new ResolveResult( "ItemCrystalSeed", ItemCrystalSeed.Certus ); + return new ResolverResult( "ItemCrystalSeed", ItemCrystalSeed.Certus ); if ( itemName.equalsIgnoreCase( "ItemCrystalSeed.Nether" ) ) - return new ResolveResult( "ItemCrystalSeed", ItemCrystalSeed.Nether ); + return new ResolverResult( "ItemCrystalSeed", ItemCrystalSeed.Nether ); if ( itemName.equalsIgnoreCase( "ItemCrystalSeed.Fluix" ) ) - return new ResolveResult( "ItemCrystalSeed", ItemCrystalSeed.Fluix ); + return new ResolverResult( "ItemCrystalSeed", ItemCrystalSeed.Fluix ); return null; } @@ -34,7 +79,7 @@ public class AEItemResolver implements ISubItemResolver String materialName = itemName.substring( itemName.indexOf( "." ) + 1 ); MaterialType mt = MaterialType.valueOf( materialName ); itemName = itemName.substring( 0, itemName.indexOf( "." ) ); - return new ResolveResult( itemName, mt.damageValue ); + return new ResolverResult( itemName, mt.damageValue ); } if ( itemName.startsWith( "ItemPart." ) ) @@ -42,11 +87,27 @@ public class AEItemResolver implements ISubItemResolver String partName = itemName.substring( itemName.indexOf( "." ) + 1 ); PartType pt = PartType.valueOf( partName ); itemName = itemName.substring( 0, itemName.indexOf( "." ) ); - return new ResolveResult( itemName, ItemPart.instance.getDamageByType( pt ) ); + return new ResolverResult( itemName, ItemPart.instance.getDamageByType( pt ) ); } } return null; } + private Object cableItem(AEColoredItemDefinition partType, String substring) + { + AEColor col = AEColor.Transparent; + + try + { + col = AEColor.valueOf( substring ); + } + catch (Throwable t) + { + col = AEColor.Transparent; + } + + ItemStack is = partType.stack( col, 1 ); + return new ResolverResult( "ItemPart", is.getItemDamage() ); + } } diff --git a/recipes/Ingredient.java b/recipes/Ingredient.java index 6465bd9f..df76c235 100644 --- a/recipes/Ingredient.java +++ b/recipes/Ingredient.java @@ -11,7 +11,8 @@ import appeng.api.exceptions.MissingIngredientError; import appeng.api.exceptions.RecipeError; import appeng.api.exceptions.RegistrationError; import appeng.api.recipes.IIngredient; -import appeng.api.recipes.ResolveResult; +import appeng.api.recipes.ResolverResult; +import appeng.api.recipes.ResolverResultSet; import cpw.mods.fml.common.registry.GameRegistry; public class Ingredient implements IIngredient @@ -25,7 +26,7 @@ public class Ingredient implements IIngredient final public int qty; - public Ingredient(RecipeHandler handler, String input, int qty) throws RecipeError { + public Ingredient(RecipeHandler handler, String input, int qty) throws RecipeError, MissedIngredientSet { // works no matter wat! this.qty = qty; @@ -60,12 +61,17 @@ public class Ingredient implements IIngredient { try { - ResolveResult rr = AEApi.instance().registries().recipes().resolveItem( nameSpace, tmpName ); - if ( rr != null ) + Object ro = AEApi.instance().registries().recipes().resolveItem( nameSpace, tmpName ); + if ( ro instanceof ResolverResult ) { + ResolverResult rr = (ResolverResult) ro; tmpName = rr.itemName; sel = rr.damageValue; } + else if ( ro instanceof ResolverResultSet ) + { + throw new MissedIngredientSet( (ResolverResultSet) ro ); + } } catch (IllegalArgumentException e) { diff --git a/recipes/IngredientSet.java b/recipes/IngredientSet.java new file mode 100644 index 00000000..7e384812 --- /dev/null +++ b/recipes/IngredientSet.java @@ -0,0 +1,78 @@ +package appeng.recipes; + +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; +import appeng.api.exceptions.MissingIngredientError; +import appeng.api.exceptions.RegistrationError; +import appeng.api.recipes.IIngredient; +import appeng.api.recipes.ResolverResultSet; + +public class IngredientSet implements IIngredient +{ + + int qty = 0; + final String name; + final List items; + + public IngredientSet(ResolverResultSet rr) { + name = rr.name; + items = rr.results; + } + + boolean isInside = false; + + public int getDamageValue() + { + return OreDictionary.WILDCARD_VALUE; + } + + @Override + public String getItemName() + { + return name; + } + + @Override + public ItemStack getItemStack() throws RegistrationError, MissingIngredientError + { + throw new RegistrationError( "Cannot pass group of items to a recipe which desires a single recipe item." ); + } + + @Override + public ItemStack[] getItemStackSet() throws RegistrationError, MissingIngredientError + { + if ( isInside ) + return new ItemStack[0]; + + List out = new LinkedList(); + out.addAll( items ); + + if ( out.size() == 0 ) + throw new MissingIngredientError( toString() + " - group could not be resolved to any items." ); + + for (ItemStack is : out) + is.stackSize = qty; + + return out.toArray( new ItemStack[out.size()] ); + } + + public String getNameSpace() + { + return ""; + } + + @Override + public int getQty() + { + return 0; + } + + @Override + public boolean isAir() + { + return false; + } +} diff --git a/recipes/MissedIngredientSet.java b/recipes/MissedIngredientSet.java new file mode 100644 index 00000000..9290c72f --- /dev/null +++ b/recipes/MissedIngredientSet.java @@ -0,0 +1,15 @@ +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) { + rrs = ro; + } + +} diff --git a/recipes/RecipeHandler.java b/recipes/RecipeHandler.java index 2ad5f9a0..e82ac287 100644 --- a/recipes/RecipeHandler.java +++ b/recipes/RecipeHandler.java @@ -539,7 +539,14 @@ public class RecipeHandler implements IRecipeHandler return gi.copy( qty ); data.knownItem.add( v ); - return new Ingredient( this, v, qty ); + try + { + return new Ingredient( this, v, qty ); + } + catch (MissedIngredientSet grp) + { + return new IngredientSet( grp.rrs ); + } } private boolean isNumber(String v) diff --git a/tile/storage/TileChest.java b/tile/storage/TileChest.java index 2a367782..9c0b45f5 100644 --- a/tile/storage/TileChest.java +++ b/tile/storage/TileChest.java @@ -252,9 +252,9 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan } public TileChest() { + internalMaxPower = PowerMultiplier.CONFIG.multiply( 40 ); gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL ); addNewHandler( new invManger() ); - config.registerSetting( Settings.SORT_BY, SortOrder.NAME ); config.registerSetting( Settings.VIEW_MODE, ViewItems.ALL ); config.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );