cut crafting tree earlier if ingredients are available
This commit is contained in:
@@ -57,6 +57,8 @@ public class CraftingJob implements Runnable, ICraftingJob
|
|||||||
private final World world;
|
private final World world;
|
||||||
private final IItemList<IAEItemStack> crafting = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
private final IItemList<IAEItemStack> crafting = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||||
private final IItemList<IAEItemStack> missing = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
private final IItemList<IAEItemStack> missing = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||||
|
private final IItemList<IAEItemStack> usedWhileBuilding = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||||
|
|
||||||
private final HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<>();
|
private final HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<>();
|
||||||
private final Object monitor = new Object();
|
private final Object monitor = new Object();
|
||||||
private final Stopwatch watch = Stopwatch.createUnstarted();
|
private final Stopwatch watch = Stopwatch.createUnstarted();
|
||||||
@@ -102,6 +104,16 @@ public class CraftingJob implements Runnable, ICraftingJob
|
|||||||
this.availableCheck.injectItems( o, Actionable.MODULATE, this.actionSrc );
|
this.availableCheck.injectItems( o, Actionable.MODULATE, this.actionSrc );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IItemList<IAEItemStack> getUsedWhileBuilding()
|
||||||
|
{
|
||||||
|
return usedWhileBuilding;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IAEItemStack getOriginal( IAEItemStack request )
|
||||||
|
{
|
||||||
|
return original.getItemList().findPrecise( request );
|
||||||
|
}
|
||||||
|
|
||||||
IAEItemStack checkUse( final IAEItemStack available )
|
IAEItemStack checkUse( final IAEItemStack available )
|
||||||
{
|
{
|
||||||
return this.availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc );
|
return this.availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc );
|
||||||
|
|||||||
@@ -88,6 +88,35 @@ public class CraftingTreeNode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CraftingTreeNode( final ICraftingGrid cc, final CraftingJob job, final IAEItemStack wat, final CraftingTreeProcess par, final int slot, final int depth, boolean available )
|
||||||
|
{
|
||||||
|
this.what = wat;
|
||||||
|
this.parent = par;
|
||||||
|
this.slot = slot;
|
||||||
|
this.world = job.getWorld();
|
||||||
|
this.job = job;
|
||||||
|
this.sim = false;
|
||||||
|
|
||||||
|
this.canEmit = cc.canEmitFor( this.what );
|
||||||
|
|
||||||
|
if( this.canEmit )
|
||||||
|
{
|
||||||
|
return; // if you can emit for something, you can't make it with patterns.
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !available )
|
||||||
|
{
|
||||||
|
for( final ICraftingPatternDetails details : cc.getCraftingFor( this.what, this.parent == null ? null : this.parent.details, slot, this.world ) )// in
|
||||||
|
// order.
|
||||||
|
{
|
||||||
|
if( this.parent == null || this.parent.notRecursive( details ) )
|
||||||
|
{
|
||||||
|
this.nodes.add( new CraftingTreeProcess( cc, job, details, this, depth + 1 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean notRecursive( final ICraftingPatternDetails details )
|
boolean notRecursive( final ICraftingPatternDetails details )
|
||||||
{
|
{
|
||||||
IAEItemStack[] o = details.getCondensedOutputs();
|
IAEItemStack[] o = details.getCondensedOutputs();
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ public class CraftingTreeProcess
|
|||||||
if( part.getItem().hasContainerItem( part.getDefinition() ) )
|
if( part.getItem().hasContainerItem( part.getDefinition() ) )
|
||||||
{
|
{
|
||||||
this.limitQty = this.containerItems = true;
|
this.limitQty = this.containerItems = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,11 +103,20 @@ public class CraftingTreeProcess
|
|||||||
{
|
{
|
||||||
final IAEItemStack part = list[x];
|
final IAEItemStack part = list[x];
|
||||||
if( part != null )
|
if( part != null )
|
||||||
|
{
|
||||||
|
job.getUsedWhileBuilding().addStorage( part );
|
||||||
|
IAEItemStack used = job.getUsedWhileBuilding().findPrecise( part );
|
||||||
|
if( job.getOriginal( part ) != null && used.getStackSize() <= job.getOriginal( part ).getStackSize() )
|
||||||
|
{
|
||||||
|
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1, true ), part.getStackSize() );
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// this is minor different then below, this slot uses the pattern, but kinda fudges it.
|
// this is minor different then below, this slot uses the pattern, but kinda fudges it.
|
||||||
@@ -116,9 +126,18 @@ public class CraftingTreeProcess
|
|||||||
{
|
{
|
||||||
final IAEItemStack comparePart = list[x];
|
final IAEItemStack comparePart = list[x];
|
||||||
if( part != null && part.equals( comparePart ) )
|
if( part != null && part.equals( comparePart ) )
|
||||||
|
{
|
||||||
|
job.getUsedWhileBuilding().addStorage( part );
|
||||||
|
IAEItemStack used = job.getUsedWhileBuilding().findPrecise( part );
|
||||||
|
if( job.getOriginal( part ) != null && used.getStackSize() <= job.getOriginal( part ).getStackSize() )
|
||||||
|
{
|
||||||
|
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1, true ), part.getStackSize() );
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// use the first slot...
|
// use the first slot...
|
||||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user