2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-03-10 03:11:29 +01:00
|
|
|
package appeng.recipes;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-03-10 03:11:29 +01:00
|
|
|
import appeng.api.exceptions.MissingIngredientError;
|
|
|
|
import appeng.api.exceptions.RegistrationError;
|
|
|
|
import appeng.api.recipes.IIngredient;
|
|
|
|
import appeng.api.recipes.ResolverResultSet;
|
2017-04-12 16:10:13 +02:00
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2014-03-10 03:11:29 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-03-10 03:11:29 +01:00
|
|
|
public class IngredientSet implements IIngredient
|
|
|
|
{
|
|
|
|
|
2015-08-06 22:45:16 +02:00
|
|
|
private final int qty;
|
|
|
|
private final String name;
|
|
|
|
private final List<ItemStack> items;
|
|
|
|
private final boolean isInside = false;
|
|
|
|
private ItemStack[] baked;
|
2014-07-26 02:31:12 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public IngredientSet( final ResolverResultSet rr, final int qty )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-08-06 22:45:16 +02:00
|
|
|
Preconditions.checkNotNull( rr );
|
|
|
|
Preconditions.checkNotNull( rr.name );
|
|
|
|
Preconditions.checkNotNull( rr.results );
|
|
|
|
Preconditions.checkState( qty > 0 );
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.name = rr.name;
|
|
|
|
this.items = rr.results;
|
2015-08-06 22:45:16 +02:00
|
|
|
this.qty = qty;
|
2014-03-10 03:11:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.baked != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.baked;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-26 02:31:12 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isInside )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-03-10 03:11:29 +01:00
|
|
|
return new ItemStack[0];
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-03-10 03:11:29 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final List<ItemStack> out = new LinkedList<ItemStack>();
|
2014-12-29 15:13:47 +01:00
|
|
|
out.addAll( this.items );
|
2014-03-10 03:11:29 +01:00
|
|
|
|
2015-09-25 23:18:27 +02:00
|
|
|
if( out.isEmpty() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
throw new MissingIngredientError( this.toString() + " - group could not be resolved to any items." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-03-10 03:11:29 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ItemStack is : out )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
is.stackSize = this.qty;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-03-10 03:11:29 +01:00
|
|
|
|
|
|
|
return out.toArray( new ItemStack[out.size()] );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public boolean isAir()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2014-03-10 03:11:29 +01:00
|
|
|
public String getNameSpace()
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public String getItemName()
|
2014-03-10 03:11:29 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.name;
|
2014-03-10 03:11:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public int getDamageValue()
|
2014-03-10 03:11:29 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return OreDictionary.WILDCARD_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getQty()
|
|
|
|
{
|
2015-08-06 22:45:16 +02:00
|
|
|
return this.qty;
|
2014-03-10 03:11:29 +01:00
|
|
|
}
|
2014-07-26 02:31:12 +02:00
|
|
|
|
2014-07-26 00:49:49 +02:00
|
|
|
@Override
|
|
|
|
public void bake() throws RegistrationError, MissingIngredientError
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.baked = null;
|
|
|
|
this.baked = this.getItemStackSet();
|
2014-07-26 00:49:49 +02:00
|
|
|
}
|
2014-03-10 03:11:29 +01:00
|
|
|
}
|