Basic reformat, hit once, hope never again
This commit is contained in:
@@ -18,8 +18,10 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
|
||||
public class CraftBranchFailure extends Exception
|
||||
{
|
||||
|
||||
@@ -27,7 +29,8 @@ public class CraftBranchFailure extends Exception
|
||||
|
||||
final IAEItemStack missing;
|
||||
|
||||
public CraftBranchFailure(IAEItemStack what, long howMany) {
|
||||
public CraftBranchFailure( IAEItemStack what, long howMany )
|
||||
{
|
||||
super( "Failed: " + what.getItem().getUnlocalizedName() + " x " + howMany );
|
||||
this.missing = what.copy();
|
||||
this.missing.setStackSize( howMany );
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
|
||||
public class CraftingCalculationFailure extends RuntimeException
|
||||
{
|
||||
|
||||
@@ -27,7 +29,8 @@ public class CraftingCalculationFailure extends RuntimeException
|
||||
|
||||
final IAEItemStack missing;
|
||||
|
||||
public CraftingCalculationFailure(IAEItemStack what, long howMany) {
|
||||
public CraftingCalculationFailure( IAEItemStack what, long howMany )
|
||||
{
|
||||
super( "this should have been caught!" );
|
||||
this.missing = what.copy();
|
||||
this.missing.setStackSize( howMany );
|
||||
|
||||
@@ -42,33 +42,32 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.core.AELog;
|
||||
import appeng.hooks.TickHandler;
|
||||
|
||||
|
||||
public class CraftingJob implements Runnable, ICraftingJob
|
||||
{
|
||||
|
||||
IAEItemStack output;
|
||||
|
||||
final IItemList<IAEItemStack> storage;
|
||||
|
||||
final HashSet<IAEItemStack> prophecies;
|
||||
|
||||
boolean simulate = false;
|
||||
final MECraftingInventory original;
|
||||
|
||||
MECraftingInventory availableCheck;
|
||||
final World world;
|
||||
final IItemList<IAEItemStack> crafting = AEApi.instance().storage().createItemList();
|
||||
final IItemList<IAEItemStack> missing = AEApi.instance().storage().createItemList();
|
||||
final HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<String, TwoIntegers>();
|
||||
private final Object monitor = new Object();
|
||||
private final Stopwatch watch = Stopwatch.createUnstarted();
|
||||
public CraftingTreeNode tree;
|
||||
IAEItemStack output;
|
||||
boolean simulate = false;
|
||||
MECraftingInventory availableCheck;
|
||||
long bytes = 0;
|
||||
private BaseActionSource actionSrc;
|
||||
private ICraftingCallback callback;
|
||||
private boolean running = false;
|
||||
private boolean done = false;
|
||||
private int time = 5;
|
||||
private int incTime = Integer.MAX_VALUE;
|
||||
|
||||
long bytes = 0;
|
||||
final World world;
|
||||
|
||||
@Override
|
||||
public IAEItemStack getOutput()
|
||||
{
|
||||
return this.output;
|
||||
}
|
||||
|
||||
public CraftingJob(World w, NBTTagCompound data)
|
||||
public CraftingJob( World w, NBTTagCompound data )
|
||||
{
|
||||
this.world = this.wrapWorld( w );
|
||||
this.storage = AEApi.instance().storage().createItemList();
|
||||
@@ -77,17 +76,12 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
this.availableCheck = null;
|
||||
}
|
||||
|
||||
public void refund(IAEItemStack o)
|
||||
private World wrapWorld( World w )
|
||||
{
|
||||
this.availableCheck.injectItems( o, Actionable.MODULATE, this.actionSrc );
|
||||
return w;
|
||||
}
|
||||
|
||||
public IAEItemStack checkUse(IAEItemStack available)
|
||||
{
|
||||
return this.availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc );
|
||||
}
|
||||
|
||||
public CraftingJob(World w, IGrid grid, BaseActionSource actionSrc, IAEItemStack what, ICraftingCallback callback)
|
||||
public CraftingJob( World w, IGrid grid, BaseActionSource actionSrc, IAEItemStack what, ICraftingCallback callback )
|
||||
{
|
||||
this.world = this.wrapWorld( w );
|
||||
this.output = what.copy();
|
||||
@@ -104,33 +98,29 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
this.availableCheck = null;
|
||||
}
|
||||
|
||||
private World wrapWorld(World w)
|
||||
{
|
||||
return w;
|
||||
}
|
||||
|
||||
private CraftingTreeNode getCraftingTree(ICraftingGrid cc, IAEItemStack what)
|
||||
private CraftingTreeNode getCraftingTree( ICraftingGrid cc, IAEItemStack what )
|
||||
{
|
||||
return new CraftingTreeNode( cc, this, what, null, -1, 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getByteTotal()
|
||||
public void refund( IAEItemStack o )
|
||||
{
|
||||
return this.bytes;
|
||||
this.availableCheck.injectItems( o, Actionable.MODULATE, this.actionSrc );
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound out)
|
||||
public IAEItemStack checkUse( IAEItemStack available )
|
||||
{
|
||||
return this.availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc );
|
||||
}
|
||||
|
||||
public void writeToNBT( NBTTagCompound out )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
final IItemList<IAEItemStack> crafting = AEApi.instance().storage().createItemList();
|
||||
final IItemList<IAEItemStack> missing = AEApi.instance().storage().createItemList();
|
||||
|
||||
public void addTask(IAEItemStack what, long crafts, ICraftingPatternDetails details, int depth)
|
||||
public void addTask( IAEItemStack what, long crafts, ICraftingPatternDetails details, int depth )
|
||||
{
|
||||
if ( crafts > 0 )
|
||||
if( crafts > 0 )
|
||||
{
|
||||
what = what.copy();
|
||||
what.setStackSize( what.getStackSize() * crafts );
|
||||
@@ -138,21 +128,12 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
}
|
||||
}
|
||||
|
||||
public void addMissing(IAEItemStack what)
|
||||
public void addMissing( IAEItemStack what )
|
||||
{
|
||||
what = what.copy();
|
||||
this.missing.add( what );
|
||||
}
|
||||
|
||||
static class TwoIntegers
|
||||
{
|
||||
|
||||
public final long perOp = 0;
|
||||
public final long times = 0;
|
||||
}
|
||||
|
||||
final HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<String, TwoIntegers>();
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
@@ -172,17 +153,17 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
this.tree.request( craftingInventory, this.output.getStackSize(), this.actionSrc );
|
||||
this.tree.dive( this );
|
||||
|
||||
for (String s : this.opsAndMultiplier.keySet())
|
||||
for( String s : this.opsAndMultiplier.keySet() )
|
||||
{
|
||||
TwoIntegers ti = this.opsAndMultiplier.get( s );
|
||||
AELog.crafting( s + " * " + ti.times + " = " + (ti.perOp * ti.times) );
|
||||
AELog.crafting( s + " * " + ti.times + " = " + ( ti.perOp * ti.times ) );
|
||||
}
|
||||
|
||||
AELog.crafting( "------------- " + this.bytes + "b real" + timer.elapsed( TimeUnit.MILLISECONDS ) + "ms" );
|
||||
// if ( mode == Actionable.MODULATE )
|
||||
// craftingInventory.moveItemsToStorage( storage );
|
||||
}
|
||||
catch (CraftBranchFailure e)
|
||||
catch( CraftBranchFailure e )
|
||||
{
|
||||
this.simulate = true;
|
||||
|
||||
@@ -198,34 +179,34 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
this.tree.request( craftingInventory, this.output.getStackSize(), this.actionSrc );
|
||||
this.tree.dive( this );
|
||||
|
||||
for (String s : this.opsAndMultiplier.keySet())
|
||||
for( String s : this.opsAndMultiplier.keySet() )
|
||||
{
|
||||
TwoIntegers ti = this.opsAndMultiplier.get( s );
|
||||
AELog.crafting( s + " * " + ti.times + " = " + (ti.perOp * ti.times) );
|
||||
AELog.crafting( s + " * " + ti.times + " = " + ( ti.perOp * ti.times ) );
|
||||
}
|
||||
|
||||
AELog.crafting( "------------- " + this.bytes + "b simulate" + timer.elapsed( TimeUnit.MILLISECONDS ) + "ms" );
|
||||
}
|
||||
catch (CraftBranchFailure e1)
|
||||
catch( CraftBranchFailure e1 )
|
||||
{
|
||||
AELog.error( e1 );
|
||||
}
|
||||
catch (CraftingCalculationFailure f)
|
||||
catch( CraftingCalculationFailure f )
|
||||
{
|
||||
AELog.error( f );
|
||||
}
|
||||
catch (InterruptedException e1)
|
||||
catch( InterruptedException e1 )
|
||||
{
|
||||
AELog.crafting( "Crafting calculation canceled." );
|
||||
this.finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (CraftingCalculationFailure f)
|
||||
catch( CraftingCalculationFailure f )
|
||||
{
|
||||
AELog.error( f );
|
||||
}
|
||||
catch (InterruptedException e1)
|
||||
catch( InterruptedException e1 )
|
||||
{
|
||||
AELog.crafting( "Crafting calculation canceled." );
|
||||
this.finish();
|
||||
@@ -234,24 +215,57 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
|
||||
this.log( "crafting job now done" );
|
||||
}
|
||||
catch (Throwable t)
|
||||
catch( Throwable t )
|
||||
{
|
||||
this.finish();
|
||||
throw new RuntimeException( t );
|
||||
}
|
||||
|
||||
this.finish();
|
||||
}
|
||||
|
||||
public void handlePausing() throws InterruptedException
|
||||
{
|
||||
if( this.incTime > 100 )
|
||||
{
|
||||
this.incTime = 0;
|
||||
|
||||
synchronized( this.monitor )
|
||||
{
|
||||
if( this.watch.elapsed( TimeUnit.MICROSECONDS ) > this.time )
|
||||
{
|
||||
this.running = false;
|
||||
this.watch.stop();
|
||||
this.monitor.notify();
|
||||
}
|
||||
|
||||
if( !this.running )
|
||||
{
|
||||
this.log( "crafting job will now sleep" );
|
||||
|
||||
while( !this.running )
|
||||
{
|
||||
this.monitor.wait();
|
||||
}
|
||||
|
||||
this.log( "crafting job now active" );
|
||||
}
|
||||
}
|
||||
|
||||
if( Thread.interrupted() )
|
||||
throw new InterruptedException();
|
||||
}
|
||||
this.incTime++;
|
||||
}
|
||||
|
||||
public void finish()
|
||||
{
|
||||
if ( this.callback != null )
|
||||
if( this.callback != null )
|
||||
this.callback.calculationComplete( this );
|
||||
|
||||
this.availableCheck = null;
|
||||
|
||||
synchronized (this.monitor)
|
||||
synchronized( this.monitor )
|
||||
{
|
||||
this.running = false;
|
||||
this.done = true;
|
||||
@@ -259,12 +273,36 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
}
|
||||
}
|
||||
|
||||
private void log( String string )
|
||||
{
|
||||
// AELog.crafting( string );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSimulation()
|
||||
{
|
||||
return this.simulate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getByteTotal()
|
||||
{
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populatePlan( IItemList<IAEItemStack> plan )
|
||||
{
|
||||
if( this.tree != null )
|
||||
this.tree.getPlan( plan );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack getOutput()
|
||||
{
|
||||
return this.output;
|
||||
}
|
||||
|
||||
public boolean isDone()
|
||||
{
|
||||
return this.done;
|
||||
@@ -275,25 +313,20 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
return this.world;
|
||||
}
|
||||
|
||||
private boolean running = false;
|
||||
private boolean done = false;
|
||||
private final Object monitor = new Object();
|
||||
private final Stopwatch watch = Stopwatch.createUnstarted();
|
||||
private int time = 5;
|
||||
|
||||
/**
|
||||
* returns true if this needs more simulation.
|
||||
*
|
||||
* @param milli milliseconds of simulation
|
||||
*
|
||||
* @return true if this needs more simulation
|
||||
*/
|
||||
public boolean simulateFor(int milli)
|
||||
public boolean simulateFor( int milli )
|
||||
{
|
||||
this.time = milli;
|
||||
|
||||
synchronized (this.monitor)
|
||||
synchronized( this.monitor )
|
||||
{
|
||||
if ( this.done )
|
||||
if( this.done )
|
||||
return false;
|
||||
|
||||
this.watch.reset();
|
||||
@@ -304,13 +337,13 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
|
||||
this.monitor.notify();
|
||||
|
||||
while (this.running)
|
||||
while( this.running )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.monitor.wait();
|
||||
}
|
||||
catch (InterruptedException ignored)
|
||||
catch( InterruptedException ignored )
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -321,57 +354,15 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
return true;
|
||||
}
|
||||
|
||||
private int incTime = Integer.MAX_VALUE;
|
||||
|
||||
public void handlePausing() throws InterruptedException
|
||||
{
|
||||
if ( this.incTime > 100 )
|
||||
{
|
||||
this.incTime = 0;
|
||||
|
||||
synchronized (this.monitor)
|
||||
{
|
||||
if ( this.watch.elapsed( TimeUnit.MICROSECONDS ) > this.time )
|
||||
{
|
||||
this.running = false;
|
||||
this.watch.stop();
|
||||
this.monitor.notify();
|
||||
}
|
||||
|
||||
if ( !this.running )
|
||||
{
|
||||
this.log( "crafting job will now sleep" );
|
||||
|
||||
while (!this.running)
|
||||
{
|
||||
this.monitor.wait();
|
||||
}
|
||||
|
||||
this.log( "crafting job now active" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( Thread.interrupted() )
|
||||
throw new InterruptedException();
|
||||
}
|
||||
this.incTime++;
|
||||
}
|
||||
|
||||
private void log(String string)
|
||||
{
|
||||
// AELog.crafting( string );
|
||||
}
|
||||
|
||||
public void addBytes(long crafts)
|
||||
public void addBytes( long crafts )
|
||||
{
|
||||
this.bytes += crafts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populatePlan(IItemList<IAEItemStack> plan)
|
||||
static class TwoIntegers
|
||||
{
|
||||
if ( this.tree != null )
|
||||
this.tree.getPlan( plan );
|
||||
}
|
||||
|
||||
public final long perOp = 0;
|
||||
public final long times = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -26,40 +27,40 @@ import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
|
||||
public class CraftingLink implements ICraftingLink
|
||||
{
|
||||
|
||||
boolean canceled = false;
|
||||
boolean done = false;
|
||||
|
||||
CraftingLinkNexus tie;
|
||||
|
||||
final ICraftingRequester req;
|
||||
final ICraftingCPU cpu;
|
||||
|
||||
final String CraftID;
|
||||
final boolean standalone;
|
||||
boolean canceled = false;
|
||||
boolean done = false;
|
||||
CraftingLinkNexus tie;
|
||||
|
||||
public CraftingLink(NBTTagCompound data, ICraftingRequester req) {
|
||||
public CraftingLink( NBTTagCompound data, ICraftingRequester req )
|
||||
{
|
||||
this.CraftID = data.getString( "CraftID" );
|
||||
this.canceled = data.getBoolean( "canceled" );
|
||||
this.done = data.getBoolean( "done" );
|
||||
this.standalone = data.getBoolean( "standalone" );
|
||||
|
||||
if ( !data.hasKey( "req" ) || !data.getBoolean( "req" ) )
|
||||
if( !data.hasKey( "req" ) || !data.getBoolean( "req" ) )
|
||||
throw new RuntimeException( "Invalid Crafting Link for Object" );
|
||||
|
||||
this.req = req;
|
||||
this.cpu = null;
|
||||
}
|
||||
|
||||
public CraftingLink(NBTTagCompound data, ICraftingCPU cpu) {
|
||||
public CraftingLink( NBTTagCompound data, ICraftingCPU cpu )
|
||||
{
|
||||
this.CraftID = data.getString( "CraftID" );
|
||||
this.canceled = data.getBoolean( "canceled" );
|
||||
this.done = data.getBoolean( "done" );
|
||||
this.standalone = data.getBoolean( "standalone" );
|
||||
|
||||
if ( !data.hasKey( "req" ) || data.getBoolean( "req" ) )
|
||||
if( !data.hasKey( "req" ) || data.getBoolean( "req" ) )
|
||||
throw new RuntimeException( "Invalid Crafting Link for Object" );
|
||||
|
||||
this.cpu = cpu;
|
||||
@@ -69,13 +70,13 @@ public class CraftingLink implements ICraftingLink
|
||||
@Override
|
||||
public boolean isCanceled()
|
||||
{
|
||||
if ( this.canceled )
|
||||
if( this.canceled )
|
||||
return true;
|
||||
|
||||
if ( this.done )
|
||||
if( this.done )
|
||||
return false;
|
||||
|
||||
if ( this.tie == null )
|
||||
if( this.tie == null )
|
||||
return false;
|
||||
|
||||
return this.tie.isCanceled();
|
||||
@@ -84,13 +85,13 @@ public class CraftingLink implements ICraftingLink
|
||||
@Override
|
||||
public boolean isDone()
|
||||
{
|
||||
if ( this.done )
|
||||
if( this.done )
|
||||
return true;
|
||||
|
||||
if ( this.canceled )
|
||||
if( this.canceled )
|
||||
return false;
|
||||
|
||||
if ( this.tie == null )
|
||||
if( this.tie == null )
|
||||
return false;
|
||||
|
||||
return this.tie.isDone();
|
||||
@@ -99,60 +100,60 @@ public class CraftingLink implements ICraftingLink
|
||||
@Override
|
||||
public void cancel()
|
||||
{
|
||||
if ( this.done )
|
||||
if( this.done )
|
||||
return;
|
||||
|
||||
this.canceled = true;
|
||||
|
||||
if ( this.tie != null )
|
||||
if( this.tie != null )
|
||||
this.tie.cancel();
|
||||
|
||||
this.tie = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
tag.setString( "CraftID", this.CraftID );
|
||||
tag.setBoolean( "canceled", this.canceled );
|
||||
tag.setBoolean( "done", this.done );
|
||||
tag.setBoolean( "standalone", this.standalone );
|
||||
tag.setBoolean( "req", this.req != null );
|
||||
}
|
||||
|
||||
public void setNexus(CraftingLinkNexus n)
|
||||
{
|
||||
if ( this.tie != null )
|
||||
this.tie.remove( this );
|
||||
|
||||
if ( this.canceled && n != null )
|
||||
{
|
||||
n.cancel();
|
||||
this.tie = null;
|
||||
return;
|
||||
}
|
||||
|
||||
this.tie = n;
|
||||
|
||||
if ( n != null )
|
||||
n.add( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCraftingID()
|
||||
{
|
||||
return this.CraftID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStandalone()
|
||||
{
|
||||
return this.standalone;
|
||||
}
|
||||
|
||||
public IAEItemStack injectItems(IAEItemStack input, Actionable mode)
|
||||
@Override
|
||||
public void writeToNBT( NBTTagCompound tag )
|
||||
{
|
||||
if ( this.tie == null || this.tie.req == null || this.tie.req.req == null )
|
||||
tag.setString( "CraftID", this.CraftID );
|
||||
tag.setBoolean( "canceled", this.canceled );
|
||||
tag.setBoolean( "done", this.done );
|
||||
tag.setBoolean( "standalone", this.standalone );
|
||||
tag.setBoolean( "req", this.req != null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCraftingID()
|
||||
{
|
||||
return this.CraftID;
|
||||
}
|
||||
|
||||
public void setNexus( CraftingLinkNexus n )
|
||||
{
|
||||
if( this.tie != null )
|
||||
this.tie.remove( this );
|
||||
|
||||
if( this.canceled && n != null )
|
||||
{
|
||||
n.cancel();
|
||||
this.tie = null;
|
||||
return;
|
||||
}
|
||||
|
||||
this.tie = n;
|
||||
|
||||
if( n != null )
|
||||
n.add( this );
|
||||
}
|
||||
|
||||
public IAEItemStack injectItems( IAEItemStack input, Actionable mode )
|
||||
{
|
||||
if( this.tie == null || this.tie.req == null || this.tie.req.req == null )
|
||||
return input;
|
||||
|
||||
return this.tie.req.req.injectCraftedItems( this.tie.req, input, mode );
|
||||
@@ -160,7 +161,7 @@ public class CraftingLink implements ICraftingLink
|
||||
|
||||
public void markDone()
|
||||
{
|
||||
if ( this.tie != null )
|
||||
if( this.tie != null )
|
||||
this.tie.markDone();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,46 +18,46 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
|
||||
|
||||
public class CraftingLinkNexus
|
||||
{
|
||||
|
||||
public CraftingLinkNexus(String craftID) {
|
||||
this.CraftID = craftID;
|
||||
}
|
||||
|
||||
public final String CraftID;
|
||||
|
||||
boolean canceled = false;
|
||||
boolean done = false;
|
||||
|
||||
int tickOfDeath = 0;
|
||||
|
||||
CraftingLink req;
|
||||
CraftingLink cpu;
|
||||
|
||||
public boolean isDead(IGrid g, CraftingGridCache craftingGridCache)
|
||||
public CraftingLinkNexus( String craftID )
|
||||
{
|
||||
if ( this.canceled || this.done )
|
||||
this.CraftID = craftID;
|
||||
}
|
||||
|
||||
public boolean isDead( IGrid g, CraftingGridCache craftingGridCache )
|
||||
{
|
||||
if( this.canceled || this.done )
|
||||
return true;
|
||||
|
||||
if ( this.req == null || this.cpu == null )
|
||||
if( this.req == null || this.cpu == null )
|
||||
this.tickOfDeath++;
|
||||
else
|
||||
{
|
||||
boolean hasCpu = craftingGridCache.hasCpu( this.cpu.cpu );
|
||||
boolean hasMachine = this.req.req.getActionableNode().getGrid() == g;
|
||||
|
||||
if ( hasCpu && hasMachine )
|
||||
if( hasCpu && hasMachine )
|
||||
this.tickOfDeath = 0;
|
||||
else
|
||||
this.tickOfDeath += 60;
|
||||
}
|
||||
|
||||
if ( this.tickOfDeath > 60 )
|
||||
if( this.tickOfDeath > 60 )
|
||||
{
|
||||
this.cancel();
|
||||
return true;
|
||||
@@ -66,19 +66,34 @@ public class CraftingLinkNexus
|
||||
return false;
|
||||
}
|
||||
|
||||
public void remove(CraftingLink craftingLink)
|
||||
public void cancel()
|
||||
{
|
||||
if ( this.req == craftingLink )
|
||||
this.canceled = true;
|
||||
|
||||
if( this.req != null )
|
||||
{
|
||||
this.req.canceled = true;
|
||||
if( this.req.req != null )
|
||||
this.req.req.jobStateChange( this.req );
|
||||
}
|
||||
|
||||
if( this.cpu != null )
|
||||
this.cpu.canceled = true;
|
||||
}
|
||||
|
||||
public void remove( CraftingLink craftingLink )
|
||||
{
|
||||
if( this.req == craftingLink )
|
||||
this.req = null;
|
||||
else if ( this.cpu == craftingLink )
|
||||
else if( this.cpu == craftingLink )
|
||||
this.cpu = null;
|
||||
}
|
||||
|
||||
public void add(CraftingLink craftingLink)
|
||||
public void add( CraftingLink craftingLink )
|
||||
{
|
||||
if ( craftingLink.cpu != null )
|
||||
if( craftingLink.cpu != null )
|
||||
this.cpu = craftingLink;
|
||||
else if ( craftingLink.req != null )
|
||||
else if( craftingLink.req != null )
|
||||
this.req = craftingLink;
|
||||
}
|
||||
|
||||
@@ -96,44 +111,28 @@ public class CraftingLinkNexus
|
||||
{
|
||||
this.done = true;
|
||||
|
||||
if ( this.req != null )
|
||||
if( this.req != null )
|
||||
{
|
||||
this.req.done = true;
|
||||
if ( this.req.req != null )
|
||||
if( this.req.req != null )
|
||||
this.req.req.jobStateChange( this.req );
|
||||
}
|
||||
|
||||
if ( this.cpu != null )
|
||||
if( this.cpu != null )
|
||||
this.cpu.done = true;
|
||||
}
|
||||
|
||||
public void cancel()
|
||||
{
|
||||
this.canceled = true;
|
||||
|
||||
if ( this.req != null )
|
||||
{
|
||||
this.req.canceled = true;
|
||||
if ( this.req.req != null )
|
||||
this.req.req.jobStateChange( this.req );
|
||||
}
|
||||
|
||||
if ( this.cpu != null )
|
||||
this.cpu.canceled = true;
|
||||
}
|
||||
|
||||
public boolean isMachine(IGridHost machine)
|
||||
public boolean isMachine( IGridHost machine )
|
||||
{
|
||||
return this.req == machine;
|
||||
}
|
||||
|
||||
public void removeNode()
|
||||
{
|
||||
if ( this.req != null )
|
||||
if( this.req != null )
|
||||
this.req.setNexus( null );
|
||||
|
||||
this.req = null;
|
||||
this.tickOfDeath = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,36 +35,31 @@ import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
|
||||
|
||||
public class CraftingTreeNode
|
||||
{
|
||||
|
||||
// what slot!
|
||||
final int slot;
|
||||
final CraftingJob job;
|
||||
final IItemList<IAEItemStack> used = AEApi.instance().storage().createItemList();
|
||||
// parent node.
|
||||
private final CraftingTreeProcess parent;
|
||||
private final World world;
|
||||
|
||||
// what slot!
|
||||
final int slot;
|
||||
int bytes = 0;
|
||||
|
||||
// what item is this?
|
||||
private final IAEItemStack what;
|
||||
|
||||
// what are the crafting patterns for this?
|
||||
private final ArrayList<CraftingTreeProcess> nodes = new ArrayList<CraftingTreeProcess>();
|
||||
|
||||
int bytes = 0;
|
||||
boolean canEmit = false;
|
||||
boolean cannotUse = false;
|
||||
|
||||
long missing = 0;
|
||||
long howManyEmitted = 0;
|
||||
|
||||
final CraftingJob job;
|
||||
final IItemList<IAEItemStack> used = AEApi.instance().storage().createItemList();
|
||||
boolean exhausted = false;
|
||||
|
||||
boolean sim;
|
||||
|
||||
public CraftingTreeNode(ICraftingGrid cc, CraftingJob job, IAEItemStack wat, CraftingTreeProcess par, int slot, int depth)
|
||||
public CraftingTreeNode( ICraftingGrid cc, CraftingJob job, IAEItemStack wat, CraftingTreeProcess par, int slot, int depth )
|
||||
{
|
||||
this.what = wat;
|
||||
this.parent = par;
|
||||
@@ -74,66 +69,58 @@ public class CraftingTreeNode
|
||||
this.sim = false;
|
||||
|
||||
this.canEmit = cc.canEmitFor( this.what );
|
||||
if ( this.canEmit )
|
||||
if( this.canEmit )
|
||||
return; // if you can emit for something, you can't make it with patterns.
|
||||
|
||||
for (ICraftingPatternDetails details : cc.getCraftingFor( this.what, this.parent == null ? null : this.parent.details, slot, this.world ))// in
|
||||
// order.
|
||||
for( 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 ) )
|
||||
if( this.parent == null || this.parent.notRecursive( details ) )
|
||||
this.nodes.add( new CraftingTreeProcess( cc, job, details, this, depth + 1 ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IAEItemStack getStack(long size)
|
||||
{
|
||||
IAEItemStack is = this.what.copy();
|
||||
is.setStackSize( size );
|
||||
return is;
|
||||
}
|
||||
|
||||
boolean notRecursive(ICraftingPatternDetails details)
|
||||
boolean notRecursive( ICraftingPatternDetails details )
|
||||
{
|
||||
IAEItemStack[] o = details.getCondensedOutputs();
|
||||
for (IAEItemStack i : o)
|
||||
if ( i.equals( this.what ) )
|
||||
for( IAEItemStack i : o )
|
||||
if( i.equals( this.what ) )
|
||||
return false;
|
||||
|
||||
o = details.getCondensedInputs();
|
||||
for (IAEItemStack i : o)
|
||||
if ( i.equals( this.what ) )
|
||||
for( IAEItemStack i : o )
|
||||
if( i.equals( this.what ) )
|
||||
return false;
|
||||
|
||||
if ( this.parent == null )
|
||||
if( this.parent == null )
|
||||
return true;
|
||||
|
||||
return this.parent.notRecursive( details );
|
||||
}
|
||||
|
||||
public IAEItemStack request(MECraftingInventory inv, long l, BaseActionSource src) throws CraftBranchFailure, InterruptedException
|
||||
public IAEItemStack request( MECraftingInventory inv, long l, BaseActionSource src ) throws CraftBranchFailure, InterruptedException
|
||||
{
|
||||
this.job.handlePausing();
|
||||
|
||||
List<IAEItemStack> thingsUsed = new LinkedList<IAEItemStack>();
|
||||
|
||||
this.what.setStackSize( l );
|
||||
if ( this.slot >= 0 && this.parent != null && this.parent.details.isCraftable() )
|
||||
if( this.slot >= 0 && this.parent != null && this.parent.details.isCraftable() )
|
||||
{
|
||||
for (IAEItemStack fuzz : inv.getItemList().findFuzzy( this.what, FuzzyMode.IGNORE_ALL ))
|
||||
for( IAEItemStack fuzz : inv.getItemList().findFuzzy( this.what, FuzzyMode.IGNORE_ALL ) )
|
||||
{
|
||||
if ( this.parent.details.isValidItemForSlot( this.slot, fuzz.getItemStack(), this.world ) )
|
||||
if( this.parent.details.isValidItemForSlot( this.slot, fuzz.getItemStack(), this.world ) )
|
||||
{
|
||||
fuzz = fuzz.copy();
|
||||
fuzz.setStackSize( l );
|
||||
IAEItemStack available = inv.extractItems( fuzz, Actionable.MODULATE, src );
|
||||
|
||||
if ( available != null )
|
||||
if( available != null )
|
||||
{
|
||||
if ( !this.exhausted )
|
||||
if( !this.exhausted )
|
||||
{
|
||||
IAEItemStack is = this.job.checkUse( available );
|
||||
if ( is != null )
|
||||
if( is != null )
|
||||
{
|
||||
thingsUsed.add( is.copy() );
|
||||
this.used.add( is );
|
||||
@@ -143,7 +130,7 @@ public class CraftingTreeNode
|
||||
this.bytes += available.getStackSize();
|
||||
l -= available.getStackSize();
|
||||
|
||||
if ( l == 0 )
|
||||
if( l == 0 )
|
||||
return available;
|
||||
}
|
||||
}
|
||||
@@ -153,12 +140,12 @@ public class CraftingTreeNode
|
||||
{
|
||||
IAEItemStack available = inv.extractItems( this.what, Actionable.MODULATE, src );
|
||||
|
||||
if ( available != null )
|
||||
if( available != null )
|
||||
{
|
||||
if ( !this.exhausted )
|
||||
if( !this.exhausted )
|
||||
{
|
||||
IAEItemStack is = this.job.checkUse( available );
|
||||
if ( is != null )
|
||||
if( is != null )
|
||||
{
|
||||
thingsUsed.add( is.copy() );
|
||||
this.used.add( is );
|
||||
@@ -168,12 +155,12 @@ public class CraftingTreeNode
|
||||
this.bytes += available.getStackSize();
|
||||
l -= available.getStackSize();
|
||||
|
||||
if ( l == 0 )
|
||||
if( l == 0 )
|
||||
return available;
|
||||
}
|
||||
}
|
||||
|
||||
if ( this.canEmit )
|
||||
if( this.canEmit )
|
||||
{
|
||||
IAEItemStack wat = this.what.copy();
|
||||
wat.setStackSize( l );
|
||||
@@ -186,11 +173,11 @@ public class CraftingTreeNode
|
||||
|
||||
this.exhausted = true;
|
||||
|
||||
if ( this.nodes.size() == 1 )
|
||||
if( this.nodes.size() == 1 )
|
||||
{
|
||||
CraftingTreeProcess pro = this.nodes.get( 0 );
|
||||
|
||||
while (pro.possible && l > 0)
|
||||
while( pro.possible && l > 0 )
|
||||
{
|
||||
IAEItemStack madeWhat = pro.getAmountCrafted( this.what );
|
||||
|
||||
@@ -199,25 +186,25 @@ public class CraftingTreeNode
|
||||
madeWhat.setStackSize( l );
|
||||
IAEItemStack available = inv.extractItems( madeWhat, Actionable.MODULATE, src );
|
||||
|
||||
if ( available != null )
|
||||
if( available != null )
|
||||
{
|
||||
this.bytes += available.getStackSize();
|
||||
l -= available.getStackSize();
|
||||
|
||||
if ( l <= 0 )
|
||||
if( l <= 0 )
|
||||
return available;
|
||||
}
|
||||
else
|
||||
pro.possible = false; // ;P
|
||||
}
|
||||
}
|
||||
else if ( this.nodes.size() > 1 )
|
||||
else if( this.nodes.size() > 1 )
|
||||
{
|
||||
for (CraftingTreeProcess pro : this.nodes)
|
||||
for( CraftingTreeProcess pro : this.nodes )
|
||||
{
|
||||
try
|
||||
{
|
||||
while (pro.possible && l > 0)
|
||||
while( pro.possible && l > 0 )
|
||||
{
|
||||
MECraftingInventory subInv = new MECraftingInventory( inv, true, true, true );
|
||||
pro.request( subInv, 1, src );
|
||||
@@ -225,29 +212,29 @@ public class CraftingTreeNode
|
||||
this.what.setStackSize( l );
|
||||
IAEItemStack available = subInv.extractItems( this.what, Actionable.MODULATE, src );
|
||||
|
||||
if ( available != null )
|
||||
if( available != null )
|
||||
{
|
||||
if ( !subInv.commit( src ) )
|
||||
if( !subInv.commit( src ) )
|
||||
throw new CraftBranchFailure( this.what, l );
|
||||
|
||||
this.bytes += available.getStackSize();
|
||||
l -= available.getStackSize();
|
||||
|
||||
if ( l <= 0 )
|
||||
if( l <= 0 )
|
||||
return available;
|
||||
}
|
||||
else
|
||||
pro.possible = false; // ;P
|
||||
}
|
||||
}
|
||||
catch (CraftBranchFailure fail)
|
||||
catch( CraftBranchFailure fail )
|
||||
{
|
||||
pro.possible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( this.sim )
|
||||
if( this.sim )
|
||||
{
|
||||
this.missing += l;
|
||||
this.bytes += l;
|
||||
@@ -256,7 +243,7 @@ public class CraftingTreeNode
|
||||
return rv;
|
||||
}
|
||||
|
||||
for (IAEItemStack o : thingsUsed)
|
||||
for( IAEItemStack o : thingsUsed )
|
||||
{
|
||||
this.job.refund( o.copy() );
|
||||
o.setStackSize( -o.getStackSize() );
|
||||
@@ -266,18 +253,25 @@ public class CraftingTreeNode
|
||||
throw new CraftBranchFailure( this.what, l );
|
||||
}
|
||||
|
||||
public void dive(CraftingJob job)
|
||||
public void dive( CraftingJob job )
|
||||
{
|
||||
if ( this.missing > 0 )
|
||||
if( this.missing > 0 )
|
||||
job.addMissing( this.getStack( this.missing ) );
|
||||
// missing = 0;
|
||||
|
||||
job.addBytes( 8 + this.bytes );
|
||||
|
||||
for (CraftingTreeProcess pro : this.nodes)
|
||||
for( CraftingTreeProcess pro : this.nodes )
|
||||
pro.dive( job );
|
||||
}
|
||||
|
||||
public IAEItemStack getStack( long size )
|
||||
{
|
||||
IAEItemStack is = this.what.copy();
|
||||
is.setStackSize( size );
|
||||
return is;
|
||||
}
|
||||
|
||||
public void setSimulate()
|
||||
{
|
||||
this.sim = true;
|
||||
@@ -286,53 +280,53 @@ public class CraftingTreeNode
|
||||
this.used.resetStatus();
|
||||
this.exhausted = false;
|
||||
|
||||
for (CraftingTreeProcess pro : this.nodes)
|
||||
for( CraftingTreeProcess pro : this.nodes )
|
||||
pro.setSimulate();
|
||||
}
|
||||
|
||||
public void setJob(MECraftingInventory storage, CraftingCPUCluster craftingCPUCluster, BaseActionSource src) throws CraftBranchFailure
|
||||
public void setJob( MECraftingInventory storage, CraftingCPUCluster craftingCPUCluster, BaseActionSource src ) throws CraftBranchFailure
|
||||
{
|
||||
for (IAEItemStack i : this.used)
|
||||
for( IAEItemStack i : this.used )
|
||||
{
|
||||
IAEItemStack ex = storage.extractItems( i, Actionable.MODULATE, src );
|
||||
|
||||
if ( ex == null || ex.getStackSize() != i.getStackSize() )
|
||||
if( ex == null || ex.getStackSize() != i.getStackSize() )
|
||||
throw new CraftBranchFailure( i, i.getStackSize() );
|
||||
|
||||
craftingCPUCluster.addStorage( ex );
|
||||
}
|
||||
|
||||
if ( this.howManyEmitted > 0 )
|
||||
if( this.howManyEmitted > 0 )
|
||||
{
|
||||
IAEItemStack i = this.what.copy();
|
||||
i.setStackSize( this.howManyEmitted );
|
||||
craftingCPUCluster.addEmitable( i );
|
||||
}
|
||||
|
||||
for (CraftingTreeProcess pro : this.nodes)
|
||||
for( CraftingTreeProcess pro : this.nodes )
|
||||
pro.setJob( storage, craftingCPUCluster, src );
|
||||
}
|
||||
|
||||
public void getPlan(IItemList<IAEItemStack> plan)
|
||||
public void getPlan( IItemList<IAEItemStack> plan )
|
||||
{
|
||||
if ( this.missing > 0 )
|
||||
if( this.missing > 0 )
|
||||
{
|
||||
IAEItemStack o = this.what.copy();
|
||||
o.setStackSize( this.missing );
|
||||
plan.add( o );
|
||||
}
|
||||
|
||||
if ( this.howManyEmitted > 0 )
|
||||
if( this.howManyEmitted > 0 )
|
||||
{
|
||||
IAEItemStack i = this.what.copy();
|
||||
i.setCountRequestable( this.howManyEmitted );
|
||||
plan.addRequestable( i );
|
||||
}
|
||||
|
||||
for (IAEItemStack i : this.used)
|
||||
for( IAEItemStack i : this.used )
|
||||
plan.add( i.copy() );
|
||||
|
||||
for (CraftingTreeProcess pro : this.nodes)
|
||||
for( CraftingTreeProcess pro : this.nodes )
|
||||
pro.getPlan( plan );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,88 +41,87 @@ import appeng.container.ContainerNull;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class CraftingTreeProcess
|
||||
{
|
||||
|
||||
World world;
|
||||
final CraftingTreeNode parent;
|
||||
final ICraftingPatternDetails details;
|
||||
final CraftingJob job;
|
||||
|
||||
final Map<CraftingTreeNode, Long> nodes = new HashMap<CraftingTreeNode, Long>();
|
||||
final private int depth;
|
||||
public boolean possible = true;
|
||||
World world;
|
||||
long crafts = 0;
|
||||
boolean containerItems;
|
||||
boolean limitQty;
|
||||
boolean fullSimulation;
|
||||
|
||||
private long bytes = 0;
|
||||
final private int depth;
|
||||
|
||||
final Map<CraftingTreeNode, Long> nodes = new HashMap<CraftingTreeNode, Long>();
|
||||
public boolean possible = true;
|
||||
|
||||
public CraftingTreeProcess( ICraftingGrid cc, CraftingJob job, ICraftingPatternDetails details, CraftingTreeNode craftingTreeNode, int depth ) {
|
||||
public CraftingTreeProcess( ICraftingGrid cc, CraftingJob job, ICraftingPatternDetails details, CraftingTreeNode craftingTreeNode, int depth )
|
||||
{
|
||||
this.parent = craftingTreeNode;
|
||||
this.details = details;
|
||||
this.job = job;
|
||||
this.depth = depth;
|
||||
World world = job.getWorld();
|
||||
|
||||
if ( details.isCraftable() )
|
||||
if( details.isCraftable() )
|
||||
{
|
||||
IAEItemStack[] list = details.getInputs();
|
||||
|
||||
InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
IAEItemStack[] is = details.getInputs();
|
||||
for (int x = 0; x < ic.getSizeInventory(); x++)
|
||||
for( int x = 0; x < ic.getSizeInventory(); x++ )
|
||||
ic.setInventorySlotContents( x, is[x] == null ? null : is[x].getItemStack() );
|
||||
|
||||
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) world ), details.getOutput( ic, world ), ic );
|
||||
|
||||
for (int x = 0; x < ic.getSizeInventory(); x++)
|
||||
for( int x = 0; x < ic.getSizeInventory(); x++ )
|
||||
{
|
||||
ItemStack g = ic.getStackInSlot( x );
|
||||
if ( g != null && g.stackSize > 1 )
|
||||
if( g != null && g.stackSize > 1 )
|
||||
this.fullSimulation = true;
|
||||
}
|
||||
|
||||
for ( IAEItemStack part : details.getCondensedInputs() )
|
||||
for( IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
ItemStack g = part.getItemStack();
|
||||
|
||||
boolean isAnInput = false;
|
||||
for ( IAEItemStack a : details.getCondensedOutputs() )
|
||||
for( IAEItemStack a : details.getCondensedOutputs() )
|
||||
{
|
||||
if ( g != null && a != null && a.equals( g ) )
|
||||
if( g != null && a != null && a.equals( g ) )
|
||||
isAnInput = true;
|
||||
}
|
||||
|
||||
if ( isAnInput )
|
||||
if( isAnInput )
|
||||
this.limitQty = true;
|
||||
|
||||
if ( g.getItem().hasContainerItem( g ) )
|
||||
if( g.getItem().hasContainerItem( g ) )
|
||||
this.limitQty = this.containerItems = true;
|
||||
}
|
||||
|
||||
boolean complicated = false;
|
||||
|
||||
if ( this.containerItems || complicated )
|
||||
if( this.containerItems || complicated )
|
||||
{
|
||||
for (int x = 0; x < list.length; x++)
|
||||
for( int x = 0; x < list.length; x++ )
|
||||
{
|
||||
IAEItemStack part = list[x];
|
||||
if ( part != null )
|
||||
if( part != null )
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is minor different then below, this slot uses the pattern, but kinda fudges it.
|
||||
for (IAEItemStack part : details.getCondensedInputs())
|
||||
for( IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
for (int x = 0; x < list.length; x++)
|
||||
for( int x = 0; x < list.length; x++ )
|
||||
{
|
||||
IAEItemStack comparePart = list[x];
|
||||
if ( part != null && part.equals( comparePart ) )
|
||||
if( part != null && part.equals( comparePart ) )
|
||||
{
|
||||
// use the first slot...
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
||||
@@ -134,75 +133,49 @@ public class CraftingTreeProcess
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( IAEItemStack part : details.getCondensedInputs() )
|
||||
for( IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
ItemStack g = part.getItemStack();
|
||||
|
||||
boolean isAnInput = false;
|
||||
for (IAEItemStack a : details.getCondensedOutputs())
|
||||
for( IAEItemStack a : details.getCondensedOutputs() )
|
||||
{
|
||||
if ( g != null && a != null && a.equals( g ) )
|
||||
if( g != null && a != null && a.equals( g ) )
|
||||
isAnInput = true;
|
||||
}
|
||||
|
||||
if ( isAnInput )
|
||||
if( isAnInput )
|
||||
this.limitQty = true;
|
||||
}
|
||||
|
||||
for (IAEItemStack part : details.getCondensedInputs())
|
||||
for( IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, -1, depth + 1 ), part.getStackSize() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean notRecursive(ICraftingPatternDetails details)
|
||||
public boolean notRecursive( ICraftingPatternDetails details )
|
||||
{
|
||||
return this.parent == null || this.parent.notRecursive( details );
|
||||
}
|
||||
|
||||
long getTimes(long remaining, long stackSize)
|
||||
long getTimes( long remaining, long stackSize )
|
||||
{
|
||||
if ( this.limitQty || this.fullSimulation )
|
||||
if( this.limitQty || this.fullSimulation )
|
||||
return 1;
|
||||
return (remaining / stackSize) + (remaining % stackSize != 0 ? 1 : 0);
|
||||
return ( remaining / stackSize ) + ( remaining % stackSize != 0 ? 1 : 0 );
|
||||
}
|
||||
|
||||
IAEItemStack getAmountCrafted(IAEItemStack what2)
|
||||
{
|
||||
for (IAEItemStack is : this.details.getCondensedOutputs())
|
||||
{
|
||||
if ( is.equals( what2 ) )
|
||||
{
|
||||
what2 = what2.copy();
|
||||
what2.setStackSize( is.getStackSize() );
|
||||
return what2;
|
||||
}
|
||||
}
|
||||
|
||||
// more fuzzy!
|
||||
for (IAEItemStack is : this.details.getCondensedOutputs())
|
||||
{
|
||||
if ( is.getItem() == what2.getItem() && (is.getItem().isDamageable() || is.getItemDamage() == what2.getItemDamage()) )
|
||||
{
|
||||
what2 = is.copy();
|
||||
what2.setStackSize( is.getStackSize() );
|
||||
return what2;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException( "Crafting Tree construction failed." );
|
||||
}
|
||||
|
||||
public void request(MECraftingInventory inv, long i, BaseActionSource src) throws CraftBranchFailure, InterruptedException
|
||||
public void request( MECraftingInventory inv, long i, BaseActionSource src ) throws CraftBranchFailure, InterruptedException
|
||||
{
|
||||
this.job.handlePausing();
|
||||
|
||||
if ( this.fullSimulation )
|
||||
if( this.fullSimulation )
|
||||
{
|
||||
InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
|
||||
for (Entry<CraftingTreeNode, Long> entry : this.nodes.entrySet())
|
||||
for( Entry<CraftingTreeNode, Long> entry : this.nodes.entrySet() )
|
||||
{
|
||||
IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
||||
IAEItemStack stack = entry.getKey().request( inv, item.getStackSize(), src );
|
||||
@@ -212,13 +185,13 @@ public class CraftingTreeProcess
|
||||
|
||||
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) this.world ), this.details.getOutput( ic, this.world ), ic );
|
||||
|
||||
for (int x = 0; x < ic.getSizeInventory(); x++)
|
||||
for( int x = 0; x < ic.getSizeInventory(); x++ )
|
||||
{
|
||||
ItemStack is = ic.getStackInSlot( x );
|
||||
is = Platform.getContainerItem( is );
|
||||
|
||||
IAEItemStack o = AEApi.instance().storage().createItemStack( is );
|
||||
if ( o != null )
|
||||
if( o != null )
|
||||
{
|
||||
this.bytes++;
|
||||
inv.injectItems( o, Actionable.MODULATE, src );
|
||||
@@ -228,16 +201,16 @@ public class CraftingTreeProcess
|
||||
else
|
||||
{
|
||||
// request and remove inputs...
|
||||
for (Entry<CraftingTreeNode, Long> entry : this.nodes.entrySet())
|
||||
for( Entry<CraftingTreeNode, Long> entry : this.nodes.entrySet() )
|
||||
{
|
||||
IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
||||
IAEItemStack stack = entry.getKey().request( inv, item.getStackSize() * i, src );
|
||||
|
||||
if ( this.containerItems )
|
||||
if( this.containerItems )
|
||||
{
|
||||
ItemStack is = Platform.getContainerItem( stack.getItemStack() );
|
||||
IAEItemStack o = AEApi.instance().storage().createItemStack( is );
|
||||
if ( o != null )
|
||||
if( o != null )
|
||||
{
|
||||
this.bytes++;
|
||||
inv.injectItems( o, Actionable.MODULATE, src );
|
||||
@@ -249,7 +222,7 @@ public class CraftingTreeProcess
|
||||
// assume its possible.
|
||||
|
||||
// add crafting results..
|
||||
for (IAEItemStack out : this.details.getCondensedOutputs())
|
||||
for( IAEItemStack out : this.details.getCondensedOutputs() )
|
||||
{
|
||||
IAEItemStack o = out.copy();
|
||||
o.setStackSize( o.getStackSize() * i );
|
||||
@@ -259,42 +232,68 @@ public class CraftingTreeProcess
|
||||
this.crafts += i;
|
||||
}
|
||||
|
||||
public void dive(CraftingJob job)
|
||||
public void dive( CraftingJob job )
|
||||
{
|
||||
job.addTask( this.getAmountCrafted( this.parent.getStack( 1 ) ), this.crafts, this.details, this.depth );
|
||||
for (CraftingTreeNode pro : this.nodes.keySet())
|
||||
for( CraftingTreeNode pro : this.nodes.keySet() )
|
||||
pro.dive( job );
|
||||
|
||||
job.addBytes( 8 + this.crafts + this.bytes );
|
||||
}
|
||||
|
||||
IAEItemStack getAmountCrafted( IAEItemStack what2 )
|
||||
{
|
||||
for( IAEItemStack is : this.details.getCondensedOutputs() )
|
||||
{
|
||||
if( is.equals( what2 ) )
|
||||
{
|
||||
what2 = what2.copy();
|
||||
what2.setStackSize( is.getStackSize() );
|
||||
return what2;
|
||||
}
|
||||
}
|
||||
|
||||
// more fuzzy!
|
||||
for( IAEItemStack is : this.details.getCondensedOutputs() )
|
||||
{
|
||||
if( is.getItem() == what2.getItem() && ( is.getItem().isDamageable() || is.getItemDamage() == what2.getItemDamage() ) )
|
||||
{
|
||||
what2 = is.copy();
|
||||
what2.setStackSize( is.getStackSize() );
|
||||
return what2;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException( "Crafting Tree construction failed." );
|
||||
}
|
||||
|
||||
public void setSimulate()
|
||||
{
|
||||
this.crafts = 0;
|
||||
this.bytes = 0;
|
||||
|
||||
for (CraftingTreeNode pro : this.nodes.keySet())
|
||||
for( CraftingTreeNode pro : this.nodes.keySet() )
|
||||
pro.setSimulate();
|
||||
}
|
||||
|
||||
public void setJob(MECraftingInventory storage, CraftingCPUCluster craftingCPUCluster, BaseActionSource src) throws CraftBranchFailure
|
||||
public void setJob( MECraftingInventory storage, CraftingCPUCluster craftingCPUCluster, BaseActionSource src ) throws CraftBranchFailure
|
||||
{
|
||||
craftingCPUCluster.addCrafting( this.details, this.crafts );
|
||||
|
||||
for (CraftingTreeNode pro : this.nodes.keySet())
|
||||
for( CraftingTreeNode pro : this.nodes.keySet() )
|
||||
pro.setJob( storage, craftingCPUCluster, src );
|
||||
}
|
||||
|
||||
public void getPlan(IItemList<IAEItemStack> plan)
|
||||
public void getPlan( IItemList<IAEItemStack> plan )
|
||||
{
|
||||
for (IAEItemStack i : this.details.getOutputs())
|
||||
for( IAEItemStack i : this.details.getOutputs() )
|
||||
{
|
||||
i = i.copy();
|
||||
i.setCountRequestable( i.getStackSize() * this.crafts );
|
||||
plan.addRequestable( i );
|
||||
}
|
||||
|
||||
for (CraftingTreeNode pro : this.nodes.keySet())
|
||||
for( CraftingTreeNode pro : this.nodes.keySet() )
|
||||
pro.getPlan( plan );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -27,12 +28,134 @@ import appeng.api.networking.crafting.ICraftingWatcherHost;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
|
||||
|
||||
/**
|
||||
* Maintain my interests, and a global watch list, they should always be fully synchronized.
|
||||
*/
|
||||
public class CraftingWatcher implements ICraftingWatcher
|
||||
{
|
||||
|
||||
final CraftingGridCache gsc;
|
||||
final ICraftingWatcherHost host;
|
||||
final HashSet<IAEStack> myInterests = new HashSet<IAEStack>();
|
||||
|
||||
public CraftingWatcher( CraftingGridCache cache, ICraftingWatcherHost host )
|
||||
{
|
||||
this.gsc = cache;
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public ICraftingWatcherHost getHost()
|
||||
{
|
||||
return this.host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.myInterests.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.myInterests.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains( Object o )
|
||||
{
|
||||
return this.myInterests.contains( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEStack> iterator()
|
||||
{
|
||||
return new ItemWatcherIterator( this, this.myInterests.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray()
|
||||
{
|
||||
return this.myInterests.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray( T[] a )
|
||||
{
|
||||
return this.myInterests.toArray( a );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add( IAEStack e )
|
||||
{
|
||||
if( this.myInterests.contains( e ) )
|
||||
return false;
|
||||
|
||||
return this.myInterests.add( e.copy() ) && this.gsc.interestManager.put( e, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove( Object o )
|
||||
{
|
||||
return this.myInterests.remove( o ) && this.gsc.interestManager.remove( (IAEStack) o, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll( Collection<?> c )
|
||||
{
|
||||
return this.myInterests.containsAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll( Collection<? extends IAEStack> c )
|
||||
{
|
||||
boolean didChange = false;
|
||||
|
||||
for( IAEStack o : c )
|
||||
didChange = this.add( o ) || didChange;
|
||||
|
||||
return didChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll( Collection<?> c )
|
||||
{
|
||||
boolean didSomething = false;
|
||||
for( Object o : c )
|
||||
didSomething = this.remove( o ) || didSomething;
|
||||
return didSomething;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll( Collection<?> c )
|
||||
{
|
||||
boolean changed = false;
|
||||
Iterator<IAEStack> i = this.iterator();
|
||||
|
||||
while( i.hasNext() )
|
||||
{
|
||||
if( !c.contains( i.next() ) )
|
||||
{
|
||||
i.remove();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
Iterator<IAEStack> i = this.myInterests.iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
this.gsc.interestManager.remove( i.next(), this );
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
class ItemWatcherIterator implements Iterator<IAEStack>
|
||||
{
|
||||
|
||||
@@ -40,7 +163,8 @@ public class CraftingWatcher implements ICraftingWatcher
|
||||
final Iterator<IAEStack> interestIterator;
|
||||
IAEStack myLast;
|
||||
|
||||
public ItemWatcherIterator(CraftingWatcher parent, Iterator<IAEStack> i) {
|
||||
public ItemWatcherIterator( CraftingWatcher parent, Iterator<IAEStack> i )
|
||||
{
|
||||
this.watcher = parent;
|
||||
this.interestIterator = i;
|
||||
}
|
||||
@@ -63,127 +187,5 @@ public class CraftingWatcher implements ICraftingWatcher
|
||||
CraftingWatcher.this.gsc.interestManager.remove( this.myLast, this.watcher );
|
||||
this.interestIterator.remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final CraftingGridCache gsc;
|
||||
final ICraftingWatcherHost host;
|
||||
final HashSet<IAEStack> myInterests = new HashSet<IAEStack>();
|
||||
|
||||
public CraftingWatcher(CraftingGridCache cache, ICraftingWatcherHost host) {
|
||||
this.gsc = cache;
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public ICraftingWatcherHost getHost()
|
||||
{
|
||||
return this.host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(IAEStack e)
|
||||
{
|
||||
if ( this.myInterests.contains( e ) )
|
||||
return false;
|
||||
|
||||
return this.myInterests.add( e.copy() ) && this.gsc.interestManager.put( e, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends IAEStack> c)
|
||||
{
|
||||
boolean didChange = false;
|
||||
|
||||
for (IAEStack o : c)
|
||||
didChange = this.add( o ) || didChange;
|
||||
|
||||
return didChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
Iterator<IAEStack> i = this.myInterests.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
this.gsc.interestManager.remove( i.next(), this );
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o)
|
||||
{
|
||||
return this.myInterests.contains( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c)
|
||||
{
|
||||
return this.myInterests.containsAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.myInterests.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEStack> iterator()
|
||||
{
|
||||
return new ItemWatcherIterator( this, this.myInterests.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o)
|
||||
{
|
||||
return this.myInterests.remove( o ) && this.gsc.interestManager.remove( (IAEStack) o, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c)
|
||||
{
|
||||
boolean didSomething = false;
|
||||
for (Object o : c)
|
||||
didSomething = this.remove( o ) || didSomething;
|
||||
return didSomething;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c)
|
||||
{
|
||||
boolean changed = false;
|
||||
Iterator<IAEStack> i = this.iterator();
|
||||
|
||||
while (i.hasNext())
|
||||
{
|
||||
if ( !c.contains( i.next() ) )
|
||||
{
|
||||
i.remove();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.myInterests.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray()
|
||||
{
|
||||
return this.myInterests.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a)
|
||||
{
|
||||
return this.myInterests.toArray( a );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
@@ -27,6 +28,7 @@ import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
|
||||
public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
{
|
||||
|
||||
@@ -57,24 +59,24 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
this.par = null;
|
||||
}
|
||||
|
||||
public MECraftingInventory(MECraftingInventory parent)
|
||||
public MECraftingInventory( MECraftingInventory parent )
|
||||
{
|
||||
this.target = parent;
|
||||
this.logExtracted = parent.logExtracted;
|
||||
this.logInjections = parent.logInjections;
|
||||
this.logMissing = parent.logMissing;
|
||||
|
||||
if ( this.logMissing )
|
||||
if( this.logMissing )
|
||||
this.missingCache = AEApi.instance().storage().createItemList();
|
||||
else
|
||||
this.missingCache = null;
|
||||
|
||||
if ( this.logExtracted )
|
||||
if( this.logExtracted )
|
||||
this.extractedCache = AEApi.instance().storage().createItemList();
|
||||
else
|
||||
this.extractedCache = null;
|
||||
|
||||
if ( this.logInjections )
|
||||
if( this.logInjections )
|
||||
this.injectedCache = AEApi.instance().storage().createItemList();
|
||||
else
|
||||
this.injectedCache = null;
|
||||
@@ -84,53 +86,53 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
this.par = parent;
|
||||
}
|
||||
|
||||
public MECraftingInventory(IMEMonitor<IAEItemStack> target, BaseActionSource src, boolean logExtracted, boolean logInjections, boolean logMissing)
|
||||
public MECraftingInventory( IMEMonitor<IAEItemStack> target, BaseActionSource src, boolean logExtracted, boolean logInjections, boolean logMissing )
|
||||
{
|
||||
this.target = target;
|
||||
this.logExtracted = logExtracted;
|
||||
this.logInjections = logInjections;
|
||||
this.logMissing = logMissing;
|
||||
|
||||
if ( logMissing )
|
||||
if( logMissing )
|
||||
this.missingCache = AEApi.instance().storage().createItemList();
|
||||
else
|
||||
this.missingCache = null;
|
||||
|
||||
if ( logExtracted )
|
||||
if( logExtracted )
|
||||
this.extractedCache = AEApi.instance().storage().createItemList();
|
||||
else
|
||||
this.extractedCache = null;
|
||||
|
||||
if ( logInjections )
|
||||
if( logInjections )
|
||||
this.injectedCache = AEApi.instance().storage().createItemList();
|
||||
else
|
||||
this.injectedCache = null;
|
||||
|
||||
this.localCache = AEApi.instance().storage().createItemList();
|
||||
for (IAEItemStack is : target.getStorageList())
|
||||
for( IAEItemStack is : target.getStorageList() )
|
||||
this.localCache.add( target.extractItems( is, Actionable.SIMULATE, src ) );
|
||||
|
||||
this.par = null;
|
||||
}
|
||||
|
||||
public MECraftingInventory(IMEInventory<IAEItemStack> target, boolean logExtracted, boolean logInjections, boolean logMissing)
|
||||
public MECraftingInventory( IMEInventory<IAEItemStack> target, boolean logExtracted, boolean logInjections, boolean logMissing )
|
||||
{
|
||||
this.target = target;
|
||||
this.logExtracted = logExtracted;
|
||||
this.logInjections = logInjections;
|
||||
this.logMissing = logMissing;
|
||||
|
||||
if ( logMissing )
|
||||
if( logMissing )
|
||||
this.missingCache = AEApi.instance().storage().createItemList();
|
||||
else
|
||||
this.missingCache = null;
|
||||
|
||||
if ( logExtracted )
|
||||
if( logExtracted )
|
||||
this.extractedCache = AEApi.instance().storage().createItemList();
|
||||
else
|
||||
this.extractedCache = null;
|
||||
|
||||
if ( logInjections )
|
||||
if( logInjections )
|
||||
this.injectedCache = AEApi.instance().storage().createItemList();
|
||||
else
|
||||
this.injectedCache = null;
|
||||
@@ -140,14 +142,14 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack input, Actionable mode, BaseActionSource src)
|
||||
public IAEItemStack injectItems( IAEItemStack input, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
if ( input == null )
|
||||
if( input == null )
|
||||
return null;
|
||||
|
||||
if ( mode == Actionable.MODULATE )
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
if ( this.logInjections )
|
||||
if( this.logInjections )
|
||||
this.injectedCache.add( input );
|
||||
this.localCache.add( input );
|
||||
}
|
||||
@@ -156,21 +158,21 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src)
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
if ( request == null )
|
||||
if( request == null )
|
||||
return null;
|
||||
|
||||
IAEItemStack list = this.localCache.findPrecise( request );
|
||||
if ( list == null || list.getStackSize() == 0 )
|
||||
if( list == null || list.getStackSize() == 0 )
|
||||
return null;
|
||||
|
||||
if ( list.getStackSize() >= request.getStackSize() )
|
||||
if( list.getStackSize() >= request.getStackSize() )
|
||||
{
|
||||
if ( mode == Actionable.MODULATE )
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
list.decStackSize( request.getStackSize() );
|
||||
if ( this.logExtracted )
|
||||
if( this.logExtracted )
|
||||
this.extractedCache.add( request );
|
||||
}
|
||||
|
||||
@@ -180,10 +182,10 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
IAEItemStack ret = request.copy();
|
||||
ret.setStackSize( list.getStackSize() );
|
||||
|
||||
if ( mode == Actionable.MODULATE )
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
list.reset();
|
||||
if ( this.logExtracted )
|
||||
if( this.logExtracted )
|
||||
this.extractedCache.add( ret );
|
||||
}
|
||||
|
||||
@@ -191,39 +193,39 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out)
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||
{
|
||||
for (IAEItemStack is : this.localCache)
|
||||
for( IAEItemStack is : this.localCache )
|
||||
out.add( is );
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public IItemList<IAEItemStack> getItemList()
|
||||
{
|
||||
return this.localCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
public boolean commit(BaseActionSource src)
|
||||
public IItemList<IAEItemStack> getItemList()
|
||||
{
|
||||
return this.localCache;
|
||||
}
|
||||
|
||||
public boolean commit( BaseActionSource src )
|
||||
{
|
||||
IItemList<IAEItemStack> added = AEApi.instance().storage().createItemList();
|
||||
IItemList<IAEItemStack> pulled = AEApi.instance().storage().createItemList();
|
||||
boolean failed = false;
|
||||
|
||||
if ( this.logInjections )
|
||||
if( this.logInjections )
|
||||
{
|
||||
for (IAEItemStack inject : this.injectedCache)
|
||||
for( IAEItemStack inject : this.injectedCache )
|
||||
{
|
||||
IAEItemStack result = null;
|
||||
added.add( result = this.target.injectItems( inject, Actionable.MODULATE, src ) );
|
||||
|
||||
if ( result != null )
|
||||
if( result != null )
|
||||
{
|
||||
failed = true;
|
||||
break;
|
||||
@@ -231,22 +233,22 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
}
|
||||
}
|
||||
|
||||
if ( failed )
|
||||
if( failed )
|
||||
{
|
||||
for (IAEItemStack is : added)
|
||||
for( IAEItemStack is : added )
|
||||
this.target.extractItems( is, Actionable.MODULATE, src );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( this.logExtracted )
|
||||
if( this.logExtracted )
|
||||
{
|
||||
for (IAEItemStack extra : this.extractedCache)
|
||||
for( IAEItemStack extra : this.extractedCache )
|
||||
{
|
||||
IAEItemStack result = null;
|
||||
pulled.add( result = this.target.extractItems( extra, Actionable.MODULATE, src ) );
|
||||
|
||||
if ( result == null || result.getStackSize() != extra.getStackSize() )
|
||||
if( result == null || result.getStackSize() != extra.getStackSize() )
|
||||
{
|
||||
failed = true;
|
||||
break;
|
||||
@@ -254,35 +256,35 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
}
|
||||
}
|
||||
|
||||
if ( failed )
|
||||
if( failed )
|
||||
{
|
||||
for (IAEItemStack is : added)
|
||||
for( IAEItemStack is : added )
|
||||
this.target.extractItems( is, Actionable.MODULATE, src );
|
||||
|
||||
for (IAEItemStack is : pulled)
|
||||
for( IAEItemStack is : pulled )
|
||||
this.target.injectItems( is, Actionable.MODULATE, src );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( this.logMissing && this.par != null )
|
||||
if( this.logMissing && this.par != null )
|
||||
{
|
||||
for (IAEItemStack extra : this.missingCache)
|
||||
for( IAEItemStack extra : this.missingCache )
|
||||
this.par.addMissing( extra );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addMissing(IAEItemStack extra)
|
||||
public void addMissing( IAEItemStack extra )
|
||||
{
|
||||
this.missingCache.add( extra );
|
||||
}
|
||||
|
||||
public void ignore(IAEItemStack what)
|
||||
public void ignore( IAEItemStack what )
|
||||
{
|
||||
IAEItemStack list = this.localCache.findPrecise( what );
|
||||
if ( list != null )
|
||||
if( list != null )
|
||||
list.setStackSize( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user