pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,21 +18,17 @@
|
||||
|
||||
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().getRegistryName() + " x " + howMany );
|
||||
this.missing = what.copy();
|
||||
this.missing.setStackSize( howMany );
|
||||
}
|
||||
public CraftBranchFailure(final IAEItemStack what, final long howMany) {
|
||||
super("Failed: " + what.getItem().getRegistryName() + " x " + howMany);
|
||||
this.missing = what.copy();
|
||||
this.missing.setStackSize(howMany);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,21 +18,17 @@
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -47,361 +46,300 @@ import appeng.api.util.DimensionalCoord;
|
||||
import appeng.core.AELog;
|
||||
import appeng.hooks.TickHandler;
|
||||
|
||||
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 ms";
|
||||
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 ms";
|
||||
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 HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<>();
|
||||
private final Object monitor = new Object();
|
||||
private final Stopwatch watch = Stopwatch.createUnstarted();
|
||||
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 = 5;
|
||||
private int incTime = Integer.MAX_VALUE;
|
||||
|
||||
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 watch = Stopwatch.createUnstarted();
|
||||
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 = 5;
|
||||
private int incTime = Integer.MAX_VALUE;
|
||||
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;
|
||||
final ICraftingGrid cc = grid.getCache(ICraftingGrid.class);
|
||||
final IStorageGrid sg = grid.getCache(IStorageGrid.class);
|
||||
this.original = new MECraftingInventory(
|
||||
sg.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)), actionSrc,
|
||||
false, false, false);
|
||||
|
||||
this.callback = callback;
|
||||
final ICraftingGrid cc = grid.getCache( ICraftingGrid.class );
|
||||
final IStorageGrid sg = grid.getCache( IStorageGrid.class );
|
||||
this.original = new MECraftingInventory( sg
|
||||
.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), actionSrc, false, false, false );
|
||||
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 );
|
||||
}
|
||||
public void writeToNBT(final CompoundNBT out) {
|
||||
|
||||
public void writeToNBT( final CompoundNBT out )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
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 Stopwatch timer = Stopwatch.createStarted();
|
||||
|
||||
final Stopwatch timer = Stopwatch.createStarted();
|
||||
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);
|
||||
this.getTree().request(craftingInventory, this.output.getStackSize(), this.actionSrc);
|
||||
this.getTree().dive(this);
|
||||
|
||||
this.availableCheck = new MECraftingInventory( this.original, false, false, false );
|
||||
this.getTree().request( craftingInventory, this.output.getStackSize(), this.actionSrc );
|
||||
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("real", timer);
|
||||
// if ( mode == Actionable.MODULATE )
|
||||
// craftingInventory.moveItemsToStorage( storage );
|
||||
} catch (final CraftBranchFailure e) {
|
||||
this.simulate = true;
|
||||
|
||||
this.logCraftingJob( "real", timer );
|
||||
// if ( mode == Actionable.MODULATE )
|
||||
// craftingInventory.moveItemsToStorage( storage );
|
||||
}
|
||||
catch( final CraftBranchFailure e )
|
||||
{
|
||||
this.simulate = true;
|
||||
try {
|
||||
final Stopwatch timer = Stopwatch.createStarted();
|
||||
final MECraftingInventory craftingInventory = new MECraftingInventory(this.original, true, false,
|
||||
true);
|
||||
craftingInventory.ignore(this.output);
|
||||
|
||||
try
|
||||
{
|
||||
final Stopwatch timer = Stopwatch.createStarted();
|
||||
final MECraftingInventory craftingInventory = new MECraftingInventory( this.original, true, false, true );
|
||||
craftingInventory.ignore( this.output );
|
||||
this.availableCheck = new MECraftingInventory(this.original, false, false, false);
|
||||
|
||||
this.availableCheck = new MECraftingInventory( this.original, false, false, false );
|
||||
this.getTree().setSimulate();
|
||||
this.getTree().request(craftingInventory, this.output.getStackSize(), this.actionSrc);
|
||||
this.getTree().dive(this);
|
||||
|
||||
this.getTree().setSimulate();
|
||||
this.getTree().request( craftingInventory, this.output.getStackSize(), this.actionSrc );
|
||||
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("simulate", timer);
|
||||
} 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( "simulate", timer );
|
||||
}
|
||||
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.incTime > 100) {
|
||||
this.incTime = 0;
|
||||
|
||||
void handlePausing() throws InterruptedException
|
||||
{
|
||||
if( this.incTime > 100 )
|
||||
{
|
||||
this.incTime = 0;
|
||||
synchronized (this.monitor) {
|
||||
if (this.watch.elapsed(TimeUnit.MICROSECONDS) > this.time) {
|
||||
this.running = false;
|
||||
this.watch.stop();
|
||||
this.monitor.notify();
|
||||
}
|
||||
|
||||
synchronized( this.monitor )
|
||||
{
|
||||
if( this.watch.elapsed( TimeUnit.MICROSECONDS ) > this.time )
|
||||
{
|
||||
this.running = false;
|
||||
this.watch.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();
|
||||
}
|
||||
}
|
||||
this.incTime++;
|
||||
}
|
||||
|
||||
if( Thread.interrupted() )
|
||||
{
|
||||
throw new InterruptedException();
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* returns true if this needs more simulation.
|
||||
*
|
||||
* @param milli milliseconds of simulation
|
||||
*
|
||||
* @return true if this needs more simulation
|
||||
*/
|
||||
public boolean simulateFor(final int milli) {
|
||||
this.time = milli;
|
||||
|
||||
/**
|
||||
* returns true if this needs more simulation.
|
||||
*
|
||||
* @param milli milliseconds of simulation
|
||||
*
|
||||
* @return true if this needs more simulation
|
||||
*/
|
||||
public boolean simulateFor( final int milli )
|
||||
{
|
||||
this.time = milli;
|
||||
synchronized (this.monitor) {
|
||||
if (this.done) {
|
||||
return false;
|
||||
}
|
||||
|
||||
synchronized( this.monitor )
|
||||
{
|
||||
if( this.done )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.watch.reset();
|
||||
this.watch.start();
|
||||
this.running = true;
|
||||
|
||||
this.watch.reset();
|
||||
this.watch.start();
|
||||
this.running = true;
|
||||
AELog.craftingDebug("main thread is now going to sleep");
|
||||
|
||||
AELog.craftingDebug( "main thread is now going to sleep" );
|
||||
this.monitor.notify();
|
||||
|
||||
this.monitor.notify();
|
||||
while (this.running) {
|
||||
try {
|
||||
this.monitor.wait();
|
||||
} catch (final InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
while( this.running )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.monitor.wait();
|
||||
}
|
||||
catch( final InterruptedException ignored )
|
||||
{
|
||||
}
|
||||
}
|
||||
AELog.craftingDebug("main thread is now active");
|
||||
}
|
||||
|
||||
AELog.craftingDebug( "main thread is now active" );
|
||||
}
|
||||
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.MILLISECONDS);
|
||||
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.MILLISECONDS );
|
||||
final String actionSource;
|
||||
if (this.actionSrc.player().isPresent()) {
|
||||
final PlayerEntity player = this.actionSrc.player().get();
|
||||
|
||||
if( this.actionSrc.player().isPresent() )
|
||||
{
|
||||
final PlayerEntity 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -27,189 +26,157 @@ import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
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 CompoundNBT 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 CompoundNBT 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.contains("req") || !data.getBoolean("req")) {
|
||||
throw new IllegalStateException("Invalid Crafting Link for Object");
|
||||
}
|
||||
|
||||
if( !data.contains( "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 CompoundNBT 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 CompoundNBT 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.contains("req") || data.getBoolean("req")) {
|
||||
throw new IllegalStateException("Invalid Crafting Link for Object");
|
||||
}
|
||||
|
||||
if( !data.contains( "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 CompoundNBT tag) {
|
||||
tag.putString("CraftID", this.CraftID);
|
||||
tag.putBoolean("canceled", this.isCanceled());
|
||||
tag.putBoolean("done", this.isDone());
|
||||
tag.putBoolean("standalone", this.standalone);
|
||||
tag.putBoolean("req", this.getRequester() != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT tag )
|
||||
{
|
||||
tag.putString( "CraftID", this.CraftID );
|
||||
tag.putBoolean( "canceled", this.isCanceled() );
|
||||
tag.putBoolean( "done", this.isDone() );
|
||||
tag.putBoolean( "standalone", this.standalone );
|
||||
tag.putBoolean( "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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,157 +18,121 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import appeng.api.networking.IGrid;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -38,370 +37,309 @@ import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
|
||||
public class CraftingTreeNode {
|
||||
|
||||
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 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 int bytes = 0;
|
||||
private boolean canEmit = false;
|
||||
private long missing = 0;
|
||||
private long howManyEmitted = 0;
|
||||
private boolean exhausted = false;
|
||||
private boolean sim;
|
||||
|
||||
private boolean sim;
|
||||
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.sim = 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.sim = false;
|
||||
this.canEmit = cc.canEmitFor(this.what);
|
||||
|
||||
this.canEmit = cc.canEmitFor( this.what );
|
||||
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 || this.parent.notRecursive(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 || this.parent.notRecursive( details ) )
|
||||
{
|
||||
this.nodes.add( new CraftingTreeProcess( cc, job, details, this, depth + 1 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean notRecursive(final ICraftingPatternDetails details) {
|
||||
IAEItemStack[] o = details.getCondensedOutputs();
|
||||
|
||||
boolean notRecursive( final ICraftingPatternDetails details )
|
||||
{
|
||||
IAEItemStack[] o = details.getCondensedOutputs();
|
||||
for (final IAEItemStack i : o) {
|
||||
if (i.equals(this.what)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for( final IAEItemStack i : o )
|
||||
{
|
||||
if( i.equals( this.what ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
o = details.getCondensedInputs();
|
||||
|
||||
o = details.getCondensedInputs();
|
||||
for (final IAEItemStack i : o) {
|
||||
if (i.equals(this.what)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for( final IAEItemStack i : o )
|
||||
{
|
||||
if( i.equals( this.what ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (this.parent == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( this.parent == null )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return this.parent.notRecursive(details);
|
||||
}
|
||||
|
||||
return this.parent.notRecursive( details );
|
||||
}
|
||||
IAEItemStack request(final MECraftingInventory inv, long l, final IActionSource src)
|
||||
throws CraftBranchFailure, InterruptedException {
|
||||
this.job.handlePausing();
|
||||
|
||||
IAEItemStack request( final MECraftingInventory inv, long l, final IActionSource src ) throws CraftBranchFailure, InterruptedException
|
||||
{
|
||||
this.job.handlePausing();
|
||||
final List<IAEItemStack> thingsUsed = new ArrayList<>();
|
||||
|
||||
final List<IAEItemStack> thingsUsed = new ArrayList<>();
|
||||
this.what.setStackSize(l);
|
||||
if (this.getSlot() >= 0 && this.parent != null && this.parent.details.isCraftable()) {
|
||||
final Collection<IAEItemStack> itemList;
|
||||
final IItemList<IAEItemStack> inventoryList = inv.getItemList();
|
||||
|
||||
this.what.setStackSize( l );
|
||||
if( this.getSlot() >= 0 && this.parent != null && this.parent.details.isCraftable() )
|
||||
{
|
||||
final Collection<IAEItemStack> itemList;
|
||||
final IItemList<IAEItemStack> inventoryList = inv.getItemList();
|
||||
if (this.parent.details.canSubstitute()) {
|
||||
itemList = inventoryList.findFuzzy(this.what, FuzzyMode.IGNORE_ALL);
|
||||
} else {
|
||||
itemList = Lists.newArrayList();
|
||||
|
||||
if( this.parent.details.canSubstitute() )
|
||||
{
|
||||
itemList = inventoryList.findFuzzy( this.what, FuzzyMode.IGNORE_ALL );
|
||||
}
|
||||
else
|
||||
{
|
||||
itemList = Lists.newArrayList();
|
||||
final IAEItemStack item = inventoryList.findPrecise(this.what);
|
||||
|
||||
final IAEItemStack item = inventoryList.findPrecise( this.what );
|
||||
if (item != null) {
|
||||
itemList.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
if( item != null )
|
||||
{
|
||||
itemList.add( item );
|
||||
}
|
||||
}
|
||||
for (IAEItemStack fuzz : itemList) {
|
||||
if (this.parent.details.isValidItemForSlot(this.getSlot(),
|
||||
fuzz.copy().setStackSize(1).createItemStack(), this.world)) {
|
||||
fuzz = fuzz.copy();
|
||||
fuzz.setStackSize(l);
|
||||
|
||||
for( IAEItemStack fuzz : itemList )
|
||||
{
|
||||
if( this.parent.details.isValidItemForSlot( this.getSlot(), fuzz.copy().setStackSize( 1 ).createItemStack(), 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.canEmit) {
|
||||
final IAEItemStack wat = this.what.copy();
|
||||
wat.setStackSize(l);
|
||||
|
||||
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;
|
||||
}
|
||||
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);
|
||||
|
||||
while( pro.possible && l > 0 )
|
||||
{
|
||||
final IAEItemStack madeWhat = pro.getAmountCrafted( this.what );
|
||||
pro.request(inv, pro.getTimes(l, madeWhat.getStackSize()), src);
|
||||
|
||||
pro.request( inv, pro.getTimes( l, madeWhat.getStackSize() ), src );
|
||||
madeWhat.setStackSize(l);
|
||||
|
||||
madeWhat.setStackSize( l );
|
||||
final IAEItemStack available = inv.extractItems(madeWhat, Actionable.MODULATE, src);
|
||||
|
||||
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 (this.sim) {
|
||||
this.missing += l;
|
||||
this.bytes += l;
|
||||
final IAEItemStack rv = this.what.copy();
|
||||
rv.setStackSize(l);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if( this.sim )
|
||||
{
|
||||
this.missing += l;
|
||||
this.bytes += 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 );
|
||||
}
|
||||
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(8 + this.bytes);
|
||||
|
||||
job.addBytes( 8 + 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.sim = true;
|
||||
this.missing = 0;
|
||||
this.bytes = 0;
|
||||
this.used.resetStatus();
|
||||
this.exhausted = false;
|
||||
|
||||
void setSimulate()
|
||||
{
|
||||
this.sim = true;
|
||||
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 ex = 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 ex = storage.extractItems( i, Actionable.MODULATE, src );
|
||||
if (ex == null || ex.getStackSize() != i.getStackSize()) {
|
||||
throw new CraftBranchFailure(i, i.getStackSize());
|
||||
}
|
||||
|
||||
if( ex == null || ex.getStackSize() != i.getStackSize() )
|
||||
{
|
||||
throw new CraftBranchFailure( i, i.getStackSize() );
|
||||
}
|
||||
craftingCPUCluster.addStorage(ex);
|
||||
}
|
||||
|
||||
craftingCPUCluster.addStorage( ex );
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -41,285 +40,241 @@ import appeng.container.ContainerNull;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class CraftingTreeProcess {
|
||||
|
||||
public class CraftingTreeProcess
|
||||
{
|
||||
private final CraftingTreeNode parent;
|
||||
final ICraftingPatternDetails details;
|
||||
private final CraftingJob job;
|
||||
private final Map<CraftingTreeNode, Long> nodes = new HashMap<>();
|
||||
private final int depth;
|
||||
boolean possible = true;
|
||||
private World world;
|
||||
private long crafts = 0;
|
||||
private boolean containerItems;
|
||||
private boolean limitQty;
|
||||
private boolean fullSimulation;
|
||||
private long bytes = 0;
|
||||
|
||||
private final CraftingTreeNode parent;
|
||||
final ICraftingPatternDetails details;
|
||||
private final CraftingJob job;
|
||||
private final Map<CraftingTreeNode, Long> nodes = new HashMap<>();
|
||||
private final int depth;
|
||||
boolean possible = true;
|
||||
private World world;
|
||||
private long crafts = 0;
|
||||
private boolean containerItems;
|
||||
private boolean limitQty;
|
||||
private boolean fullSimulation;
|
||||
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;
|
||||
final World 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;
|
||||
final World world = job.getWorld();
|
||||
if (details.isCraftable()) {
|
||||
final IAEItemStack[] list = details.getInputs();
|
||||
|
||||
if( details.isCraftable() )
|
||||
{
|
||||
final IAEItemStack[] list = details.getInputs();
|
||||
final CraftingInventory ic = new CraftingInventory(new ContainerNull(), 3, 3);
|
||||
final IAEItemStack[] is = details.getInputs();
|
||||
for (int x = 0; x < ic.getSizeInventory(); x++) {
|
||||
ic.setInventorySlotContents(x, is[x] == null ? ItemStack.EMPTY : is[x].createItemStack());
|
||||
}
|
||||
|
||||
final CraftingInventory ic = new CraftingInventory( new ContainerNull(), 3, 3 );
|
||||
final IAEItemStack[] is = details.getInputs();
|
||||
for( int x = 0; x < ic.getSizeInventory(); x++ )
|
||||
{
|
||||
ic.setInventorySlotContents( x, is[x] == null ? ItemStack.EMPTY : is[x].createItemStack() );
|
||||
}
|
||||
BasicEventHooks.firePlayerCraftingEvent(Platform.getPlayer((ServerWorld) world),
|
||||
details.getOutput(ic, world), ic);
|
||||
|
||||
BasicEventHooks.firePlayerCraftingEvent( Platform.getPlayer( (ServerWorld) world ), details.getOutput( ic, world ), ic );
|
||||
for (int x = 0; x < ic.getSizeInventory(); x++) {
|
||||
final ItemStack g = ic.getStackInSlot(x);
|
||||
if (!g.isEmpty() && g.getCount() > 1) {
|
||||
this.fullSimulation = true;
|
||||
}
|
||||
}
|
||||
|
||||
for( int x = 0; x < ic.getSizeInventory(); x++ )
|
||||
{
|
||||
final ItemStack g = ic.getStackInSlot( x );
|
||||
if( !g.isEmpty() && g.getCount() > 1 )
|
||||
{
|
||||
this.fullSimulation = true;
|
||||
}
|
||||
}
|
||||
for (final IAEItemStack part : details.getCondensedInputs()) {
|
||||
final ItemStack g = part.createItemStack();
|
||||
|
||||
for( final IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
final ItemStack g = part.createItemStack();
|
||||
boolean isAnInput = false;
|
||||
for (final IAEItemStack a : details.getCondensedOutputs()) {
|
||||
if (!g.isEmpty() && a != null && a.equals(g)) {
|
||||
isAnInput = true;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAnInput = false;
|
||||
for( final IAEItemStack a : details.getCondensedOutputs() )
|
||||
{
|
||||
if( !g.isEmpty() && a != null && a.equals( g ) )
|
||||
{
|
||||
isAnInput = true;
|
||||
}
|
||||
}
|
||||
if (isAnInput) {
|
||||
this.limitQty = true;
|
||||
}
|
||||
|
||||
if( isAnInput )
|
||||
{
|
||||
this.limitQty = true;
|
||||
}
|
||||
if (g.getItem().hasContainerItem(g)) {
|
||||
this.limitQty = this.containerItems = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( g.getItem().hasContainerItem( g ) )
|
||||
{
|
||||
this.limitQty = this.containerItems = true;
|
||||
}
|
||||
}
|
||||
final boolean complicated = false;
|
||||
|
||||
final boolean complicated = false;
|
||||
if (this.containerItems || complicated) {
|
||||
for (int x = 0; x < list.length; x++) {
|
||||
final IAEItemStack part = list[x];
|
||||
if (part != null) {
|
||||
this.nodes.put(new CraftingTreeNode(cc, job, part.copy(), this, x, depth + 1),
|
||||
part.getStackSize());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// this is minor different then below, this slot uses the pattern, but kinda
|
||||
// fudges it.
|
||||
for (final IAEItemStack part : details.getCondensedInputs()) {
|
||||
for (int x = 0; x < list.length; x++) {
|
||||
final IAEItemStack comparePart = list[x];
|
||||
if (part != null && part.equals(comparePart)) {
|
||||
// use the first slot...
|
||||
this.nodes.put(new CraftingTreeNode(cc, job, part.copy(), this, x, depth + 1),
|
||||
part.getStackSize());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (final IAEItemStack part : details.getCondensedInputs()) {
|
||||
final ItemStack g = part.createItemStack();
|
||||
|
||||
if( this.containerItems || complicated )
|
||||
{
|
||||
for( int x = 0; x < list.length; x++ )
|
||||
{
|
||||
final IAEItemStack part = list[x];
|
||||
if( part != null )
|
||||
{
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is minor different then below, this slot uses the pattern, but kinda fudges it.
|
||||
for( final IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
for( int x = 0; x < list.length; x++ )
|
||||
{
|
||||
final IAEItemStack comparePart = list[x];
|
||||
if( part != null && part.equals( comparePart ) )
|
||||
{
|
||||
// use the first slot...
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( final IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
final ItemStack g = part.createItemStack();
|
||||
boolean isAnInput = false;
|
||||
for (final IAEItemStack a : details.getCondensedOutputs()) {
|
||||
if (!g.isEmpty() && a != null && a.equals(g)) {
|
||||
isAnInput = true;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAnInput = false;
|
||||
for( final IAEItemStack a : details.getCondensedOutputs() )
|
||||
{
|
||||
if( !g.isEmpty() && a != null && a.equals( g ) )
|
||||
{
|
||||
isAnInput = true;
|
||||
}
|
||||
}
|
||||
if (isAnInput) {
|
||||
this.limitQty = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( isAnInput )
|
||||
{
|
||||
this.limitQty = true;
|
||||
}
|
||||
}
|
||||
for (final IAEItemStack part : details.getCondensedInputs()) {
|
||||
this.nodes.put(new CraftingTreeNode(cc, job, part.copy(), this, -1, depth + 1), part.getStackSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( final IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, -1, depth + 1 ), part.getStackSize() );
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean notRecursive(final ICraftingPatternDetails details) {
|
||||
return this.parent == null || this.parent.notRecursive(details);
|
||||
}
|
||||
|
||||
boolean notRecursive( final ICraftingPatternDetails details )
|
||||
{
|
||||
return this.parent == null || this.parent.notRecursive( details );
|
||||
}
|
||||
long getTimes(final long remaining, final long stackSize) {
|
||||
if (this.limitQty || this.fullSimulation) {
|
||||
return 1;
|
||||
}
|
||||
return (remaining / stackSize) + (remaining % stackSize != 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
long getTimes( final long remaining, final long stackSize )
|
||||
{
|
||||
if( this.limitQty || this.fullSimulation )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return ( remaining / stackSize ) + ( remaining % stackSize != 0 ? 1 : 0 );
|
||||
}
|
||||
void request(final MECraftingInventory inv, final long i, final IActionSource src)
|
||||
throws CraftBranchFailure, InterruptedException {
|
||||
this.job.handlePausing();
|
||||
|
||||
void request( final MECraftingInventory inv, final long i, final IActionSource src ) throws CraftBranchFailure, InterruptedException
|
||||
{
|
||||
this.job.handlePausing();
|
||||
if (this.fullSimulation) {
|
||||
final CraftingInventory ic = new CraftingInventory(new ContainerNull(), 3, 3);
|
||||
|
||||
if( this.fullSimulation )
|
||||
{
|
||||
final CraftingInventory ic = new CraftingInventory( new ContainerNull(), 3, 3 );
|
||||
for (final Entry<CraftingTreeNode, Long> entry : this.nodes.entrySet()) {
|
||||
final IAEItemStack item = entry.getKey().getStack(entry.getValue());
|
||||
final IAEItemStack stack = entry.getKey().request(inv, item.getStackSize(), src);
|
||||
|
||||
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.entrySet() )
|
||||
{
|
||||
final IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
||||
final IAEItemStack stack = entry.getKey().request( inv, item.getStackSize(), src );
|
||||
ic.setInventorySlotContents(entry.getKey().getSlot(), stack.createItemStack());
|
||||
}
|
||||
|
||||
ic.setInventorySlotContents( entry.getKey().getSlot(), stack.createItemStack() );
|
||||
}
|
||||
BasicEventHooks.firePlayerCraftingEvent(Platform.getPlayer((ServerWorld) this.world),
|
||||
this.details.getOutput(ic, this.world), ic);
|
||||
|
||||
BasicEventHooks.firePlayerCraftingEvent( Platform.getPlayer( (ServerWorld) this.world ), this.details.getOutput( ic, this.world ), ic );
|
||||
for (int x = 0; x < ic.getSizeInventory(); x++) {
|
||||
ItemStack is = ic.getStackInSlot(x);
|
||||
is = Platform.getContainerItem(is);
|
||||
|
||||
for( int x = 0; x < ic.getSizeInventory(); x++ )
|
||||
{
|
||||
ItemStack is = ic.getStackInSlot( x );
|
||||
is = Platform.getContainerItem( is );
|
||||
final IAEItemStack o = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createStack(is);
|
||||
if (o != null) {
|
||||
this.bytes++;
|
||||
inv.injectItems(o, Actionable.MODULATE, src);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// request and remove inputs...
|
||||
for (final Entry<CraftingTreeNode, Long> entry : this.nodes.entrySet()) {
|
||||
final IAEItemStack item = entry.getKey().getStack(entry.getValue());
|
||||
final IAEItemStack stack = entry.getKey().request(inv, item.getStackSize() * i, src);
|
||||
|
||||
final IAEItemStack o = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( is );
|
||||
if( o != null )
|
||||
{
|
||||
this.bytes++;
|
||||
inv.injectItems( o, Actionable.MODULATE, src );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// request and remove inputs...
|
||||
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.entrySet() )
|
||||
{
|
||||
final IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
||||
final IAEItemStack stack = entry.getKey().request( inv, item.getStackSize() * i, src );
|
||||
if (this.containerItems) {
|
||||
final ItemStack is = Platform.getContainerItem(stack.createItemStack());
|
||||
final IAEItemStack o = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createStack(is);
|
||||
if (o != null) {
|
||||
this.bytes++;
|
||||
inv.injectItems(o, Actionable.MODULATE, src);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( this.containerItems )
|
||||
{
|
||||
final ItemStack is = Platform.getContainerItem( stack.createItemStack() );
|
||||
final IAEItemStack o = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( is );
|
||||
if( o != null )
|
||||
{
|
||||
this.bytes++;
|
||||
inv.injectItems( o, 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() * i);
|
||||
inv.injectItems(o, Actionable.MODULATE, src);
|
||||
}
|
||||
|
||||
// add crafting results..
|
||||
for( final IAEItemStack out : this.details.getCondensedOutputs() )
|
||||
{
|
||||
final IAEItemStack o = out.copy();
|
||||
o.setStackSize( o.getStackSize() * i );
|
||||
inv.injectItems( o, Actionable.MODULATE, src );
|
||||
}
|
||||
this.crafts += i;
|
||||
}
|
||||
|
||||
this.crafts += i;
|
||||
}
|
||||
void dive(final CraftingJob job) {
|
||||
job.addTask(this.getAmountCrafted(this.parent.getStack(1)), this.crafts, this.details, this.depth);
|
||||
for (final CraftingTreeNode pro : this.nodes.keySet()) {
|
||||
pro.dive(job);
|
||||
}
|
||||
|
||||
void dive( final CraftingJob job )
|
||||
{
|
||||
job.addTask( this.getAmountCrafted( this.parent.getStack( 1 ) ), this.crafts, this.details, this.depth );
|
||||
for( final CraftingTreeNode pro : this.nodes.keySet() )
|
||||
{
|
||||
pro.dive( job );
|
||||
}
|
||||
job.addBytes(8 + this.crafts + this.bytes);
|
||||
}
|
||||
|
||||
job.addBytes( 8 + this.crafts + this.bytes );
|
||||
}
|
||||
IAEItemStack getAmountCrafted(IAEItemStack what2) {
|
||||
for (final IAEItemStack is : this.details.getCondensedOutputs()) {
|
||||
if (is.equals(what2)) {
|
||||
what2 = what2.copy();
|
||||
what2.setStackSize(is.getStackSize());
|
||||
return what2;
|
||||
}
|
||||
}
|
||||
|
||||
IAEItemStack getAmountCrafted( IAEItemStack what2 )
|
||||
{
|
||||
for( final IAEItemStack is : this.details.getCondensedOutputs() )
|
||||
{
|
||||
if( is.equals( 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 CraftingTreeNode pro : this.nodes.keySet()) {
|
||||
pro.setSimulate();
|
||||
}
|
||||
}
|
||||
|
||||
for( final CraftingTreeNode pro : this.nodes.keySet() )
|
||||
{
|
||||
pro.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 CraftingTreeNode pro : this.nodes.keySet()) {
|
||||
pro.setJob(storage, craftingCPUCluster, src);
|
||||
}
|
||||
}
|
||||
|
||||
for( final CraftingTreeNode pro : this.nodes.keySet() )
|
||||
{
|
||||
pro.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 CraftingTreeNode pro : this.nodes.keySet() )
|
||||
{
|
||||
pro.getPlan( plan );
|
||||
}
|
||||
}
|
||||
for (final CraftingTreeNode pro : this.nodes.keySet()) {
|
||||
pro.getPlan(plan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
@@ -28,54 +27,46 @@ import appeng.api.networking.crafting.ICraftingWatcherHost;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
|
||||
|
||||
/**
|
||||
* Maintain my interests, and a global watch list, they should always be fully synchronized.
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
@@ -30,326 +29,266 @@ import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.inv.ItemListIgnoreCrafting;
|
||||
|
||||
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;
|
||||
}
|
||||
@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()) {
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( result == null || result.getStackSize() != extra.getStackSize() )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
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