diff --git a/src/main/java/appeng/recipes/GroupIngredient.java b/src/main/java/appeng/recipes/GroupIngredient.java index e11a2298..f70abc16 100644 --- a/src/main/java/appeng/recipes/GroupIngredient.java +++ b/src/main/java/appeng/recipes/GroupIngredient.java @@ -23,6 +23,8 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.List; +import com.google.common.base.Preconditions; + import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; import appeng.api.exceptions.MissingIngredientError; @@ -34,16 +36,22 @@ import appeng.api.recipes.IIngredient; public class GroupIngredient implements IIngredient { - final String name; - final List ingredients; - int qty = 0; - ItemStack[] baked; + private final String name; + private final List ingredients; + private final int qty; + private ItemStack[] baked; boolean isInside = false; - public GroupIngredient( String myName, List ingredients ) throws RecipeError + public GroupIngredient( String myName, List ingredients, int qty ) throws RecipeError { + Preconditions.checkNotNull( myName ); + Preconditions.checkNotNull( ingredients ); + Preconditions.checkState( !ingredients.isEmpty() ); + Preconditions.checkState( qty > 0 ); + this.name = myName; + this.qty = qty; for( IIngredient ingredient : ingredients ) { @@ -58,9 +66,8 @@ public class GroupIngredient implements IIngredient public IIngredient copy( int qty ) throws RecipeError { - GroupIngredient gi = new GroupIngredient( this.name, this.ingredients ); - gi.qty = qty; - return gi; + Preconditions.checkState( qty > 0 ); + return new GroupIngredient( this.name, this.ingredients, qty ); } @Override @@ -143,7 +150,7 @@ public class GroupIngredient implements IIngredient @Override public int getQty() { - return 0; + return this.qty; } @Override diff --git a/src/main/java/appeng/recipes/Ingredient.java b/src/main/java/appeng/recipes/Ingredient.java index 3361ce74..dcb27a04 100644 --- a/src/main/java/appeng/recipes/Ingredient.java +++ b/src/main/java/appeng/recipes/Ingredient.java @@ -21,6 +21,8 @@ package appeng.recipes; import java.util.List; +import com.google.common.base.Preconditions; + import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -39,17 +41,19 @@ import appeng.api.recipes.ResolverResultSet; public class Ingredient implements IIngredient { - public final boolean isAir; - - public final String nameSpace; - public final String itemName; - public final int meta; - public final int qty; - NBTTagCompound nbt = null; - ItemStack[] baked; + private final boolean isAir; + private final String nameSpace; + private final String itemName; + private final int meta; + private final int qty; + private NBTTagCompound nbt = null; + private ItemStack[] baked; public Ingredient( RecipeHandler handler, String input, int qty ) throws RecipeError, MissedIngredientSet { + Preconditions.checkNotNull( handler ); + Preconditions.checkNotNull( input ); + Preconditions.checkState( qty > 0 ); // works no matter wat! this.qty = qty; @@ -132,7 +136,7 @@ public class Ingredient implements IIngredient throw new RecipeError( input + " : Needs at least Namespace and Name." ); } - handler.data.knownItem.add( this.toString() ); + handler.getData().knownItem.add( this.toString() ); } @Override diff --git a/src/main/java/appeng/recipes/IngredientSet.java b/src/main/java/appeng/recipes/IngredientSet.java index 18b93045..2ac140b4 100644 --- a/src/main/java/appeng/recipes/IngredientSet.java +++ b/src/main/java/appeng/recipes/IngredientSet.java @@ -22,6 +22,8 @@ package appeng.recipes; import java.util.LinkedList; import java.util.List; +import com.google.common.base.Preconditions; + import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; import appeng.api.exceptions.MissingIngredientError; @@ -33,16 +35,22 @@ import appeng.api.recipes.ResolverResultSet; public class IngredientSet implements IIngredient { - final int qty = 0; - final String name; - final List items; - final boolean isInside = false; - ItemStack[] baked; + private final int qty; + private final String name; + private final List items; + private final boolean isInside = false; + private ItemStack[] baked; - public IngredientSet( ResolverResultSet rr ) + public IngredientSet( ResolverResultSet rr, int qty ) { + Preconditions.checkNotNull( rr ); + Preconditions.checkNotNull( rr.name ); + Preconditions.checkNotNull( rr.results ); + Preconditions.checkState( qty > 0 ); + this.name = rr.name; this.items = rr.results; + this.qty = qty; } @Override @@ -107,7 +115,7 @@ public class IngredientSet implements IIngredient @Override public int getQty() { - return 0; + return this.qty; } @Override diff --git a/src/main/java/appeng/recipes/MissedIngredientSet.java b/src/main/java/appeng/recipes/MissedIngredientSet.java index 2a5a9aa5..3b1cb4e5 100644 --- a/src/main/java/appeng/recipes/MissedIngredientSet.java +++ b/src/main/java/appeng/recipes/MissedIngredientSet.java @@ -26,10 +26,15 @@ public class MissedIngredientSet extends Throwable { private static final long serialVersionUID = 2672951714376345807L; - final ResolverResultSet rrs; + private final ResolverResultSet resolverResultSet; public MissedIngredientSet( ResolverResultSet ro ) { - this.rrs = ro; + this.resolverResultSet = ro; + } + + public ResolverResultSet getResolverResultSet() + { + return this.resolverResultSet; } } diff --git a/src/main/java/appeng/recipes/RecipeData.java b/src/main/java/appeng/recipes/RecipeData.java index cbeeaec4..0e64c15a 100644 --- a/src/main/java/appeng/recipes/RecipeData.java +++ b/src/main/java/appeng/recipes/RecipeData.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import appeng.api.recipes.ICraftHandler; @@ -31,10 +32,10 @@ import appeng.api.recipes.ICraftHandler; public class RecipeData { - public final HashMap aliases = new HashMap(); - public final HashMap groups = new HashMap(); + public final Map aliases = new HashMap(); + public final Map groups = new HashMap(); - public final List Handlers = new LinkedList(); + public final List handlers = new LinkedList(); public final Set knownItem = new HashSet(); public boolean crash = true; public boolean exceptions = true; diff --git a/src/main/java/appeng/recipes/RecipeHandler.java b/src/main/java/appeng/recipes/RecipeHandler.java index 34534128..f59f4742 100644 --- a/src/main/java/appeng/recipes/RecipeHandler.java +++ b/src/main/java/appeng/recipes/RecipeHandler.java @@ -33,6 +33,10 @@ import java.util.zip.ZipOutputStream; import javax.annotation.Nonnull; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.collect.HashMultimap; + import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.LoaderState; @@ -72,9 +76,8 @@ import com.google.common.collect.HashMultimap; */ public class RecipeHandler implements IRecipeHandler { - - public final List tokens = new LinkedList(); - final RecipeData data; + private final RecipeData data; + private final List tokens = new LinkedList(); public RecipeHandler() { @@ -83,12 +86,13 @@ public class RecipeHandler implements IRecipeHandler RecipeHandler( RecipeHandler parent ) { + Preconditions.checkNotNull( parent ); this.data = parent.data; } private void addCrafting( ICraftHandler ch ) { - this.data.Handlers.add( ch ); + this.data.handlers.add( ch ); } public String getName( @Nonnull IIngredient i ) @@ -114,6 +118,8 @@ public class RecipeHandler implements IRecipeHandler public String getName( ItemStack is ) throws RecipeError { + Preconditions.checkNotNull( is ); + UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor( is.getItem() ); String realName = id.modId + ':' + id.name; @@ -220,6 +226,8 @@ public class RecipeHandler implements IRecipeHandler public String alias( String in ) { + Preconditions.checkNotNull( in ); + String out = this.data.aliases.get( in ); if( out != null ) @@ -233,6 +241,9 @@ public class RecipeHandler implements IRecipeHandler @Override public void parseRecipes( IRecipeLoader loader, String path ) { + Preconditions.checkNotNull( loader ); + Preconditions.checkNotNull( path ); + try { BufferedReader reader = null; @@ -364,7 +375,7 @@ public class RecipeHandler implements IRecipeHandler Map processed = new HashMap(); try { - for( ICraftHandler ch : this.data.Handlers ) + for( ICraftHandler ch : this.data.handlers ) { try { @@ -503,7 +514,7 @@ public class RecipeHandler implements IRecipeHandler { List out = new LinkedList(); - for( ICraftHandler ch : this.data.Handlers ) + for( ICraftHandler ch : this.data.handlers ) { try { @@ -521,6 +532,11 @@ public class RecipeHandler implements IRecipeHandler return out; } + RecipeData getData() + { + return this.data; + } + private void processTokens( IRecipeLoader loader, String file, int line ) throws RecipeError { try @@ -557,7 +573,7 @@ public class RecipeHandler implements IRecipeHandler if( inputs.size() == 1 && inputs.get( 0 ).size() > 0 && post.size() == 1 ) { - this.data.groups.put( post.get( 0 ), new GroupIngredient( post.get( 0 ), inputs.get( 0 ) ) ); + this.data.groups.put( post.get( 0 ), new GroupIngredient( post.get( 0 ), inputs.get( 0 ), 1 ) ); } else { @@ -743,7 +759,7 @@ public class RecipeHandler implements IRecipeHandler } catch( MissedIngredientSet grp ) { - return new IngredientSet( grp.rrs ); + return new IngredientSet( grp.getResolverResultSet(), qty ); } } diff --git a/src/main/java/appeng/recipes/game/FacadeRecipe.java b/src/main/java/appeng/recipes/game/FacadeRecipe.java index a9490d60..e13ab1e8 100644 --- a/src/main/java/appeng/recipes/game/FacadeRecipe.java +++ b/src/main/java/appeng/recipes/game/FacadeRecipe.java @@ -38,7 +38,6 @@ import com.google.common.base.Optional; public final class FacadeRecipe implements IRecipe { - private final IComparableDefinition anchor; private final Optional maybeFacade; diff --git a/src/main/java/appeng/recipes/game/ShapedRecipe.java b/src/main/java/appeng/recipes/game/ShapedRecipe.java index a4957b2c..d0243412 100644 --- a/src/main/java/appeng/recipes/game/ShapedRecipe.java +++ b/src/main/java/appeng/recipes/game/ShapedRecipe.java @@ -36,7 +36,6 @@ import appeng.api.recipes.IIngredient; public class ShapedRecipe implements IRecipe, IRecipeBakeable { - // 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; diff --git a/src/main/java/appeng/recipes/ores/OreDictionaryHandler.java b/src/main/java/appeng/recipes/ores/OreDictionaryHandler.java index 73f1062b..f97eb802 100644 --- a/src/main/java/appeng/recipes/ores/OreDictionaryHandler.java +++ b/src/main/java/appeng/recipes/ores/OreDictionaryHandler.java @@ -35,7 +35,7 @@ public class OreDictionaryHandler public static final OreDictionaryHandler INSTANCE = new OreDictionaryHandler(); - private final List ol = new ArrayList(); + private final List oreListeners = new ArrayList(); private boolean enableRebaking = false; @@ -49,7 +49,7 @@ public class OreDictionaryHandler if( this.shouldCare( event.Name ) ) { - for( IOreListener v : this.ol ) + for( IOreListener v : this.oreListeners ) { v.oreRegistered( event.Name, event.Ore ); } @@ -101,7 +101,7 @@ public class OreDictionaryHandler */ public void observe( IOreListener n ) { - this.ol.add( n ); + this.oreListeners.add( n ); // notify the listener of any ore already in existence. for( String name : OreDictionary.getOreNames() )