Fixes #1601: Do not allow 0 as stacksize for recipes

This commit is contained in:
yueh 2015-08-06 22:45:16 +02:00 committed by thatsIch
parent b0504f4141
commit d26caa5f8b
9 changed files with 82 additions and 43 deletions

View file

@ -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<IIngredient> ingredients;
int qty = 0;
ItemStack[] baked;
private final String name;
private final List<IIngredient> ingredients;
private final int qty;
private ItemStack[] baked;
boolean isInside = false;
public GroupIngredient( String myName, List<IIngredient> ingredients ) throws RecipeError
public GroupIngredient( String myName, List<IIngredient> 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

View file

@ -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

View file

@ -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<ItemStack> items;
final boolean isInside = false;
ItemStack[] baked;
private final int qty;
private final String name;
private final List<ItemStack> 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

View file

@ -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;
}
}

View file

@ -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<String, String> aliases = new HashMap<String, String>();
public final HashMap<String, GroupIngredient> groups = new HashMap<String, GroupIngredient>();
public final Map<String, String> aliases = new HashMap<String, String>();
public final Map<String, GroupIngredient> groups = new HashMap<String, GroupIngredient>();
public final List<ICraftHandler> Handlers = new LinkedList<ICraftHandler>();
public final List<ICraftHandler> handlers = new LinkedList<ICraftHandler>();
public final Set<String> knownItem = new HashSet<String>();
public boolean crash = true;
public boolean exceptions = true;

View file

@ -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<String> tokens = new LinkedList<String>();
final RecipeData data;
private final RecipeData data;
private final List<String> tokens = new LinkedList<String>();
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<Class, Integer> processed = new HashMap<Class, Integer>();
try
{
for( ICraftHandler ch : this.data.Handlers )
for( ICraftHandler ch : this.data.handlers )
{
try
{
@ -503,7 +514,7 @@ public class RecipeHandler implements IRecipeHandler
{
List<IWebsiteSerializer> out = new LinkedList<IWebsiteSerializer>();
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 );
}
}

View file

@ -38,7 +38,6 @@ import com.google.common.base.Optional;
public final class FacadeRecipe implements IRecipe
{
private final IComparableDefinition anchor;
private final Optional<Item> maybeFacade;

View file

@ -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;

View file

@ -35,7 +35,7 @@ public class OreDictionaryHandler
public static final OreDictionaryHandler INSTANCE = new OreDictionaryHandler();
private final List<IOreListener> ol = new ArrayList<IOreListener>();
private final List<IOreListener> oreListeners = new ArrayList<IOreListener>();
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() )