2014-06-04 06:37:47 +02:00
|
|
|
package appeng.crafting;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
2014-06-16 07:48:43 +02:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2014-06-04 06:37:47 +02:00
|
|
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-06-05 05:54:01 +02:00
|
|
|
import appeng.api.AEApi;
|
2014-06-05 02:47:13 +02:00
|
|
|
import appeng.api.config.Actionable;
|
2014-06-06 06:26:01 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
2014-06-05 05:54:01 +02:00
|
|
|
import appeng.api.networking.storage.IStorageGrid;
|
2014-06-04 06:37:47 +02:00
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.storage.data.IItemList;
|
2014-06-16 07:48:43 +02:00
|
|
|
import appeng.core.AELog;
|
2014-06-05 05:54:01 +02:00
|
|
|
import appeng.me.cache.CraftingCache;
|
2014-06-16 07:48:43 +02:00
|
|
|
import appeng.util.Platform;
|
2014-06-04 06:37:47 +02:00
|
|
|
|
2014-06-16 07:48:43 +02:00
|
|
|
import com.google.common.base.Stopwatch;
|
2014-06-04 06:37:47 +02:00
|
|
|
|
2014-06-16 07:48:43 +02:00
|
|
|
public class CraftingJob
|
2014-06-04 06:37:47 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
IAEItemStack output;
|
|
|
|
|
|
|
|
IItemList<IAEItemStack> storage;
|
|
|
|
|
|
|
|
HashSet<IAEItemStack> prophecies;
|
|
|
|
|
2014-06-05 02:47:13 +02:00
|
|
|
ICraftingHost jobHost;
|
|
|
|
|
|
|
|
public CraftingJob(ICraftingHost host, NBTTagCompound data) {
|
2014-06-05 05:54:01 +02:00
|
|
|
jobHost = host;
|
|
|
|
storage = AEApi.instance().storage().createItemList();
|
|
|
|
prophecies = new HashSet();
|
2014-06-05 02:47:13 +02:00
|
|
|
}
|
|
|
|
|
2014-06-16 07:48:43 +02:00
|
|
|
public CraftingJob(ICraftingHost host, IAEItemStack what, Actionable mode) {
|
2014-06-05 05:54:01 +02:00
|
|
|
jobHost = host;
|
|
|
|
output = what.copy();
|
|
|
|
storage = AEApi.instance().storage().createItemList();
|
|
|
|
prophecies = new HashSet();
|
|
|
|
|
|
|
|
CraftingCache cc = host.getGrid().getCache( CraftingCache.class );
|
|
|
|
IStorageGrid sg = host.getGrid().getCache( IStorageGrid.class );
|
|
|
|
|
|
|
|
IItemList<IAEItemStack> missing = AEApi.instance().storage().createItemList();
|
2014-06-06 06:26:01 +02:00
|
|
|
|
2014-06-16 07:48:43 +02:00
|
|
|
MECraftingInventory meci = new MECraftingInventory( sg.getItemInventory(), true, false, true );
|
|
|
|
meci.ignore( what );
|
2014-06-06 06:26:01 +02:00
|
|
|
|
2014-06-16 07:48:43 +02:00
|
|
|
CraftingTreeNode tree = getCraftingTree( cc, what );
|
2014-06-06 06:26:01 +02:00
|
|
|
|
2014-06-16 07:48:43 +02:00
|
|
|
try
|
2014-06-05 05:54:01 +02:00
|
|
|
{
|
2014-06-16 07:48:43 +02:00
|
|
|
Stopwatch timer = Stopwatch.createStarted();
|
|
|
|
tree.request( meci, what.getStackSize(), host.getActionSrc() );
|
|
|
|
tree.dive( this );
|
|
|
|
AELog.info( "-------------" + timer.elapsed( TimeUnit.MILLISECONDS ) + "ms" );
|
|
|
|
// if ( mode == Actionable.MODULATE )
|
|
|
|
// meci.moveItemsToStorage( storage );
|
2014-06-05 05:54:01 +02:00
|
|
|
}
|
2014-06-16 07:48:43 +02:00
|
|
|
catch (CraftBranchFailure e)
|
2014-06-06 06:26:01 +02:00
|
|
|
{
|
2014-06-16 07:48:43 +02:00
|
|
|
AELog.error( e );
|
2014-06-06 06:26:01 +02:00
|
|
|
}
|
2014-06-16 07:48:43 +02:00
|
|
|
catch (CraftingCalculationFailure f)
|
2014-06-06 06:26:01 +02:00
|
|
|
{
|
2014-06-16 07:48:43 +02:00
|
|
|
AELog.error( f );
|
2014-06-06 06:26:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-16 07:48:43 +02:00
|
|
|
private CraftingTreeNode getCraftingTree(CraftingCache cc, IAEItemStack what)
|
2014-06-06 06:26:01 +02:00
|
|
|
{
|
2014-06-16 07:48:43 +02:00
|
|
|
return new CraftingTreeNode( cc, this, what, null, 0 );
|
2014-06-06 06:26:01 +02:00
|
|
|
}
|
|
|
|
|
2014-06-16 07:48:43 +02:00
|
|
|
public void writeToNBT(NBTTagCompound out)
|
2014-06-06 06:26:01 +02:00
|
|
|
{
|
|
|
|
|
2014-06-04 06:37:47 +02:00
|
|
|
}
|
|
|
|
|
2014-06-16 07:48:43 +02:00
|
|
|
public void addTask(IAEItemStack what, int crafts, ICraftingPatternDetails details, int depth)
|
2014-06-04 06:37:47 +02:00
|
|
|
{
|
2014-06-16 07:48:43 +02:00
|
|
|
if ( crafts > 0 )
|
2014-06-04 06:37:47 +02:00
|
|
|
{
|
2014-06-16 07:48:43 +02:00
|
|
|
AELog.info( "new task: " + Platform.getItemDisplayName( what ) + " x " + what.getStackSize() + " * " + crafts + " = "
|
|
|
|
+ (what.getStackSize() * crafts) + " @ " + depth );
|
2014-06-04 06:37:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-16 07:48:43 +02:00
|
|
|
public void addMissing(IAEItemStack what)
|
2014-06-04 06:37:47 +02:00
|
|
|
{
|
2014-06-16 07:48:43 +02:00
|
|
|
AELog.info( "required material: " + Platform.getItemDisplayName( what ) + " x " + what.getStackSize() );
|
2014-06-04 06:37:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|