reformatted all src files (#141)
This commit is contained in:
@@ -22,17 +22,15 @@ package appeng.crafting;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
|
||||
public class CraftBranchFailure extends Exception
|
||||
{
|
||||
public class CraftBranchFailure extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 654603652836724823L;
|
||||
private static final long serialVersionUID = 654603652836724823L;
|
||||
|
||||
private final IAEItemStack missing;
|
||||
private final IAEItemStack missing;
|
||||
|
||||
public CraftBranchFailure( final IAEItemStack what, final long howMany )
|
||||
{
|
||||
super( "Failed: " + what.getItem().getUnlocalizedName() + " x " + howMany );
|
||||
this.missing = what.copy();
|
||||
this.missing.setStackSize( howMany );
|
||||
}
|
||||
public CraftBranchFailure(final IAEItemStack what, final long howMany) {
|
||||
super("Failed: " + what.getItem().getUnlocalizedName() + " x " + howMany);
|
||||
this.missing = what.copy();
|
||||
this.missing.setStackSize(howMany);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,17 +22,15 @@ package appeng.crafting;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
|
||||
public class CraftingCalculationFailure extends RuntimeException
|
||||
{
|
||||
public class CraftingCalculationFailure extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 654603652836724823L;
|
||||
private static final long serialVersionUID = 654603652836724823L;
|
||||
|
||||
private final IAEItemStack missing;
|
||||
private final IAEItemStack missing;
|
||||
|
||||
public CraftingCalculationFailure( final IAEItemStack what, final long howMany )
|
||||
{
|
||||
super( "this should have been caught!" );
|
||||
this.missing = what.copy();
|
||||
this.missing.setStackSize( howMany );
|
||||
}
|
||||
public CraftingCalculationFailure(final IAEItemStack what, final long howMany) {
|
||||
super("this should have been caught!");
|
||||
this.missing = what.copy();
|
||||
this.missing.setStackSize(howMany);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,358 +46,290 @@ import java.util.HashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
public class CraftingJob implements Runnable, ICraftingJob
|
||||
{
|
||||
private static final String LOG_CRAFTING_JOB = "CraftingJob (%s) issued by %s requesting [%s] using %s bytes took %s us";
|
||||
private static final String LOG_MACHINE_SOURCE_DETAILS = "Machine[object=%s, %s]";
|
||||
public class CraftingJob implements Runnable, ICraftingJob {
|
||||
private static final String LOG_CRAFTING_JOB = "CraftingJob (%s) issued by %s requesting [%s] using %s bytes took %s us";
|
||||
private static final String LOG_MACHINE_SOURCE_DETAILS = "Machine[object=%s, %s]";
|
||||
|
||||
private final MECraftingInventory original;
|
||||
private final World world;
|
||||
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 MECraftingInventory original;
|
||||
private final World world;
|
||||
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 HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<>();
|
||||
private final Object monitor = new Object();
|
||||
private final Stopwatch tickSpreadingWatch = Stopwatch.createUnstarted();
|
||||
private final Stopwatch craftingTreeWatch = Stopwatch.createUnstarted();
|
||||
private final ICraftingGrid cc;
|
||||
private CraftingTreeNode tree;
|
||||
private final IAEItemStack output;
|
||||
private boolean simulate = false;
|
||||
private MECraftingInventory availableCheck;
|
||||
private long bytes = 0;
|
||||
private final IActionSource actionSrc;
|
||||
private final ICraftingCallback callback;
|
||||
private boolean running = false;
|
||||
private boolean done = false;
|
||||
private int time;
|
||||
private int incTime;
|
||||
private final HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<>();
|
||||
private final Object monitor = new Object();
|
||||
private final Stopwatch tickSpreadingWatch = Stopwatch.createUnstarted();
|
||||
private final Stopwatch craftingTreeWatch = Stopwatch.createUnstarted();
|
||||
private final ICraftingGrid cc;
|
||||
private CraftingTreeNode tree;
|
||||
private final IAEItemStack output;
|
||||
private boolean simulate = false;
|
||||
private MECraftingInventory availableCheck;
|
||||
private long bytes = 0;
|
||||
private final IActionSource actionSrc;
|
||||
private final ICraftingCallback callback;
|
||||
private boolean running = false;
|
||||
private boolean done = false;
|
||||
private int time;
|
||||
private int incTime;
|
||||
|
||||
private World wrapWorld( final World w )
|
||||
{
|
||||
return w;
|
||||
}
|
||||
private World wrapWorld(final World w) {
|
||||
return w;
|
||||
}
|
||||
|
||||
public CraftingJob( final World w, final IGrid grid, final IActionSource actionSrc, final IAEItemStack what, final ICraftingCallback callback )
|
||||
{
|
||||
this.world = this.wrapWorld( w );
|
||||
this.output = what.copy();
|
||||
this.actionSrc = actionSrc;
|
||||
public CraftingJob(final World w, final IGrid grid, final IActionSource actionSrc, final IAEItemStack what, final ICraftingCallback callback) {
|
||||
this.world = this.wrapWorld(w);
|
||||
this.output = what.copy();
|
||||
this.actionSrc = actionSrc;
|
||||
|
||||
this.callback = callback;
|
||||
this.callback = callback;
|
||||
|
||||
this.cc = grid.getCache( ICraftingGrid.class );
|
||||
final GridStorageCache sg = grid.getCache( IStorageGrid.class );
|
||||
this.original = new MECraftingInventory( sg.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).getStorageList() );
|
||||
this.cc = grid.getCache(ICraftingGrid.class);
|
||||
final GridStorageCache sg = grid.getCache(IStorageGrid.class);
|
||||
this.original = new MECraftingInventory(sg.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)).getStorageList());
|
||||
|
||||
this.setTree( this.getCraftingTree( cc, what ) );
|
||||
this.availableCheck = null;
|
||||
}
|
||||
this.setTree(this.getCraftingTree(cc, what));
|
||||
this.availableCheck = null;
|
||||
}
|
||||
|
||||
private CraftingTreeNode getCraftingTree( final ICraftingGrid cc, final IAEItemStack what )
|
||||
{
|
||||
return new CraftingTreeNode( cc, this, what, null, -1, 0 );
|
||||
}
|
||||
private CraftingTreeNode getCraftingTree(final ICraftingGrid cc, final IAEItemStack what) {
|
||||
return new CraftingTreeNode(cc, this, what, null, -1, 0);
|
||||
}
|
||||
|
||||
void refund( final IAEItemStack o )
|
||||
{
|
||||
this.availableCheck.injectItems( o, Actionable.MODULATE, this.actionSrc );
|
||||
}
|
||||
void refund(final IAEItemStack o) {
|
||||
this.availableCheck.injectItems(o, Actionable.MODULATE, this.actionSrc);
|
||||
}
|
||||
|
||||
IAEItemStack checkUse( final IAEItemStack available )
|
||||
{
|
||||
return this.availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc );
|
||||
}
|
||||
IAEItemStack checkUse(final IAEItemStack available) {
|
||||
return this.availableCheck.extractItems(available, Actionable.MODULATE, this.actionSrc);
|
||||
}
|
||||
|
||||
IAEItemStack checkAvailable( final IAEItemStack available )
|
||||
{
|
||||
return this.availableCheck.extractItems( available, Actionable.SIMULATE, this.actionSrc );
|
||||
}
|
||||
IAEItemStack checkAvailable(final IAEItemStack available) {
|
||||
return this.availableCheck.extractItems(available, Actionable.SIMULATE, this.actionSrc);
|
||||
}
|
||||
|
||||
void addTask( IAEItemStack what, final long crafts, final ICraftingPatternDetails details, final int depth )
|
||||
{
|
||||
if( crafts > 0 )
|
||||
{
|
||||
what = what.copy();
|
||||
what.setStackSize( what.getStackSize() * crafts );
|
||||
this.crafting.add( what );
|
||||
}
|
||||
}
|
||||
void addTask(IAEItemStack what, final long crafts, final ICraftingPatternDetails details, final int depth) {
|
||||
if (crafts > 0) {
|
||||
what = what.copy();
|
||||
what.setStackSize(what.getStackSize() * crafts);
|
||||
this.crafting.add(what);
|
||||
}
|
||||
}
|
||||
|
||||
void addMissing( IAEItemStack what )
|
||||
{
|
||||
what = what.copy();
|
||||
this.missing.add( what );
|
||||
}
|
||||
void addMissing(IAEItemStack what) {
|
||||
what = what.copy();
|
||||
this.missing.add(what);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
TickHandler.INSTANCE.registerCraftingSimulation( this.world, this );
|
||||
this.handlePausing();
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
try {
|
||||
TickHandler.INSTANCE.registerCraftingSimulation(this.world, this);
|
||||
this.handlePausing();
|
||||
|
||||
final MECraftingInventory craftingInventory = new MECraftingInventory( this.original, true, false, true );
|
||||
craftingInventory.ignore( this.output );
|
||||
final MECraftingInventory craftingInventory = new MECraftingInventory(this.original, true, false, true);
|
||||
craftingInventory.ignore(this.output);
|
||||
|
||||
this.availableCheck = new MECraftingInventory( this.original, false, false, false );
|
||||
craftingTreeWatch.start();
|
||||
this.getTree().request( craftingInventory, this.output.getStackSize(), this.actionSrc );
|
||||
craftingTreeWatch.stop();
|
||||
this.getTree().dive( this );
|
||||
this.availableCheck = new MECraftingInventory(this.original, false, false, false);
|
||||
craftingTreeWatch.start();
|
||||
this.getTree().request(craftingInventory, this.output.getStackSize(), this.actionSrc);
|
||||
craftingTreeWatch.stop();
|
||||
this.getTree().dive(this);
|
||||
|
||||
for( final String s : this.opsAndMultiplier.keySet() )
|
||||
{
|
||||
final TwoIntegers ti = this.opsAndMultiplier.get( s );
|
||||
AELog.crafting( s + " * " + ti.times + " = " + ( ti.perOp * ti.times ) );
|
||||
}
|
||||
for (final String s : this.opsAndMultiplier.keySet()) {
|
||||
final TwoIntegers ti = this.opsAndMultiplier.get(s);
|
||||
AELog.crafting(s + " * " + ti.times + " = " + (ti.perOp * ti.times));
|
||||
}
|
||||
|
||||
if( actionSrc.player().isPresent() )
|
||||
{
|
||||
this.logCraftingJob( "simulated, success", craftingTreeWatch );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.logCraftingJob( "real, success", craftingTreeWatch );
|
||||
}
|
||||
}
|
||||
catch( final CraftBranchFailure e )
|
||||
{
|
||||
this.simulate = true;
|
||||
if (actionSrc.player().isPresent()) {
|
||||
this.logCraftingJob("simulated, success", craftingTreeWatch);
|
||||
} else {
|
||||
this.logCraftingJob("real, success", craftingTreeWatch);
|
||||
}
|
||||
} catch (final CraftBranchFailure e) {
|
||||
this.simulate = true;
|
||||
|
||||
try
|
||||
{
|
||||
if( actionSrc.player().isPresent() )
|
||||
{
|
||||
final MECraftingInventory craftingInventory = new MECraftingInventory( this.original, true, false, true );
|
||||
craftingInventory.ignore( this.output );
|
||||
try {
|
||||
if (actionSrc.player().isPresent()) {
|
||||
final MECraftingInventory craftingInventory = new MECraftingInventory(this.original, true, false, true);
|
||||
craftingInventory.ignore(this.output);
|
||||
|
||||
this.getTree().setSimulate();
|
||||
this.availableCheck = new MECraftingInventory( this.original, false, false, false );
|
||||
craftingTreeWatch.reset().start();
|
||||
this.getTree().request( craftingInventory, this.output.getStackSize(), this.actionSrc );
|
||||
craftingTreeWatch.stop();
|
||||
this.getTree().dive( this );
|
||||
this.getTree().setSimulate();
|
||||
this.availableCheck = new MECraftingInventory(this.original, false, false, false);
|
||||
craftingTreeWatch.reset().start();
|
||||
this.getTree().request(craftingInventory, this.output.getStackSize(), this.actionSrc);
|
||||
craftingTreeWatch.stop();
|
||||
this.getTree().dive(this);
|
||||
|
||||
for( final String s : this.opsAndMultiplier.keySet() )
|
||||
{
|
||||
final TwoIntegers ti = this.opsAndMultiplier.get( s );
|
||||
AELog.crafting( s + " * " + ti.times + " = " + ( ti.perOp * ti.times ) );
|
||||
}
|
||||
for (final String s : this.opsAndMultiplier.keySet()) {
|
||||
final TwoIntegers ti = this.opsAndMultiplier.get(s);
|
||||
AELog.crafting(s + " * " + ti.times + " = " + (ti.perOp * ti.times));
|
||||
}
|
||||
|
||||
this.logCraftingJob( "simulated, failed", craftingTreeWatch );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.logCraftingJob( "real, failed", craftingTreeWatch );
|
||||
}
|
||||
}
|
||||
catch( final CraftBranchFailure e1 )
|
||||
{
|
||||
AELog.debug( e1 );
|
||||
}
|
||||
catch( final CraftingCalculationFailure f )
|
||||
{
|
||||
AELog.debug( f );
|
||||
}
|
||||
catch( final InterruptedException e1 )
|
||||
{
|
||||
AELog.crafting( "Crafting calculation canceled." );
|
||||
this.finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch( final CraftingCalculationFailure f )
|
||||
{
|
||||
AELog.debug( f );
|
||||
}
|
||||
catch( final InterruptedException e1 )
|
||||
{
|
||||
AELog.crafting( "Crafting calculation canceled." );
|
||||
this.finish();
|
||||
return;
|
||||
}
|
||||
this.logCraftingJob("simulated, failed", craftingTreeWatch);
|
||||
} else {
|
||||
this.logCraftingJob("real, failed", craftingTreeWatch);
|
||||
}
|
||||
} catch (final CraftBranchFailure e1) {
|
||||
AELog.debug(e1);
|
||||
} catch (final CraftingCalculationFailure f) {
|
||||
AELog.debug(f);
|
||||
} catch (final InterruptedException e1) {
|
||||
AELog.crafting("Crafting calculation canceled.");
|
||||
this.finish();
|
||||
return;
|
||||
}
|
||||
} catch (final CraftingCalculationFailure f) {
|
||||
AELog.debug(f);
|
||||
} catch (final InterruptedException e1) {
|
||||
AELog.crafting("Crafting calculation canceled.");
|
||||
this.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
AELog.craftingDebug( "crafting job now done" );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
this.finish();
|
||||
throw new IllegalStateException( t );
|
||||
}
|
||||
AELog.craftingDebug("crafting job now done");
|
||||
} catch (final Throwable t) {
|
||||
this.finish();
|
||||
throw new IllegalStateException(t);
|
||||
}
|
||||
|
||||
this.finish();
|
||||
}
|
||||
this.finish();
|
||||
}
|
||||
|
||||
void handlePausing() throws InterruptedException
|
||||
{
|
||||
if( !this.actionSrc.player().isPresent() && this.incTime > 100 )
|
||||
{
|
||||
this.incTime = 0;
|
||||
synchronized ( this.monitor )
|
||||
{
|
||||
if( this.tickSpreadingWatch.elapsed( TimeUnit.MICROSECONDS ) > this.time )
|
||||
{
|
||||
this.running = false;
|
||||
this.craftingTreeWatch.stop();
|
||||
this.tickSpreadingWatch.stop();
|
||||
this.monitor.notify();
|
||||
}
|
||||
void handlePausing() throws InterruptedException {
|
||||
if (!this.actionSrc.player().isPresent() && this.incTime > 100) {
|
||||
this.incTime = 0;
|
||||
synchronized (this.monitor) {
|
||||
if (this.tickSpreadingWatch.elapsed(TimeUnit.MICROSECONDS) > this.time) {
|
||||
this.running = false;
|
||||
this.craftingTreeWatch.stop();
|
||||
this.tickSpreadingWatch.stop();
|
||||
this.monitor.notify();
|
||||
}
|
||||
|
||||
if( !this.running )
|
||||
{
|
||||
AELog.craftingDebug( "crafting job will now sleep" );
|
||||
if (!this.running) {
|
||||
AELog.craftingDebug("crafting job will now sleep");
|
||||
|
||||
while ( !this.running )
|
||||
{
|
||||
this.monitor.wait();
|
||||
}
|
||||
while (!this.running) {
|
||||
this.monitor.wait();
|
||||
}
|
||||
|
||||
AELog.craftingDebug( "crafting job now active" );
|
||||
}
|
||||
}
|
||||
}
|
||||
AELog.craftingDebug("crafting job now active");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( Thread.interrupted() )
|
||||
{
|
||||
throw new InterruptedException();
|
||||
}
|
||||
if (Thread.interrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
this.incTime++;
|
||||
}
|
||||
this.incTime++;
|
||||
}
|
||||
|
||||
private void finish()
|
||||
{
|
||||
if( this.callback != null )
|
||||
{
|
||||
this.callback.calculationComplete( this );
|
||||
}
|
||||
private void finish() {
|
||||
if (this.callback != null) {
|
||||
this.callback.calculationComplete(this);
|
||||
}
|
||||
|
||||
this.availableCheck = null;
|
||||
this.availableCheck = null;
|
||||
|
||||
synchronized ( this.monitor )
|
||||
{
|
||||
this.running = false;
|
||||
this.done = true;
|
||||
this.monitor.notify();
|
||||
}
|
||||
}
|
||||
synchronized (this.monitor) {
|
||||
this.running = false;
|
||||
this.done = true;
|
||||
this.monitor.notify();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSimulation()
|
||||
{
|
||||
return this.simulate;
|
||||
}
|
||||
@Override
|
||||
public boolean isSimulation() {
|
||||
return this.simulate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getByteTotal()
|
||||
{
|
||||
return this.bytes;
|
||||
}
|
||||
@Override
|
||||
public long getByteTotal() {
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populatePlan( final IItemList<IAEItemStack> plan )
|
||||
{
|
||||
if( this.getTree() != null )
|
||||
{
|
||||
this.getTree().getPlan( plan );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void populatePlan(final IItemList<IAEItemStack> plan) {
|
||||
if (this.getTree() != null) {
|
||||
this.getTree().getPlan(plan);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack getOutput()
|
||||
{
|
||||
return this.output;
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack getOutput() {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
public boolean isDone()
|
||||
{
|
||||
return this.done;
|
||||
}
|
||||
public boolean isDone() {
|
||||
return this.done;
|
||||
}
|
||||
|
||||
World getWorld()
|
||||
{
|
||||
return this.world;
|
||||
}
|
||||
World getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this needs more simulation
|
||||
*/
|
||||
public boolean simulateFor( final int milli )
|
||||
{
|
||||
this.time = milli;
|
||||
/**
|
||||
* @return true if this needs more simulation
|
||||
*/
|
||||
public boolean simulateFor(final int milli) {
|
||||
this.time = milli;
|
||||
|
||||
synchronized ( this.monitor )
|
||||
{
|
||||
if( this.done )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( !this.actionSrc.player().isPresent() )
|
||||
{
|
||||
this.tickSpreadingWatch.reset();
|
||||
this.tickSpreadingWatch.start();
|
||||
this.monitor.notify();
|
||||
}
|
||||
this.running = true;
|
||||
}
|
||||
synchronized (this.monitor) {
|
||||
if (this.done) {
|
||||
return false;
|
||||
}
|
||||
if (!this.actionSrc.player().isPresent()) {
|
||||
this.tickSpreadingWatch.reset();
|
||||
this.tickSpreadingWatch.start();
|
||||
this.monitor.notify();
|
||||
}
|
||||
this.running = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void addBytes( final long crafts )
|
||||
{
|
||||
this.bytes += crafts;
|
||||
}
|
||||
void addBytes(final long crafts) {
|
||||
this.bytes += crafts;
|
||||
}
|
||||
|
||||
public CraftingTreeNode getTree()
|
||||
{
|
||||
return this.tree;
|
||||
}
|
||||
public CraftingTreeNode getTree() {
|
||||
return this.tree;
|
||||
}
|
||||
|
||||
private void setTree( final CraftingTreeNode tree )
|
||||
{
|
||||
this.tree = tree;
|
||||
}
|
||||
private void setTree(final CraftingTreeNode tree) {
|
||||
this.tree = tree;
|
||||
}
|
||||
|
||||
private void logCraftingJob( String type, Stopwatch timer )
|
||||
{
|
||||
if( AELog.isCraftingLogEnabled() )
|
||||
{
|
||||
final String itemToOutput = this.output.toString();
|
||||
final long elapsedTime = timer.elapsed( TimeUnit.MICROSECONDS );
|
||||
final String actionSource;
|
||||
private void logCraftingJob(String type, Stopwatch timer) {
|
||||
if (AELog.isCraftingLogEnabled()) {
|
||||
final String itemToOutput = this.output.toString();
|
||||
final long elapsedTime = timer.elapsed(TimeUnit.MICROSECONDS);
|
||||
final String actionSource;
|
||||
|
||||
if( this.actionSrc.player().isPresent() )
|
||||
{
|
||||
final EntityPlayer player = this.actionSrc.player().get();
|
||||
if (this.actionSrc.player().isPresent()) {
|
||||
final EntityPlayer player = this.actionSrc.player().get();
|
||||
|
||||
actionSource = player.toString();
|
||||
}
|
||||
else if( this.actionSrc.machine().isPresent() )
|
||||
{
|
||||
final IActionHost machineSource = this.actionSrc.machine().get();
|
||||
final IGridNode actionableNode = machineSource.getActionableNode();
|
||||
final IGridHost machine = actionableNode.getMachine();
|
||||
final DimensionalCoord location = actionableNode.getGridBlock().getLocation();
|
||||
actionSource = player.toString();
|
||||
} else if (this.actionSrc.machine().isPresent()) {
|
||||
final IActionHost machineSource = this.actionSrc.machine().get();
|
||||
final IGridNode actionableNode = machineSource.getActionableNode();
|
||||
final IGridHost machine = actionableNode.getMachine();
|
||||
final DimensionalCoord location = actionableNode.getGridBlock().getLocation();
|
||||
|
||||
actionSource = String.format( LOG_MACHINE_SOURCE_DETAILS, machine, location );
|
||||
}
|
||||
else
|
||||
{
|
||||
actionSource = "[unknown source]";
|
||||
}
|
||||
actionSource = String.format(LOG_MACHINE_SOURCE_DETAILS, machine, location);
|
||||
} else {
|
||||
actionSource = "[unknown source]";
|
||||
}
|
||||
|
||||
AELog.crafting( LOG_CRAFTING_JOB, type, actionSource, itemToOutput, this.bytes, elapsedTime );
|
||||
}
|
||||
}
|
||||
AELog.crafting(LOG_CRAFTING_JOB, type, actionSource, itemToOutput, this.bytes, elapsedTime);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TwoIntegers
|
||||
{
|
||||
private final long perOp = 0;
|
||||
private final long times = 0;
|
||||
}
|
||||
private static class TwoIntegers {
|
||||
private final long perOp = 0;
|
||||
private final long times = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,197 +19,165 @@
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.crafting.ICraftingCPU;
|
||||
import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
|
||||
public class CraftingLink implements ICraftingLink
|
||||
{
|
||||
public class CraftingLink implements ICraftingLink {
|
||||
|
||||
private final ICraftingRequester req;
|
||||
private final ICraftingCPU cpu;
|
||||
private final String CraftID;
|
||||
private final boolean standalone;
|
||||
private boolean canceled = false;
|
||||
private boolean done = false;
|
||||
private CraftingLinkNexus tie;
|
||||
private final ICraftingRequester req;
|
||||
private final ICraftingCPU cpu;
|
||||
private final String CraftID;
|
||||
private final boolean standalone;
|
||||
private boolean canceled = false;
|
||||
private boolean done = false;
|
||||
private CraftingLinkNexus tie;
|
||||
|
||||
public CraftingLink( final NBTTagCompound data, final ICraftingRequester req )
|
||||
{
|
||||
this.CraftID = data.getString( "CraftID" );
|
||||
this.setCanceled( data.getBoolean( "canceled" ) );
|
||||
this.setDone( data.getBoolean( "done" ) );
|
||||
this.standalone = data.getBoolean( "standalone" );
|
||||
public CraftingLink(final NBTTagCompound data, final ICraftingRequester req) {
|
||||
this.CraftID = data.getString("CraftID");
|
||||
this.setCanceled(data.getBoolean("canceled"));
|
||||
this.setDone(data.getBoolean("done"));
|
||||
this.standalone = data.getBoolean("standalone");
|
||||
|
||||
if( !data.hasKey( "req" ) || !data.getBoolean( "req" ) )
|
||||
{
|
||||
throw new IllegalStateException( "Invalid Crafting Link for Object" );
|
||||
}
|
||||
if (!data.hasKey("req") || !data.getBoolean("req")) {
|
||||
throw new IllegalStateException("Invalid Crafting Link for Object");
|
||||
}
|
||||
|
||||
this.req = req;
|
||||
this.cpu = null;
|
||||
}
|
||||
this.req = req;
|
||||
this.cpu = null;
|
||||
}
|
||||
|
||||
public CraftingLink( final NBTTagCompound data, final ICraftingCPU cpu )
|
||||
{
|
||||
this.CraftID = data.getString( "CraftID" );
|
||||
this.setCanceled( data.getBoolean( "canceled" ) );
|
||||
this.setDone( data.getBoolean( "done" ) );
|
||||
this.standalone = data.getBoolean( "standalone" );
|
||||
public CraftingLink(final NBTTagCompound data, final ICraftingCPU cpu) {
|
||||
this.CraftID = data.getString("CraftID");
|
||||
this.setCanceled(data.getBoolean("canceled"));
|
||||
this.setDone(data.getBoolean("done"));
|
||||
this.standalone = data.getBoolean("standalone");
|
||||
|
||||
if( !data.hasKey( "req" ) || data.getBoolean( "req" ) )
|
||||
{
|
||||
throw new IllegalStateException( "Invalid Crafting Link for Object" );
|
||||
}
|
||||
if (!data.hasKey("req") || data.getBoolean("req")) {
|
||||
throw new IllegalStateException("Invalid Crafting Link for Object");
|
||||
}
|
||||
|
||||
this.cpu = cpu;
|
||||
this.req = null;
|
||||
}
|
||||
this.cpu = cpu;
|
||||
this.req = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCanceled()
|
||||
{
|
||||
if( this.canceled )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isCanceled() {
|
||||
if (this.canceled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( this.done )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.done) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( this.tie == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.tie == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.tie.isCanceled();
|
||||
}
|
||||
return this.tie.isCanceled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone()
|
||||
{
|
||||
if( this.done )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
if (this.done) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( this.canceled )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.canceled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( this.tie == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.tie == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.tie.isDone();
|
||||
}
|
||||
return this.tie.isDone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel()
|
||||
{
|
||||
if( this.done )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void cancel() {
|
||||
if (this.done) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setCanceled( true );
|
||||
this.setCanceled(true);
|
||||
|
||||
if( this.tie != null )
|
||||
{
|
||||
this.tie.cancel();
|
||||
}
|
||||
if (this.tie != null) {
|
||||
this.tie.cancel();
|
||||
}
|
||||
|
||||
this.tie = null;
|
||||
}
|
||||
this.tie = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStandalone()
|
||||
{
|
||||
return this.standalone;
|
||||
}
|
||||
@Override
|
||||
public boolean isStandalone() {
|
||||
return this.standalone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound tag )
|
||||
{
|
||||
tag.setString( "CraftID", this.CraftID );
|
||||
tag.setBoolean( "canceled", this.isCanceled() );
|
||||
tag.setBoolean( "done", this.isDone() );
|
||||
tag.setBoolean( "standalone", this.standalone );
|
||||
tag.setBoolean( "req", this.getRequester() != null );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound tag) {
|
||||
tag.setString("CraftID", this.CraftID);
|
||||
tag.setBoolean("canceled", this.isCanceled());
|
||||
tag.setBoolean("done", this.isDone());
|
||||
tag.setBoolean("standalone", this.standalone);
|
||||
tag.setBoolean("req", this.getRequester() != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCraftingID()
|
||||
{
|
||||
return this.CraftID;
|
||||
}
|
||||
@Override
|
||||
public String getCraftingID() {
|
||||
return this.CraftID;
|
||||
}
|
||||
|
||||
public void setNexus( final CraftingLinkNexus n )
|
||||
{
|
||||
if( this.tie != null )
|
||||
{
|
||||
this.tie.remove( this );
|
||||
}
|
||||
public void setNexus(final CraftingLinkNexus n) {
|
||||
if (this.tie != null) {
|
||||
this.tie.remove(this);
|
||||
}
|
||||
|
||||
if( this.isCanceled() && n != null )
|
||||
{
|
||||
n.cancel();
|
||||
this.tie = null;
|
||||
return;
|
||||
}
|
||||
if (this.isCanceled() && n != null) {
|
||||
n.cancel();
|
||||
this.tie = null;
|
||||
return;
|
||||
}
|
||||
|
||||
this.tie = n;
|
||||
this.tie = n;
|
||||
|
||||
if( n != null )
|
||||
{
|
||||
n.add( this );
|
||||
}
|
||||
}
|
||||
if (n != null) {
|
||||
n.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode )
|
||||
{
|
||||
if( this.tie == null || this.tie.getRequest() == null || this.tie.getRequest().getRequester() == null )
|
||||
{
|
||||
return input;
|
||||
}
|
||||
public IAEItemStack injectItems(final IAEItemStack input, final Actionable mode) {
|
||||
if (this.tie == null || this.tie.getRequest() == null || this.tie.getRequest().getRequester() == null) {
|
||||
return input;
|
||||
}
|
||||
|
||||
return this.tie.getRequest().getRequester().injectCraftedItems( this.tie.getRequest(), input, mode );
|
||||
}
|
||||
return this.tie.getRequest().getRequester().injectCraftedItems(this.tie.getRequest(), input, mode);
|
||||
}
|
||||
|
||||
public void markDone()
|
||||
{
|
||||
if( this.tie != null )
|
||||
{
|
||||
this.tie.markDone();
|
||||
}
|
||||
}
|
||||
public void markDone() {
|
||||
if (this.tie != null) {
|
||||
this.tie.markDone();
|
||||
}
|
||||
}
|
||||
|
||||
void setCanceled( final boolean canceled )
|
||||
{
|
||||
this.canceled = canceled;
|
||||
}
|
||||
void setCanceled(final boolean canceled) {
|
||||
this.canceled = canceled;
|
||||
}
|
||||
|
||||
ICraftingRequester getRequester()
|
||||
{
|
||||
return this.req;
|
||||
}
|
||||
ICraftingRequester getRequester() {
|
||||
return this.req;
|
||||
}
|
||||
|
||||
ICraftingCPU getCpu()
|
||||
{
|
||||
return this.cpu;
|
||||
}
|
||||
ICraftingCPU getCpu() {
|
||||
return this.cpu;
|
||||
}
|
||||
|
||||
void setDone( final boolean done )
|
||||
{
|
||||
this.done = done;
|
||||
}
|
||||
void setDone(final boolean done) {
|
||||
this.done = done;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,151 +24,117 @@ import appeng.api.networking.IGridHost;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
|
||||
|
||||
public class CraftingLinkNexus
|
||||
{
|
||||
public class CraftingLinkNexus {
|
||||
|
||||
private final String craftID;
|
||||
private boolean canceled = false;
|
||||
private boolean done = false;
|
||||
private int tickOfDeath = 0;
|
||||
private CraftingLink req;
|
||||
private CraftingLink cpu;
|
||||
private final String craftID;
|
||||
private boolean canceled = false;
|
||||
private boolean done = false;
|
||||
private int tickOfDeath = 0;
|
||||
private CraftingLink req;
|
||||
private CraftingLink cpu;
|
||||
|
||||
public CraftingLinkNexus( final String craftID )
|
||||
{
|
||||
this.craftID = craftID;
|
||||
}
|
||||
public CraftingLinkNexus(final String craftID) {
|
||||
this.craftID = craftID;
|
||||
}
|
||||
|
||||
public boolean isDead( final IGrid g, final CraftingGridCache craftingGridCache )
|
||||
{
|
||||
if( this.canceled || this.done )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public boolean isDead(final IGrid g, final CraftingGridCache craftingGridCache) {
|
||||
if (this.canceled || this.done) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( this.getRequest() == null || this.cpu == null )
|
||||
{
|
||||
this.tickOfDeath++;
|
||||
}
|
||||
else
|
||||
{
|
||||
final boolean hasCpu = craftingGridCache.hasCpu( this.cpu.getCpu() );
|
||||
final boolean hasMachine = this.getRequest().getRequester().getActionableNode().getGrid() == g;
|
||||
if (this.getRequest() == null || this.cpu == null) {
|
||||
this.tickOfDeath++;
|
||||
} else {
|
||||
final boolean hasCpu = craftingGridCache.hasCpu(this.cpu.getCpu());
|
||||
final boolean hasMachine = this.getRequest().getRequester().getActionableNode().getGrid() == g;
|
||||
|
||||
if( hasCpu && hasMachine )
|
||||
{
|
||||
this.tickOfDeath = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tickOfDeath += 60;
|
||||
}
|
||||
}
|
||||
if (hasCpu && hasMachine) {
|
||||
this.tickOfDeath = 0;
|
||||
} else {
|
||||
this.tickOfDeath += 60;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.tickOfDeath > 60 )
|
||||
{
|
||||
this.cancel();
|
||||
return true;
|
||||
}
|
||||
if (this.tickOfDeath > 60) {
|
||||
this.cancel();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void cancel()
|
||||
{
|
||||
this.canceled = true;
|
||||
void cancel() {
|
||||
this.canceled = true;
|
||||
|
||||
if( this.getRequest() != null )
|
||||
{
|
||||
this.getRequest().setCanceled( true );
|
||||
if( this.getRequest().getRequester() != null )
|
||||
{
|
||||
this.getRequest().getRequester().jobStateChange( this.getRequest() );
|
||||
}
|
||||
}
|
||||
if (this.getRequest() != null) {
|
||||
this.getRequest().setCanceled(true);
|
||||
if (this.getRequest().getRequester() != null) {
|
||||
this.getRequest().getRequester().jobStateChange(this.getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
if( this.cpu != null )
|
||||
{
|
||||
this.cpu.setCanceled( true );
|
||||
}
|
||||
}
|
||||
if (this.cpu != null) {
|
||||
this.cpu.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void remove( final CraftingLink craftingLink )
|
||||
{
|
||||
if( this.getRequest() == craftingLink )
|
||||
{
|
||||
this.setRequest( null );
|
||||
}
|
||||
else if( this.cpu == craftingLink )
|
||||
{
|
||||
this.cpu = null;
|
||||
}
|
||||
}
|
||||
void remove(final CraftingLink craftingLink) {
|
||||
if (this.getRequest() == craftingLink) {
|
||||
this.setRequest(null);
|
||||
} else if (this.cpu == craftingLink) {
|
||||
this.cpu = null;
|
||||
}
|
||||
}
|
||||
|
||||
void add( final CraftingLink craftingLink )
|
||||
{
|
||||
if( craftingLink.getCpu() != null )
|
||||
{
|
||||
this.cpu = craftingLink;
|
||||
}
|
||||
else if( craftingLink.getRequester() != null )
|
||||
{
|
||||
this.setRequest( craftingLink );
|
||||
}
|
||||
}
|
||||
void add(final CraftingLink craftingLink) {
|
||||
if (craftingLink.getCpu() != null) {
|
||||
this.cpu = craftingLink;
|
||||
} else if (craftingLink.getRequester() != null) {
|
||||
this.setRequest(craftingLink);
|
||||
}
|
||||
}
|
||||
|
||||
boolean isCanceled()
|
||||
{
|
||||
return this.canceled;
|
||||
}
|
||||
boolean isCanceled() {
|
||||
return this.canceled;
|
||||
}
|
||||
|
||||
boolean isDone()
|
||||
{
|
||||
return this.done;
|
||||
}
|
||||
boolean isDone() {
|
||||
return this.done;
|
||||
}
|
||||
|
||||
void markDone()
|
||||
{
|
||||
this.done = true;
|
||||
void markDone() {
|
||||
this.done = true;
|
||||
|
||||
if( this.getRequest() != null )
|
||||
{
|
||||
this.getRequest().setDone( true );
|
||||
if( this.getRequest().getRequester() != null )
|
||||
{
|
||||
this.getRequest().getRequester().jobStateChange( this.getRequest() );
|
||||
}
|
||||
}
|
||||
if (this.getRequest() != null) {
|
||||
this.getRequest().setDone(true);
|
||||
if (this.getRequest().getRequester() != null) {
|
||||
this.getRequest().getRequester().jobStateChange(this.getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
if( this.cpu != null )
|
||||
{
|
||||
this.cpu.setDone( true );
|
||||
}
|
||||
}
|
||||
if (this.cpu != null) {
|
||||
this.cpu.setDone(true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMachine( final IGridHost machine )
|
||||
{
|
||||
return this.getRequest() == machine;
|
||||
}
|
||||
public boolean isMachine(final IGridHost machine) {
|
||||
return this.getRequest() == machine;
|
||||
}
|
||||
|
||||
public void removeNode()
|
||||
{
|
||||
if( this.getRequest() != null )
|
||||
{
|
||||
this.getRequest().setNexus( null );
|
||||
}
|
||||
public void removeNode() {
|
||||
if (this.getRequest() != null) {
|
||||
this.getRequest().setNexus(null);
|
||||
}
|
||||
|
||||
this.setRequest( null );
|
||||
this.tickOfDeath = 0;
|
||||
}
|
||||
this.setRequest(null);
|
||||
this.tickOfDeath = 0;
|
||||
}
|
||||
|
||||
public CraftingLink getRequest()
|
||||
{
|
||||
return this.req;
|
||||
}
|
||||
public CraftingLink getRequest() {
|
||||
return this.req;
|
||||
}
|
||||
|
||||
public void setRequest( final CraftingLink req )
|
||||
{
|
||||
this.req = req;
|
||||
}
|
||||
public void setRequest(final CraftingLink req) {
|
||||
this.req = req;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,395 +41,317 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Optional.Interface( iface = "gregtech.api.items.IToolItem", modid = "gregtech" )
|
||||
public class CraftingTreeNode
|
||||
{
|
||||
@Optional.Interface(iface = "gregtech.api.items.IToolItem", modid = "gregtech")
|
||||
public class CraftingTreeNode {
|
||||
|
||||
// what slot!
|
||||
private final int slot;
|
||||
private final CraftingJob job;
|
||||
private final IItemList<IAEItemStack> used = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
// parent node.
|
||||
private final CraftingTreeProcess parent;
|
||||
private final World world;
|
||||
// what item is this?
|
||||
private final IAEItemStack what;
|
||||
// what are the crafting patterns for this?
|
||||
private final ArrayList<CraftingTreeProcess> nodes = new ArrayList<>();
|
||||
private final ICraftingGrid cc;
|
||||
private final int depth;
|
||||
private int bytes = 0;
|
||||
private boolean canEmit = false;
|
||||
private long missing = 0;
|
||||
private long howManyEmitted = 0;
|
||||
private boolean exhausted = false;
|
||||
// what slot!
|
||||
private final int slot;
|
||||
private final CraftingJob job;
|
||||
private final IItemList<IAEItemStack> used = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
// parent node.
|
||||
private final CraftingTreeProcess parent;
|
||||
private final World world;
|
||||
// what item is this?
|
||||
private final IAEItemStack what;
|
||||
// what are the crafting patterns for this?
|
||||
private final ArrayList<CraftingTreeProcess> nodes = new ArrayList<>();
|
||||
private final ICraftingGrid cc;
|
||||
private final int depth;
|
||||
private int bytes = 0;
|
||||
private boolean canEmit = false;
|
||||
private long missing = 0;
|
||||
private long howManyEmitted = 0;
|
||||
private boolean exhausted = false;
|
||||
|
||||
public CraftingTreeNode( final ICraftingGrid cc, final CraftingJob job, final IAEItemStack wat, final CraftingTreeProcess par, final int slot, final int depth )
|
||||
{
|
||||
this.what = wat;
|
||||
this.parent = par;
|
||||
this.slot = slot;
|
||||
this.world = job.getWorld();
|
||||
this.job = job;
|
||||
this.cc = cc;
|
||||
this.depth = depth;
|
||||
public CraftingTreeNode(final ICraftingGrid cc, final CraftingJob job, final IAEItemStack wat, final CraftingTreeProcess par, final int slot, final int depth) {
|
||||
this.what = wat;
|
||||
this.parent = par;
|
||||
this.slot = slot;
|
||||
this.world = job.getWorld();
|
||||
this.job = job;
|
||||
this.cc = cc;
|
||||
this.depth = depth;
|
||||
|
||||
this.canEmit = cc.canEmitFor( this.what );
|
||||
}
|
||||
this.canEmit = cc.canEmitFor(this.what);
|
||||
}
|
||||
|
||||
public void addNode()
|
||||
{
|
||||
if( !nodes.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
public void addNode() {
|
||||
if (!nodes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( this.canEmit )
|
||||
{
|
||||
return; // if you can emit for something, you can't make it with patterns.
|
||||
}
|
||||
if (this.canEmit) {
|
||||
return; // if you can emit for something, you can't make it with patterns.
|
||||
}
|
||||
|
||||
for( final ICraftingPatternDetails details : cc.getCraftingFor( this.what, this.parent == null ? null : this.parent.details, slot, this.world ) )// in
|
||||
// order.
|
||||
{
|
||||
if( this.parent == null || notRecursive( details ) && this.parent.details != details )
|
||||
{
|
||||
this.nodes.add( new CraftingTreeProcess( cc, job, details, this, depth + 1 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final ICraftingPatternDetails details : cc.getCraftingFor(this.what, this.parent == null ? null : this.parent.details, slot, this.world))// in
|
||||
// order.
|
||||
{
|
||||
if (this.parent == null || notRecursive(details) && this.parent.details != details) {
|
||||
this.nodes.add(new CraftingTreeProcess(cc, job, details, this, depth + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IAEItemStack request( final MECraftingInventory inv, long l, final IActionSource src ) throws CraftBranchFailure, InterruptedException
|
||||
{
|
||||
addNode();
|
||||
this.job.handlePausing();
|
||||
if( this.canEmit )
|
||||
{
|
||||
final IAEItemStack wat = this.what.copy();
|
||||
wat.setStackSize( l );
|
||||
IAEItemStack request(final MECraftingInventory inv, long l, final IActionSource src) throws CraftBranchFailure, InterruptedException {
|
||||
addNode();
|
||||
this.job.handlePausing();
|
||||
if (this.canEmit) {
|
||||
final IAEItemStack wat = this.what.copy();
|
||||
wat.setStackSize(l);
|
||||
|
||||
this.howManyEmitted = wat.getStackSize();
|
||||
this.bytes += wat.getStackSize();
|
||||
this.howManyEmitted = wat.getStackSize();
|
||||
this.bytes += wat.getStackSize();
|
||||
|
||||
return wat;
|
||||
}
|
||||
return wat;
|
||||
}
|
||||
|
||||
final IItemList<IAEItemStack> inventoryList = inv.getItemList();
|
||||
final List<IAEItemStack> thingsUsed = new ArrayList<>();
|
||||
final IItemList<IAEItemStack> inventoryList = inv.getItemList();
|
||||
final List<IAEItemStack> thingsUsed = new ArrayList<>();
|
||||
|
||||
this.what.setStackSize( l );
|
||||
this.what.setStackSize(l);
|
||||
|
||||
if( this.getSlot() >= 0 && this.parent != null && this.parent.details.isCraftable() )
|
||||
{
|
||||
Collection<IAEItemStack> itemList = new ArrayList<>();
|
||||
if (this.getSlot() >= 0 && this.parent != null && this.parent.details.isCraftable()) {
|
||||
Collection<IAEItemStack> itemList = new ArrayList<>();
|
||||
|
||||
boolean damageableItem = this.what.getItem().isDamageable() || Platform.isGTDamageableItem( this.what.getItem() );
|
||||
boolean damageableItem = this.what.getItem().isDamageable() || Platform.isGTDamageableItem(this.what.getItem());
|
||||
|
||||
if( this.parent.details.canSubstitute() )
|
||||
{
|
||||
for( IAEItemStack subs : this.parent.details.getSubstituteInputs( this.slot ) )
|
||||
{
|
||||
if( damageableItem )
|
||||
{
|
||||
itemList.addAll( inventoryList.findFuzzy( subs, FuzzyMode.IGNORE_ALL ) );
|
||||
}
|
||||
subs = inventoryList.findPrecise( subs );
|
||||
if( subs != null )
|
||||
{
|
||||
itemList.add( subs );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( damageableItem )
|
||||
{
|
||||
itemList.addAll( inventoryList.findFuzzy( this.what, FuzzyMode.IGNORE_ALL ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
final IAEItemStack item = inventoryList.findPrecise( this.what );
|
||||
if( item != null )
|
||||
{
|
||||
itemList.add( item );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.parent.details.canSubstitute()) {
|
||||
for (IAEItemStack subs : this.parent.details.getSubstituteInputs(this.slot)) {
|
||||
if (damageableItem) {
|
||||
itemList.addAll(inventoryList.findFuzzy(subs, FuzzyMode.IGNORE_ALL));
|
||||
}
|
||||
subs = inventoryList.findPrecise(subs);
|
||||
if (subs != null) {
|
||||
itemList.add(subs);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (damageableItem) {
|
||||
itemList.addAll(inventoryList.findFuzzy(this.what, FuzzyMode.IGNORE_ALL));
|
||||
} else {
|
||||
final IAEItemStack item = inventoryList.findPrecise(this.what);
|
||||
if (item != null) {
|
||||
itemList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( IAEItemStack fuzz : itemList )
|
||||
{
|
||||
if( this.parent.details.isValidItemForSlot( this.getSlot(), fuzz.copy().getCachedItemStack( 1 ), this.world ) )
|
||||
{
|
||||
fuzz = fuzz.copy();
|
||||
fuzz.setStackSize( l );
|
||||
for (IAEItemStack fuzz : itemList) {
|
||||
if (this.parent.details.isValidItemForSlot(this.getSlot(), fuzz.copy().getCachedItemStack(1), this.world)) {
|
||||
fuzz = fuzz.copy();
|
||||
fuzz.setStackSize(l);
|
||||
|
||||
final IAEItemStack available = inv.extractItems( fuzz, Actionable.MODULATE, src );
|
||||
final IAEItemStack available = inv.extractItems(fuzz, Actionable.MODULATE, src);
|
||||
|
||||
if( available != null )
|
||||
{
|
||||
if( !this.exhausted )
|
||||
{
|
||||
final IAEItemStack is = this.job.checkUse( available );
|
||||
if (available != null) {
|
||||
if (!this.exhausted) {
|
||||
final IAEItemStack is = this.job.checkUse(available);
|
||||
|
||||
if( is != null )
|
||||
{
|
||||
thingsUsed.add( is.copy() );
|
||||
this.used.add( is );
|
||||
}
|
||||
}
|
||||
if (is != null) {
|
||||
thingsUsed.add(is.copy());
|
||||
this.used.add(is);
|
||||
}
|
||||
}
|
||||
|
||||
this.bytes += available.getStackSize();
|
||||
l -= available.getStackSize();
|
||||
this.bytes += available.getStackSize();
|
||||
l -= available.getStackSize();
|
||||
|
||||
if( l == 0 )
|
||||
{
|
||||
return available;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final IAEItemStack available = inv.extractItems( this.what, Actionable.MODULATE, src );
|
||||
if (l == 0) {
|
||||
return available;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final IAEItemStack available = inv.extractItems(this.what, Actionable.MODULATE, src);
|
||||
|
||||
if( available != null )
|
||||
{
|
||||
if( !this.exhausted )
|
||||
{
|
||||
final IAEItemStack is = this.job.checkUse( available );
|
||||
if (available != null) {
|
||||
if (!this.exhausted) {
|
||||
final IAEItemStack is = this.job.checkUse(available);
|
||||
|
||||
if( is != null )
|
||||
{
|
||||
thingsUsed.add( is.copy() );
|
||||
this.used.add( is );
|
||||
}
|
||||
}
|
||||
if (is != null) {
|
||||
thingsUsed.add(is.copy());
|
||||
this.used.add(is);
|
||||
}
|
||||
}
|
||||
|
||||
this.bytes += available.getStackSize();
|
||||
l -= available.getStackSize();
|
||||
this.bytes += available.getStackSize();
|
||||
l -= available.getStackSize();
|
||||
|
||||
if( l == 0 )
|
||||
{
|
||||
return available;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (l == 0) {
|
||||
return available;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.exhausted = true;
|
||||
this.exhausted = true;
|
||||
|
||||
if( this.nodes.size() == 1 )
|
||||
{
|
||||
final CraftingTreeProcess pro = this.nodes.get( 0 );
|
||||
if (this.nodes.size() == 1) {
|
||||
final CraftingTreeProcess pro = this.nodes.get(0);
|
||||
|
||||
while ( pro.possible && l > 0 )
|
||||
{
|
||||
final IAEItemStack madeWhat = pro.getAmountCrafted( this.what );
|
||||
pro.request( inv, pro.getTimes( l, madeWhat.getStackSize() ), src );
|
||||
while (pro.possible && l > 0) {
|
||||
final IAEItemStack madeWhat = pro.getAmountCrafted(this.what);
|
||||
pro.request(inv, pro.getTimes(l, madeWhat.getStackSize()), src);
|
||||
|
||||
madeWhat.setStackSize( l );
|
||||
final IAEItemStack available = inv.extractItems( madeWhat, Actionable.MODULATE, src );
|
||||
madeWhat.setStackSize(l);
|
||||
final IAEItemStack available = inv.extractItems(madeWhat, Actionable.MODULATE, src);
|
||||
|
||||
if( available != null )
|
||||
{
|
||||
this.bytes += available.getStackSize();
|
||||
l -= available.getStackSize();
|
||||
if (available != null) {
|
||||
this.bytes += available.getStackSize();
|
||||
l -= available.getStackSize();
|
||||
|
||||
if( l <= 0 )
|
||||
{
|
||||
return available;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pro.possible = false; // ;P
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( this.nodes.size() > 1 )
|
||||
{
|
||||
for( final CraftingTreeProcess pro : this.nodes )
|
||||
{
|
||||
try
|
||||
{
|
||||
while ( pro.possible && l > 0 )
|
||||
{
|
||||
final MECraftingInventory subInv = new MECraftingInventory( inv, true, true, true );
|
||||
pro.request( subInv, 1, src );
|
||||
if (l <= 0) {
|
||||
return available;
|
||||
}
|
||||
} else {
|
||||
pro.possible = false; // ;P
|
||||
}
|
||||
}
|
||||
} else if (this.nodes.size() > 1) {
|
||||
for (final CraftingTreeProcess pro : this.nodes) {
|
||||
try {
|
||||
while (pro.possible && l > 0) {
|
||||
final MECraftingInventory subInv = new MECraftingInventory(inv, true, true, true);
|
||||
pro.request(subInv, 1, src);
|
||||
|
||||
this.what.setStackSize( l );
|
||||
final IAEItemStack available = subInv.extractItems( this.what, Actionable.MODULATE, src );
|
||||
this.what.setStackSize(l);
|
||||
final IAEItemStack available = subInv.extractItems(this.what, Actionable.MODULATE, src);
|
||||
|
||||
if( available != null )
|
||||
{
|
||||
if( !subInv.commit( src ) )
|
||||
{
|
||||
throw new CraftBranchFailure( this.what, l );
|
||||
}
|
||||
if (available != null) {
|
||||
if (!subInv.commit(src)) {
|
||||
throw new CraftBranchFailure(this.what, l);
|
||||
}
|
||||
|
||||
this.bytes += available.getStackSize();
|
||||
l -= available.getStackSize();
|
||||
this.bytes += available.getStackSize();
|
||||
l -= available.getStackSize();
|
||||
|
||||
if( l <= 0 )
|
||||
{
|
||||
return available;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pro.possible = false; // ;P
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final CraftBranchFailure fail )
|
||||
{
|
||||
pro.possible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (l <= 0) {
|
||||
return available;
|
||||
}
|
||||
} else {
|
||||
pro.possible = false; // ;P
|
||||
}
|
||||
}
|
||||
} catch (final CraftBranchFailure fail) {
|
||||
pro.possible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( job.isSimulation() )
|
||||
{
|
||||
this.bytes += l;
|
||||
this.missing += l;
|
||||
final IAEItemStack rv = this.what.copy();
|
||||
rv.setStackSize( l );
|
||||
return rv;
|
||||
}
|
||||
if (job.isSimulation()) {
|
||||
this.bytes += l;
|
||||
this.missing += l;
|
||||
final IAEItemStack rv = this.what.copy();
|
||||
rv.setStackSize(l);
|
||||
return rv;
|
||||
}
|
||||
|
||||
for( final IAEItemStack o : thingsUsed )
|
||||
{
|
||||
this.job.refund( o.copy() );
|
||||
o.setStackSize( -o.getStackSize() );
|
||||
this.used.add( o );
|
||||
}
|
||||
for (final IAEItemStack o : thingsUsed) {
|
||||
this.job.refund(o.copy());
|
||||
o.setStackSize(-o.getStackSize());
|
||||
this.used.add(o);
|
||||
}
|
||||
|
||||
throw new CraftBranchFailure( this.what, l );
|
||||
}
|
||||
throw new CraftBranchFailure(this.what, l);
|
||||
}
|
||||
|
||||
boolean notRecursive( ICraftingPatternDetails details )
|
||||
{
|
||||
if( this.parent == null )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if( this.parent.details == details )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.parent.notRecursive( details );
|
||||
}
|
||||
boolean notRecursive(ICraftingPatternDetails details) {
|
||||
if (this.parent == null) {
|
||||
return true;
|
||||
}
|
||||
if (this.parent.details == details) {
|
||||
return false;
|
||||
}
|
||||
return this.parent.notRecursive(details);
|
||||
}
|
||||
|
||||
void dive( final CraftingJob job )
|
||||
{
|
||||
if( this.missing > 0 )
|
||||
{
|
||||
job.addMissing( this.getStack( this.missing ) );
|
||||
}
|
||||
// missing = 0;
|
||||
void dive(final CraftingJob job) {
|
||||
if (this.missing > 0) {
|
||||
job.addMissing(this.getStack(this.missing));
|
||||
}
|
||||
// missing = 0;
|
||||
|
||||
job.addBytes( this.bytes );
|
||||
job.addBytes(this.bytes);
|
||||
|
||||
for( final CraftingTreeProcess pro : this.nodes )
|
||||
{
|
||||
pro.dive( job );
|
||||
}
|
||||
}
|
||||
for (final CraftingTreeProcess pro : this.nodes) {
|
||||
pro.dive(job);
|
||||
}
|
||||
}
|
||||
|
||||
IAEItemStack getStack( final long size )
|
||||
{
|
||||
final IAEItemStack is = this.what.copy();
|
||||
is.setStackSize( size );
|
||||
return is;
|
||||
}
|
||||
IAEItemStack getStack(final long size) {
|
||||
final IAEItemStack is = this.what.copy();
|
||||
is.setStackSize(size);
|
||||
return is;
|
||||
}
|
||||
|
||||
void setSimulate()
|
||||
{
|
||||
this.missing = 0;
|
||||
this.bytes = 0;
|
||||
this.used.resetStatus();
|
||||
this.exhausted = false;
|
||||
void setSimulate() {
|
||||
this.missing = 0;
|
||||
this.bytes = 0;
|
||||
this.used.resetStatus();
|
||||
this.exhausted = false;
|
||||
|
||||
for( final CraftingTreeProcess pro : this.nodes )
|
||||
{
|
||||
pro.setSimulate();
|
||||
}
|
||||
}
|
||||
for (final CraftingTreeProcess pro : this.nodes) {
|
||||
pro.setSimulate();
|
||||
}
|
||||
}
|
||||
|
||||
public void setJob( final MECraftingInventory storage, final CraftingCPUCluster craftingCPUCluster, final IActionSource src ) throws CraftBranchFailure
|
||||
{
|
||||
for( final IAEItemStack i : this.used )
|
||||
{
|
||||
final IAEItemStack actuallyExtracted = storage.extractItems( i, Actionable.MODULATE, src );
|
||||
public void setJob(final MECraftingInventory storage, final CraftingCPUCluster craftingCPUCluster, final IActionSource src) throws CraftBranchFailure {
|
||||
for (final IAEItemStack i : this.used) {
|
||||
final IAEItemStack actuallyExtracted = storage.extractItems(i, Actionable.MODULATE, src);
|
||||
|
||||
if( actuallyExtracted == null || actuallyExtracted.getStackSize() != i.getStackSize() )
|
||||
{
|
||||
if( src.player().isPresent() )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( actuallyExtracted == null )
|
||||
{
|
||||
NetworkHandler.instance().sendTo( new PacketInformPlayer( i, null, PacketInformPlayer.InfoType.NO_ITEMS_EXTRACTED ), (EntityPlayerMP) src.player().get() );
|
||||
}
|
||||
else
|
||||
{
|
||||
NetworkHandler.instance().sendTo( new PacketInformPlayer( i, actuallyExtracted, PacketInformPlayer.InfoType.PARTIAL_ITEM_EXTRACTION ), (EntityPlayerMP) src.player().get() );
|
||||
}
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new CraftBranchFailure( i, i.getStackSize() );
|
||||
}
|
||||
if (actuallyExtracted == null || actuallyExtracted.getStackSize() != i.getStackSize()) {
|
||||
if (src.player().isPresent()) {
|
||||
try {
|
||||
if (actuallyExtracted == null) {
|
||||
NetworkHandler.instance().sendTo(new PacketInformPlayer(i, null, PacketInformPlayer.InfoType.NO_ITEMS_EXTRACTED), (EntityPlayerMP) src.player().get());
|
||||
} else {
|
||||
NetworkHandler.instance().sendTo(new PacketInformPlayer(i, actuallyExtracted, PacketInformPlayer.InfoType.PARTIAL_ITEM_EXTRACTION), (EntityPlayerMP) src.player().get());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new CraftBranchFailure(i, i.getStackSize());
|
||||
}
|
||||
|
||||
craftingCPUCluster.addStorage( actuallyExtracted );
|
||||
}
|
||||
craftingCPUCluster.addStorage(actuallyExtracted);
|
||||
}
|
||||
|
||||
if( this.howManyEmitted > 0 )
|
||||
{
|
||||
final IAEItemStack i = this.what.copy().reset();
|
||||
i.setStackSize( this.howManyEmitted );
|
||||
craftingCPUCluster.addEmitable( i );
|
||||
}
|
||||
if (this.howManyEmitted > 0) {
|
||||
final IAEItemStack i = this.what.copy().reset();
|
||||
i.setStackSize(this.howManyEmitted);
|
||||
craftingCPUCluster.addEmitable(i);
|
||||
}
|
||||
|
||||
for( final CraftingTreeProcess pro : this.nodes )
|
||||
{
|
||||
pro.setJob( storage, craftingCPUCluster, src );
|
||||
}
|
||||
}
|
||||
for (final CraftingTreeProcess pro : this.nodes) {
|
||||
pro.setJob(storage, craftingCPUCluster, src);
|
||||
}
|
||||
}
|
||||
|
||||
void getPlan( final IItemList<IAEItemStack> plan )
|
||||
{
|
||||
if( this.missing > 0 )
|
||||
{
|
||||
final IAEItemStack o = this.what.copy();
|
||||
o.setStackSize( this.missing );
|
||||
plan.add( o );
|
||||
}
|
||||
void getPlan(final IItemList<IAEItemStack> plan) {
|
||||
if (this.missing > 0) {
|
||||
final IAEItemStack o = this.what.copy();
|
||||
o.setStackSize(this.missing);
|
||||
plan.add(o);
|
||||
}
|
||||
|
||||
if( this.howManyEmitted > 0 )
|
||||
{
|
||||
final IAEItemStack i = this.what.copy();
|
||||
i.setCountRequestable( this.howManyEmitted );
|
||||
plan.addRequestable( i );
|
||||
}
|
||||
if (this.howManyEmitted > 0) {
|
||||
final IAEItemStack i = this.what.copy();
|
||||
i.setCountRequestable(this.howManyEmitted);
|
||||
plan.addRequestable(i);
|
||||
}
|
||||
|
||||
for( final IAEItemStack i : this.used )
|
||||
{
|
||||
plan.add( i.copy() );
|
||||
}
|
||||
for (final IAEItemStack i : this.used) {
|
||||
plan.add(i.copy());
|
||||
}
|
||||
|
||||
for( final CraftingTreeProcess pro : this.nodes )
|
||||
{
|
||||
pro.getPlan( plan );
|
||||
}
|
||||
}
|
||||
for (final CraftingTreeProcess pro : this.nodes) {
|
||||
pro.getPlan(plan);
|
||||
}
|
||||
}
|
||||
|
||||
int getSlot()
|
||||
{
|
||||
return this.slot;
|
||||
}
|
||||
int getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,325 +39,258 @@ import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
||||
public class CraftingTreeProcess
|
||||
{
|
||||
private final CraftingTreeNode parent;
|
||||
final ICraftingPatternDetails details;
|
||||
private final CraftingJob job;
|
||||
private final Object2LongArrayMap<CraftingTreeNode> nodes = new Object2LongArrayMap<>();
|
||||
private final int depth;
|
||||
private final ICraftingGrid cc;
|
||||
private final World world;
|
||||
boolean possible = true;
|
||||
private long crafts = 0;
|
||||
private long bytes = 0;
|
||||
public class CraftingTreeProcess {
|
||||
private final CraftingTreeNode parent;
|
||||
final ICraftingPatternDetails details;
|
||||
private final CraftingJob job;
|
||||
private final Object2LongArrayMap<CraftingTreeNode> nodes = new Object2LongArrayMap<>();
|
||||
private final int depth;
|
||||
private final ICraftingGrid cc;
|
||||
private final World world;
|
||||
boolean possible = true;
|
||||
private long crafts = 0;
|
||||
private long bytes = 0;
|
||||
|
||||
public CraftingTreeProcess( final ICraftingGrid cc, final CraftingJob job, final ICraftingPatternDetails details, final CraftingTreeNode craftingTreeNode, final int depth )
|
||||
{
|
||||
this.parent = craftingTreeNode;
|
||||
this.details = details;
|
||||
this.job = job;
|
||||
this.depth = depth;
|
||||
this.cc = cc;
|
||||
this.world = job.getWorld();
|
||||
}
|
||||
public CraftingTreeProcess(final ICraftingGrid cc, final CraftingJob job, final ICraftingPatternDetails details, final CraftingTreeNode craftingTreeNode, final int depth) {
|
||||
this.parent = craftingTreeNode;
|
||||
this.details = details;
|
||||
this.job = job;
|
||||
this.depth = depth;
|
||||
this.cc = cc;
|
||||
this.world = job.getWorld();
|
||||
}
|
||||
|
||||
public void addProcess()
|
||||
{
|
||||
if( !nodes.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
public void addProcess() {
|
||||
if (!nodes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack[] list = details.getInputs();
|
||||
final IAEItemStack[] list = details.getInputs();
|
||||
|
||||
// this is minor different then below, this slot uses the pattern, but kinda fudges it.
|
||||
for( IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
if( part == null )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for( int x = 0; x < list.length; x++ )
|
||||
{
|
||||
final IAEItemStack comparePart = list[x];
|
||||
if( part.equals( comparePart ) )
|
||||
{
|
||||
boolean isPartContainer = false;
|
||||
if( part.getItem().hasContainerItem( part.getDefinition() ) )
|
||||
{
|
||||
part = list[x];
|
||||
isPartContainer = true;
|
||||
}
|
||||
// this is minor different then below, this slot uses the pattern, but kinda fudges it.
|
||||
for (IAEItemStack part : details.getCondensedInputs()) {
|
||||
if (part == null) {
|
||||
continue;
|
||||
}
|
||||
for (int x = 0; x < list.length; x++) {
|
||||
final IAEItemStack comparePart = list[x];
|
||||
if (part.equals(comparePart)) {
|
||||
boolean isPartContainer = false;
|
||||
if (part.getItem().hasContainerItem(part.getDefinition())) {
|
||||
part = list[x];
|
||||
isPartContainer = true;
|
||||
}
|
||||
|
||||
long wantedSize = part.getStackSize();
|
||||
long wantedSize = part.getStackSize();
|
||||
|
||||
if( AEConfig.instance().getEnableCraftingSubstitutes() )
|
||||
{
|
||||
IAEItemStack found;
|
||||
long remaining;
|
||||
long requestAmount;
|
||||
if (AEConfig.instance().getEnableCraftingSubstitutes()) {
|
||||
IAEItemStack found;
|
||||
long remaining;
|
||||
long requestAmount;
|
||||
|
||||
if( details.canSubstitute() )
|
||||
{
|
||||
for( IAEItemStack subs : details.getSubstituteInputs( x ) )
|
||||
{
|
||||
found = job.checkAvailable( subs );
|
||||
if (details.canSubstitute()) {
|
||||
for (IAEItemStack subs : details.getSubstituteInputs(x)) {
|
||||
found = job.checkAvailable(subs);
|
||||
|
||||
if( found != null )
|
||||
{
|
||||
remaining = found.getStackSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
remaining = 0;
|
||||
}
|
||||
if (found != null) {
|
||||
remaining = found.getStackSize();
|
||||
} else {
|
||||
remaining = 0;
|
||||
}
|
||||
|
||||
if( remaining > 0 )
|
||||
{
|
||||
if( remaining >= wantedSize )
|
||||
{
|
||||
requestAmount = wantedSize;
|
||||
wantedSize = 0;
|
||||
//we have the items
|
||||
}
|
||||
else
|
||||
{
|
||||
requestAmount = remaining;
|
||||
wantedSize -= remaining;
|
||||
}
|
||||
subs = subs.copy().setStackSize( requestAmount );
|
||||
CraftingTreeNode node = new CraftingTreeNode( cc, job, subs, this, x, depth + 1 );
|
||||
this.nodes.put( node, requestAmount );
|
||||
if( wantedSize == 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
found = job.checkAvailable( part );
|
||||
if (remaining > 0) {
|
||||
if (remaining >= wantedSize) {
|
||||
requestAmount = wantedSize;
|
||||
wantedSize = 0;
|
||||
//we have the items
|
||||
} else {
|
||||
requestAmount = remaining;
|
||||
wantedSize -= remaining;
|
||||
}
|
||||
subs = subs.copy().setStackSize(requestAmount);
|
||||
CraftingTreeNode node = new CraftingTreeNode(cc, job, subs, this, x, depth + 1);
|
||||
this.nodes.put(node, requestAmount);
|
||||
if (wantedSize == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
found = job.checkAvailable(part);
|
||||
|
||||
if( found != null )
|
||||
{
|
||||
remaining = found.getStackSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
remaining = 0;
|
||||
}
|
||||
if (found != null) {
|
||||
remaining = found.getStackSize();
|
||||
} else {
|
||||
remaining = 0;
|
||||
}
|
||||
|
||||
if( remaining > 0 )
|
||||
{
|
||||
if( remaining >= wantedSize )
|
||||
{
|
||||
requestAmount = wantedSize;
|
||||
wantedSize = 0;
|
||||
//we have the items
|
||||
}
|
||||
else
|
||||
{
|
||||
requestAmount = remaining;
|
||||
wantedSize -= remaining;
|
||||
}
|
||||
part = part.copy().setStackSize( requestAmount );
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part, this, x, depth + 1 ), requestAmount );
|
||||
}
|
||||
}
|
||||
if( wantedSize > 0 )
|
||||
{
|
||||
if( details.canSubstitute() && cc.getCraftingFor( part, details, x, world ).isEmpty() )
|
||||
{
|
||||
//try to order the crafting of a substitute
|
||||
ICraftingPatternDetails prioritizedPattern = null;
|
||||
IAEItemStack prioritizedIAE = null;
|
||||
for( IAEItemStack subs : details.getSubstituteInputs( x ) )
|
||||
{
|
||||
ImmutableCollection<ICraftingPatternDetails> detailCollection = cc.getCraftingFor( subs, details, x, world );
|
||||
if (remaining > 0) {
|
||||
if (remaining >= wantedSize) {
|
||||
requestAmount = wantedSize;
|
||||
wantedSize = 0;
|
||||
//we have the items
|
||||
} else {
|
||||
requestAmount = remaining;
|
||||
wantedSize -= remaining;
|
||||
}
|
||||
part = part.copy().setStackSize(requestAmount);
|
||||
this.nodes.put(new CraftingTreeNode(cc, job, part, this, x, depth + 1), requestAmount);
|
||||
}
|
||||
}
|
||||
if (wantedSize > 0) {
|
||||
if (details.canSubstitute() && cc.getCraftingFor(part, details, x, world).isEmpty()) {
|
||||
//try to order the crafting of a substitute
|
||||
ICraftingPatternDetails prioritizedPattern = null;
|
||||
IAEItemStack prioritizedIAE = null;
|
||||
for (IAEItemStack subs : details.getSubstituteInputs(x)) {
|
||||
ImmutableCollection<ICraftingPatternDetails> detailCollection = cc.getCraftingFor(subs, details, x, world);
|
||||
|
||||
for( ICraftingPatternDetails sp : detailCollection )
|
||||
{
|
||||
if( prioritizedPattern == null )
|
||||
{
|
||||
prioritizedPattern = sp;
|
||||
prioritizedIAE = subs;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( sp.getPriority() > prioritizedPattern.getPriority() )
|
||||
{
|
||||
prioritizedPattern = sp;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( prioritizedIAE != null )
|
||||
{
|
||||
subs = subs.copy().setStackSize( wantedSize );
|
||||
CraftingTreeNode node = new CraftingTreeNode( cc, job, subs, this, x, depth + 1 );
|
||||
this.nodes.put( node, wantedSize );
|
||||
wantedSize = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if( wantedSize > 0 )
|
||||
{
|
||||
part = part.copy().setStackSize( wantedSize );
|
||||
// use the first slot...
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part, this, x, depth + 1 ), wantedSize );
|
||||
wantedSize = 0;
|
||||
}
|
||||
if( !isPartContainer && wantedSize == 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ICraftingPatternDetails sp : detailCollection) {
|
||||
if (prioritizedPattern == null) {
|
||||
prioritizedPattern = sp;
|
||||
prioritizedIAE = subs;
|
||||
} else {
|
||||
if (sp.getPriority() > prioritizedPattern.getPriority()) {
|
||||
prioritizedPattern = sp;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prioritizedIAE != null) {
|
||||
subs = subs.copy().setStackSize(wantedSize);
|
||||
CraftingTreeNode node = new CraftingTreeNode(cc, job, subs, this, x, depth + 1);
|
||||
this.nodes.put(node, wantedSize);
|
||||
wantedSize = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wantedSize > 0) {
|
||||
part = part.copy().setStackSize(wantedSize);
|
||||
// use the first slot...
|
||||
this.nodes.put(new CraftingTreeNode(cc, job, part, this, x, depth + 1), wantedSize);
|
||||
wantedSize = 0;
|
||||
}
|
||||
if (!isPartContainer && wantedSize == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean notRecursive( ICraftingPatternDetails details )
|
||||
{
|
||||
return this.parent == null || this.parent.notRecursive( details );
|
||||
}
|
||||
boolean notRecursive(ICraftingPatternDetails details) {
|
||||
return this.parent == null || this.parent.notRecursive(details);
|
||||
}
|
||||
|
||||
long getTimes( final long remaining, final long stackSize )
|
||||
{
|
||||
for( final IAEItemStack part : details.getCondensedOutputs() )
|
||||
{
|
||||
for( final IAEItemStack o : details.getCondensedInputs() )
|
||||
{
|
||||
if( part.equals( o ) || o.getItem().hasContainerItem( part.getDefinition() ) )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ( remaining / stackSize ) + ( remaining % stackSize != 0 ? 1 : 0 );
|
||||
}
|
||||
long getTimes(final long remaining, final long stackSize) {
|
||||
for (final IAEItemStack part : details.getCondensedOutputs()) {
|
||||
for (final IAEItemStack o : details.getCondensedInputs()) {
|
||||
if (part.equals(o) || o.getItem().hasContainerItem(part.getDefinition())) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (remaining / stackSize) + (remaining % stackSize != 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
void request( final MECraftingInventory inv, final long amountOfTimes, final IActionSource src ) throws CraftBranchFailure, InterruptedException
|
||||
{
|
||||
addProcess();
|
||||
this.job.handlePausing();
|
||||
List<IAEItemStack> containerItems = null;
|
||||
void request(final MECraftingInventory inv, final long amountOfTimes, final IActionSource src) throws CraftBranchFailure, InterruptedException {
|
||||
addProcess();
|
||||
this.job.handlePausing();
|
||||
List<IAEItemStack> containerItems = null;
|
||||
|
||||
// request and remove inputs...
|
||||
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||
{
|
||||
final IAEItemStack stack = entry.getKey().request( inv, entry.getValue() * amountOfTimes, src );
|
||||
// request and remove inputs...
|
||||
for (final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet()) {
|
||||
final IAEItemStack stack = entry.getKey().request(inv, entry.getValue() * amountOfTimes, src);
|
||||
|
||||
if( this.details.isCraftable() && stack.getItem().hasContainerItem( stack.getDefinition() ) )
|
||||
{
|
||||
final ItemStack is = Platform.getContainerItem( stack.createItemStack() );
|
||||
final IAEItemStack o = AEItemStack.fromItemStack( is );
|
||||
if( o != null )
|
||||
{
|
||||
if( containerItems == null )
|
||||
{
|
||||
containerItems = new ArrayList<>();
|
||||
}
|
||||
this.bytes++;
|
||||
o.setCachedItemStack( is );
|
||||
containerItems.add( o );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.details.isCraftable() && stack.getItem().hasContainerItem(stack.getDefinition())) {
|
||||
final ItemStack is = Platform.getContainerItem(stack.createItemStack());
|
||||
final IAEItemStack o = AEItemStack.fromItemStack(is);
|
||||
if (o != null) {
|
||||
if (containerItems == null) {
|
||||
containerItems = new ArrayList<>();
|
||||
}
|
||||
this.bytes++;
|
||||
o.setCachedItemStack(is);
|
||||
containerItems.add(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( containerItems != null )
|
||||
{
|
||||
for( IAEItemStack i : containerItems )
|
||||
{
|
||||
inv.injectItems( i, Actionable.MODULATE, src );
|
||||
}
|
||||
}
|
||||
if (containerItems != null) {
|
||||
for (IAEItemStack i : containerItems) {
|
||||
inv.injectItems(i, Actionable.MODULATE, src);
|
||||
}
|
||||
}
|
||||
|
||||
// assume its possible.
|
||||
// assume its possible.
|
||||
|
||||
// add crafting results..
|
||||
for( final IAEItemStack out : this.details.getCondensedOutputs() )
|
||||
{
|
||||
final IAEItemStack o = out.copy();
|
||||
o.setStackSize( o.getStackSize() * amountOfTimes );
|
||||
inv.injectItems( o, Actionable.MODULATE, src );
|
||||
}
|
||||
this.crafts += amountOfTimes;
|
||||
}
|
||||
// add crafting results..
|
||||
for (final IAEItemStack out : this.details.getCondensedOutputs()) {
|
||||
final IAEItemStack o = out.copy();
|
||||
o.setStackSize(o.getStackSize() * amountOfTimes);
|
||||
inv.injectItems(o, Actionable.MODULATE, src);
|
||||
}
|
||||
this.crafts += amountOfTimes;
|
||||
}
|
||||
|
||||
void dive( final CraftingJob job )
|
||||
{
|
||||
job.addTask( this.getAmountCrafted( this.parent.getStack( 1 ) ), this.crafts, this.details, this.depth );
|
||||
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||
{
|
||||
entry.getKey().dive( job );
|
||||
}
|
||||
void dive(final CraftingJob job) {
|
||||
job.addTask(this.getAmountCrafted(this.parent.getStack(1)), this.crafts, this.details, this.depth);
|
||||
for (final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet()) {
|
||||
entry.getKey().dive(job);
|
||||
}
|
||||
|
||||
job.addBytes( this.crafts * 8 + this.bytes );
|
||||
}
|
||||
job.addBytes(this.crafts * 8 + this.bytes);
|
||||
}
|
||||
|
||||
IAEItemStack getAmountCrafted( IAEItemStack what2 )
|
||||
{
|
||||
for( final IAEItemStack is : this.details.getCondensedOutputs() )
|
||||
{
|
||||
if( is.isSameType( what2 ) )
|
||||
{
|
||||
what2 = what2.copy();
|
||||
what2.setStackSize( is.getStackSize() );
|
||||
return what2;
|
||||
}
|
||||
}
|
||||
IAEItemStack getAmountCrafted(IAEItemStack what2) {
|
||||
for (final IAEItemStack is : this.details.getCondensedOutputs()) {
|
||||
if (is.isSameType(what2)) {
|
||||
what2 = what2.copy();
|
||||
what2.setStackSize(is.getStackSize());
|
||||
return what2;
|
||||
}
|
||||
}
|
||||
|
||||
// more fuzzy!
|
||||
for( final 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;
|
||||
}
|
||||
}
|
||||
// more fuzzy!
|
||||
for (final 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 IllegalStateException( "Crafting Tree construction failed." );
|
||||
}
|
||||
throw new IllegalStateException("Crafting Tree construction failed.");
|
||||
}
|
||||
|
||||
void setSimulate()
|
||||
{
|
||||
this.crafts = 0;
|
||||
this.bytes = 0;
|
||||
void setSimulate() {
|
||||
this.crafts = 0;
|
||||
this.bytes = 0;
|
||||
|
||||
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||
{
|
||||
entry.getKey().setSimulate();
|
||||
}
|
||||
}
|
||||
for (final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet()) {
|
||||
entry.getKey().setSimulate();
|
||||
}
|
||||
}
|
||||
|
||||
void setJob( final MECraftingInventory storage, final CraftingCPUCluster craftingCPUCluster, final IActionSource src ) throws CraftBranchFailure
|
||||
{
|
||||
craftingCPUCluster.addCrafting( this.details, this.crafts );
|
||||
void setJob(final MECraftingInventory storage, final CraftingCPUCluster craftingCPUCluster, final IActionSource src) throws CraftBranchFailure {
|
||||
craftingCPUCluster.addCrafting(this.details, this.crafts);
|
||||
|
||||
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||
{
|
||||
entry.getKey().setJob( storage, craftingCPUCluster, src );
|
||||
}
|
||||
}
|
||||
for (final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet()) {
|
||||
entry.getKey().setJob(storage, craftingCPUCluster, src);
|
||||
}
|
||||
}
|
||||
|
||||
void getPlan( final IItemList<IAEItemStack> plan )
|
||||
{
|
||||
for( IAEItemStack i : this.details.getOutputs() )
|
||||
{
|
||||
i = i.copy();
|
||||
i.setCountRequestable( i.getStackSize() * this.crafts );
|
||||
plan.addRequestable( i );
|
||||
}
|
||||
void getPlan(final IItemList<IAEItemStack> plan) {
|
||||
for (IAEItemStack i : this.details.getOutputs()) {
|
||||
i = i.copy();
|
||||
i.setCountRequestable(i.getStackSize() * this.crafts);
|
||||
plan.addRequestable(i);
|
||||
}
|
||||
|
||||
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||
{
|
||||
entry.getKey().getPlan( plan );
|
||||
}
|
||||
}
|
||||
for (final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet()) {
|
||||
entry.getKey().getPlan(plan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,63 +19,55 @@
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import appeng.api.networking.crafting.ICraftingWatcher;
|
||||
import appeng.api.networking.crafting.ICraftingWatcherHost;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* Maintain my interests, and a global watch list, they should always be fully synchronized.
|
||||
*/
|
||||
public class CraftingWatcher implements ICraftingWatcher
|
||||
{
|
||||
public class CraftingWatcher implements ICraftingWatcher {
|
||||
|
||||
private final CraftingGridCache gsc;
|
||||
private final ICraftingWatcherHost host;
|
||||
private final Set<IAEStack> myInterests = new HashSet<>();
|
||||
private final CraftingGridCache gsc;
|
||||
private final ICraftingWatcherHost host;
|
||||
private final Set<IAEStack> myInterests = new HashSet<>();
|
||||
|
||||
public CraftingWatcher( final CraftingGridCache cache, final ICraftingWatcherHost host )
|
||||
{
|
||||
this.gsc = cache;
|
||||
this.host = host;
|
||||
}
|
||||
public CraftingWatcher(final CraftingGridCache cache, final ICraftingWatcherHost host) {
|
||||
this.gsc = cache;
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public ICraftingWatcherHost getHost()
|
||||
{
|
||||
return this.host;
|
||||
}
|
||||
public ICraftingWatcherHost getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add( final IAEStack e )
|
||||
{
|
||||
if( this.myInterests.contains( e ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean add(final IAEStack e) {
|
||||
if (this.myInterests.contains(e)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.myInterests.add( e.copy() ) && this.gsc.getInterestManager().put( e, this );
|
||||
}
|
||||
return this.myInterests.add(e.copy()) && this.gsc.getInterestManager().put(e, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove( final IAEStack o )
|
||||
{
|
||||
return this.myInterests.remove( o ) && this.gsc.getInterestManager().remove( o, this );
|
||||
}
|
||||
@Override
|
||||
public boolean remove(final IAEStack o) {
|
||||
return this.myInterests.remove(o) && this.gsc.getInterestManager().remove(o, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
final Iterator<IAEStack> i = this.myInterests.iterator();
|
||||
@Override
|
||||
public void reset() {
|
||||
final Iterator<IAEStack> i = this.myInterests.iterator();
|
||||
|
||||
while( i.hasNext() )
|
||||
{
|
||||
this.gsc.getInterestManager().remove( i.next(), this );
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
while (i.hasNext()) {
|
||||
this.gsc.getInterestManager().remove(i.next(), this);
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,365 +32,289 @@ import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketInformPlayer;
|
||||
import appeng.util.inv.ItemListIgnoreCrafting;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
{
|
||||
public class MECraftingInventory implements IMEInventory<IAEItemStack> {
|
||||
|
||||
private final MECraftingInventory par;
|
||||
private final MECraftingInventory par;
|
||||
|
||||
private final IMEInventory<IAEItemStack> target;
|
||||
private final IItemList<IAEItemStack> localCache;
|
||||
private final IMEInventory<IAEItemStack> target;
|
||||
private final IItemList<IAEItemStack> localCache;
|
||||
|
||||
private final boolean logExtracted;
|
||||
private final IItemList<IAEItemStack> extractedCache;
|
||||
private final boolean logExtracted;
|
||||
private final IItemList<IAEItemStack> extractedCache;
|
||||
|
||||
private final boolean logInjections;
|
||||
private final IItemList<IAEItemStack> injectedCache;
|
||||
private final boolean logInjections;
|
||||
private final IItemList<IAEItemStack> injectedCache;
|
||||
|
||||
private final boolean logMissing;
|
||||
private final IItemList<IAEItemStack> missingCache;
|
||||
private final boolean logMissing;
|
||||
private final IItemList<IAEItemStack> missingCache;
|
||||
|
||||
public MECraftingInventory()
|
||||
{
|
||||
this.localCache = new ItemListIgnoreCrafting<>( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
|
||||
this.extractedCache = null;
|
||||
this.injectedCache = null;
|
||||
this.missingCache = null;
|
||||
this.logExtracted = false;
|
||||
this.logInjections = false;
|
||||
this.logMissing = false;
|
||||
this.target = null;
|
||||
this.par = null;
|
||||
}
|
||||
public MECraftingInventory() {
|
||||
this.localCache = new ItemListIgnoreCrafting<>(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
|
||||
this.extractedCache = null;
|
||||
this.injectedCache = null;
|
||||
this.missingCache = null;
|
||||
this.logExtracted = false;
|
||||
this.logInjections = false;
|
||||
this.logMissing = false;
|
||||
this.target = null;
|
||||
this.par = null;
|
||||
}
|
||||
|
||||
public MECraftingInventory( final MECraftingInventory parent )
|
||||
{
|
||||
this.target = parent;
|
||||
this.logExtracted = parent.logExtracted;
|
||||
this.logInjections = parent.logInjections;
|
||||
this.logMissing = parent.logMissing;
|
||||
public MECraftingInventory(final MECraftingInventory parent) {
|
||||
this.target = parent;
|
||||
this.logExtracted = parent.logExtracted;
|
||||
this.logInjections = parent.logInjections;
|
||||
this.logMissing = parent.logMissing;
|
||||
|
||||
if( this.logMissing )
|
||||
{
|
||||
this.missingCache = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.missingCache = null;
|
||||
}
|
||||
if (this.logMissing) {
|
||||
this.missingCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
} else {
|
||||
this.missingCache = null;
|
||||
}
|
||||
|
||||
if( this.logExtracted )
|
||||
{
|
||||
this.extractedCache = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.extractedCache = null;
|
||||
}
|
||||
if (this.logExtracted) {
|
||||
this.extractedCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
} else {
|
||||
this.extractedCache = null;
|
||||
}
|
||||
|
||||
if( this.logInjections )
|
||||
{
|
||||
this.injectedCache = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.injectedCache = null;
|
||||
}
|
||||
if (this.logInjections) {
|
||||
this.injectedCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
} else {
|
||||
this.injectedCache = null;
|
||||
}
|
||||
|
||||
this.localCache = this.target.getAvailableItems( new ItemListIgnoreCrafting<>( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() ) );
|
||||
this.localCache = this.target.getAvailableItems(new ItemListIgnoreCrafting<>(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()));
|
||||
|
||||
this.par = parent;
|
||||
}
|
||||
this.par = parent;
|
||||
}
|
||||
|
||||
public MECraftingInventory( final IMEMonitor<IAEItemStack> target, final IActionSource src, final boolean logExtracted, final boolean logInjections, final boolean logMissing )
|
||||
{
|
||||
this.target = target;
|
||||
this.logExtracted = logExtracted;
|
||||
this.logInjections = logInjections;
|
||||
this.logMissing = logMissing;
|
||||
public MECraftingInventory(final IMEMonitor<IAEItemStack> target, final IActionSource src, final boolean logExtracted, final boolean logInjections, final boolean logMissing) {
|
||||
this.target = target;
|
||||
this.logExtracted = logExtracted;
|
||||
this.logInjections = logInjections;
|
||||
this.logMissing = logMissing;
|
||||
|
||||
if( logMissing )
|
||||
{
|
||||
this.missingCache = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.missingCache = null;
|
||||
}
|
||||
if (logMissing) {
|
||||
this.missingCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
} else {
|
||||
this.missingCache = null;
|
||||
}
|
||||
|
||||
if( logExtracted )
|
||||
{
|
||||
this.extractedCache = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.extractedCache = null;
|
||||
}
|
||||
if (logExtracted) {
|
||||
this.extractedCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
} else {
|
||||
this.extractedCache = null;
|
||||
}
|
||||
|
||||
if( logInjections )
|
||||
{
|
||||
this.injectedCache = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.injectedCache = null;
|
||||
}
|
||||
if (logInjections) {
|
||||
this.injectedCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
} else {
|
||||
this.injectedCache = null;
|
||||
}
|
||||
|
||||
this.localCache = new ItemListIgnoreCrafting<>( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
|
||||
for( final IAEItemStack is : target.getStorageList() )
|
||||
{
|
||||
this.localCache.add( target.extractItems( is, Actionable.SIMULATE, src ) );
|
||||
}
|
||||
this.localCache = new ItemListIgnoreCrafting<>(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
|
||||
for (final IAEItemStack is : target.getStorageList()) {
|
||||
this.localCache.add(target.extractItems(is, Actionable.SIMULATE, src));
|
||||
}
|
||||
|
||||
this.par = null;
|
||||
}
|
||||
this.par = null;
|
||||
}
|
||||
|
||||
public MECraftingInventory( final IMEInventory<IAEItemStack> target, final boolean logExtracted, final boolean logInjections, final boolean logMissing )
|
||||
{
|
||||
this.target = target;
|
||||
this.logExtracted = logExtracted;
|
||||
this.logInjections = logInjections;
|
||||
this.logMissing = logMissing;
|
||||
public MECraftingInventory(final IMEInventory<IAEItemStack> target, final boolean logExtracted, final boolean logInjections, final boolean logMissing) {
|
||||
this.target = target;
|
||||
this.logExtracted = logExtracted;
|
||||
this.logInjections = logInjections;
|
||||
this.logMissing = logMissing;
|
||||
|
||||
if( logMissing )
|
||||
{
|
||||
this.missingCache = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.missingCache = null;
|
||||
}
|
||||
if (logMissing) {
|
||||
this.missingCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
} else {
|
||||
this.missingCache = null;
|
||||
}
|
||||
|
||||
if( logExtracted )
|
||||
{
|
||||
this.extractedCache = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.extractedCache = null;
|
||||
}
|
||||
if (logExtracted) {
|
||||
this.extractedCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
} else {
|
||||
this.extractedCache = null;
|
||||
}
|
||||
|
||||
if( logInjections )
|
||||
{
|
||||
this.injectedCache = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.injectedCache = null;
|
||||
}
|
||||
if (logInjections) {
|
||||
this.injectedCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
} else {
|
||||
this.injectedCache = null;
|
||||
}
|
||||
|
||||
this.localCache = target.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
|
||||
this.par = null;
|
||||
}
|
||||
this.localCache = target.getAvailableItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
|
||||
this.par = null;
|
||||
}
|
||||
|
||||
public MECraftingInventory( final IItemList<IAEItemStack> itemList )
|
||||
{
|
||||
this.localCache = new ItemListIgnoreCrafting<>( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
|
||||
this.target = null;
|
||||
this.logExtracted = false;
|
||||
this.logInjections = false;
|
||||
this.logMissing = false;
|
||||
this.missingCache = null;
|
||||
this.extractedCache = null;
|
||||
this.injectedCache = null;
|
||||
public MECraftingInventory(final IItemList<IAEItemStack> itemList) {
|
||||
this.localCache = new ItemListIgnoreCrafting<>(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
|
||||
this.target = null;
|
||||
this.logExtracted = false;
|
||||
this.logInjections = false;
|
||||
this.logMissing = false;
|
||||
this.missingCache = null;
|
||||
this.extractedCache = null;
|
||||
this.injectedCache = null;
|
||||
|
||||
for( IAEItemStack iaeItemStack : itemList )
|
||||
{
|
||||
this.localCache.add( iaeItemStack );
|
||||
}
|
||||
for (IAEItemStack iaeItemStack : itemList) {
|
||||
this.localCache.add(iaeItemStack);
|
||||
}
|
||||
|
||||
this.par = null;
|
||||
}
|
||||
this.par = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
if( input == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack injectItems(final IAEItemStack input, final Actionable mode, final IActionSource src) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
if( this.logInjections )
|
||||
{
|
||||
this.injectedCache.add( input );
|
||||
}
|
||||
this.localCache.add( input );
|
||||
}
|
||||
if (mode == Actionable.MODULATE) {
|
||||
if (this.logInjections) {
|
||||
this.injectedCache.add(input);
|
||||
}
|
||||
this.localCache.add(input);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
if( request == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack extractItems(final IAEItemStack request, final Actionable mode, final IActionSource src) {
|
||||
if (request == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final IAEItemStack list = this.localCache.findPrecise( request );
|
||||
if( list == null || list.getStackSize() == 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final IAEItemStack list = this.localCache.findPrecise(request);
|
||||
if (list == null || list.getStackSize() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if( list.getStackSize() >= request.getStackSize() )
|
||||
{
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
list.decStackSize( request.getStackSize() );
|
||||
if( this.logExtracted )
|
||||
{
|
||||
this.extractedCache.add( request );
|
||||
}
|
||||
}
|
||||
if (list.getStackSize() >= request.getStackSize()) {
|
||||
if (mode == Actionable.MODULATE) {
|
||||
list.decStackSize(request.getStackSize());
|
||||
if (this.logExtracted) {
|
||||
this.extractedCache.add(request);
|
||||
}
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
final IAEItemStack ret = request.copy();
|
||||
ret.setStackSize( list.getStackSize() );
|
||||
final IAEItemStack ret = request.copy();
|
||||
ret.setStackSize(list.getStackSize());
|
||||
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
list.reset();
|
||||
if( this.logExtracted )
|
||||
{
|
||||
this.extractedCache.add( ret );
|
||||
}
|
||||
}
|
||||
if (mode == Actionable.MODULATE) {
|
||||
list.reset();
|
||||
if (this.logExtracted) {
|
||||
this.extractedCache.add(ret);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems( final IItemList<IAEItemStack> out )
|
||||
{
|
||||
for( final IAEItemStack is : this.localCache )
|
||||
{
|
||||
out.add( is );
|
||||
}
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(final IItemList<IAEItemStack> out) {
|
||||
for (final IAEItemStack is : this.localCache) {
|
||||
out.add(is);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
public IItemList<IAEItemStack> getItemList()
|
||||
{
|
||||
return this.localCache;
|
||||
}
|
||||
public IItemList<IAEItemStack> getItemList() {
|
||||
return this.localCache;
|
||||
}
|
||||
|
||||
public boolean commit( final IActionSource src )
|
||||
{
|
||||
final IItemList<IAEItemStack> added = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
final IItemList<IAEItemStack> pulled = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
boolean failed = false;
|
||||
public boolean commit(final IActionSource src) {
|
||||
final IItemList<IAEItemStack> added = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
final IItemList<IAEItemStack> pulled = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
boolean failed = false;
|
||||
|
||||
if( this.logInjections )
|
||||
{
|
||||
for( final IAEItemStack inject : this.injectedCache )
|
||||
{
|
||||
IAEItemStack result = null;
|
||||
added.add( result = this.target.injectItems( inject, Actionable.MODULATE, src ) );
|
||||
if (this.logInjections) {
|
||||
for (final IAEItemStack inject : this.injectedCache) {
|
||||
IAEItemStack result = null;
|
||||
added.add(result = this.target.injectItems(inject, Actionable.MODULATE, src));
|
||||
|
||||
if( result != null )
|
||||
{
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result != null) {
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( failed )
|
||||
{
|
||||
for( final IAEItemStack is : added )
|
||||
{
|
||||
this.target.extractItems( is, Actionable.MODULATE, src );
|
||||
}
|
||||
if (failed) {
|
||||
for (final IAEItemStack is : added) {
|
||||
this.target.extractItems(is, Actionable.MODULATE, src);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if( this.logExtracted )
|
||||
{
|
||||
for( final IAEItemStack extra : this.extractedCache )
|
||||
{
|
||||
IAEItemStack result = null;
|
||||
pulled.add( result = this.target.extractItems( extra, Actionable.MODULATE, src ) );
|
||||
if (this.logExtracted) {
|
||||
for (final 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( src.player().isPresent() )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( result == null )
|
||||
{
|
||||
NetworkHandler.instance().sendTo( new PacketInformPlayer( extra, null, PacketInformPlayer.InfoType.NO_ITEMS_EXTRACTED ), (EntityPlayerMP) src.player().get() );
|
||||
}
|
||||
else
|
||||
{
|
||||
NetworkHandler.instance().sendTo( new PacketInformPlayer( extra, result, PacketInformPlayer.InfoType.PARTIAL_ITEM_EXTRACTION ), (EntityPlayerMP) src.player().get() );
|
||||
}
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result == null || result.getStackSize() != extra.getStackSize()) {
|
||||
if (src.player().isPresent()) {
|
||||
try {
|
||||
if (result == null) {
|
||||
NetworkHandler.instance().sendTo(new PacketInformPlayer(extra, null, PacketInformPlayer.InfoType.NO_ITEMS_EXTRACTED), (EntityPlayerMP) src.player().get());
|
||||
} else {
|
||||
NetworkHandler.instance().sendTo(new PacketInformPlayer(extra, result, PacketInformPlayer.InfoType.PARTIAL_ITEM_EXTRACTION), (EntityPlayerMP) src.player().get());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( failed )
|
||||
{
|
||||
for( final IAEItemStack is : added )
|
||||
{
|
||||
this.target.extractItems( is, Actionable.MODULATE, src );
|
||||
}
|
||||
if (failed) {
|
||||
for (final IAEItemStack is : added) {
|
||||
this.target.extractItems(is, Actionable.MODULATE, src);
|
||||
}
|
||||
|
||||
for( final IAEItemStack is : pulled )
|
||||
{
|
||||
this.target.injectItems( is, Actionable.MODULATE, src );
|
||||
}
|
||||
for (final IAEItemStack is : pulled) {
|
||||
this.target.injectItems(is, Actionable.MODULATE, src);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if( this.logMissing && this.par != null )
|
||||
{
|
||||
for( final IAEItemStack extra : this.missingCache )
|
||||
{
|
||||
this.par.addMissing( extra );
|
||||
}
|
||||
}
|
||||
if (this.logMissing && this.par != null) {
|
||||
for (final IAEItemStack extra : this.missingCache) {
|
||||
this.par.addMissing(extra);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addMissing( final IAEItemStack extra )
|
||||
{
|
||||
this.missingCache.add( extra );
|
||||
}
|
||||
private void addMissing(final IAEItemStack extra) {
|
||||
this.missingCache.add(extra);
|
||||
}
|
||||
|
||||
void ignore( final IAEItemStack what )
|
||||
{
|
||||
final IAEItemStack list = this.localCache.findPrecise( what );
|
||||
if( list != null )
|
||||
{
|
||||
list.setStackSize( 0 );
|
||||
}
|
||||
}
|
||||
void ignore(final IAEItemStack what) {
|
||||
final IAEItemStack list = this.localCache.findPrecise(what);
|
||||
if (list != null) {
|
||||
list.setStackSize(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user