Fixed the order craftinglinks are notified for the last item.

Fixes #1833
This commit is contained in:
yueh
2015-08-28 13:29:24 +02:00
committed by thatsIch
parent 84fa5a38e0
commit 6a2056562b
2 changed files with 157 additions and 133 deletions
+3 -3
View File
@@ -313,9 +313,9 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
{ {
this.craftingCPUClusters.add( cluster ); this.craftingCPUClusters.add( cluster );
if( cluster.myLastLink != null ) if( cluster.getLastCraftingLink() != null )
{ {
this.addLink( (CraftingLink) cluster.myLastLink ); this.addLink( (CraftingLink) cluster.getLastCraftingLink() );
} }
} }
} }
@@ -640,7 +640,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
while( this.iterator.hasNext() && this.cpuCluster == null ) while( this.iterator.hasNext() && this.cpuCluster == null )
{ {
this.cpuCluster = this.iterator.next(); this.cpuCluster = this.iterator.next();
if( !this.cpuCluster.isActive() || this.cpuCluster.isDestroyed ) if( !this.cpuCluster.isActive() || this.cpuCluster.isDestroyed() )
{ {
this.cpuCluster = null; this.cpuCluster = null;
} }
@@ -78,31 +78,31 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
public class CraftingCPUCluster implements IAECluster, ICraftingCPU public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
{ {
public final WorldCoord min; private final WorldCoord min;
public final WorldCoord max; private final WorldCoord max;
final int[] usedOps = new int[3]; private final int[] usedOps = new int[3];
final Map<ICraftingPatternDetails, TaskProgress> tasks = new HashMap<ICraftingPatternDetails, TaskProgress>(); private final Map<ICraftingPatternDetails, TaskProgress> tasks = new HashMap<ICraftingPatternDetails, TaskProgress>();
// INSTANCE sate // INSTANCE sate
private final LinkedList<TileCraftingTile> tiles = new LinkedList<TileCraftingTile>(); private final LinkedList<TileCraftingTile> tiles = new LinkedList<TileCraftingTile>();
private final LinkedList<TileCraftingTile> storage = new LinkedList<TileCraftingTile>(); private final LinkedList<TileCraftingTile> storage = new LinkedList<TileCraftingTile>();
private final LinkedList<TileCraftingMonitorTile> status = new LinkedList<TileCraftingMonitorTile>(); private final LinkedList<TileCraftingMonitorTile> status = new LinkedList<TileCraftingMonitorTile>();
private final HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object>(); private final HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object>();
public ICraftingLink myLastLink; private ICraftingLink myLastLink;
public String myName = ""; private String myName = "";
public boolean isDestroyed = false; private boolean isDestroyed = false;
/** /**
* crafting job info * crafting job info
*/ */
MECraftingInventory inventory = new MECraftingInventory(); private MECraftingInventory inventory = new MECraftingInventory();
IAEItemStack finalOutput; private IAEItemStack finalOutput;
boolean waiting = false; private boolean waiting = false;
IItemList<IAEItemStack> waitingFor = AEApi.instance().storage().createItemList(); private IItemList<IAEItemStack> waitingFor = AEApi.instance().storage().createItemList();
long availableStorage = 0; private long availableStorage = 0;
MachineSource machineSrc = null; private MachineSource machineSrc = null;
int accelerator = 0; private int accelerator = 0;
private boolean isComplete = true; private boolean isComplete = true;
private int remainingOperations; private int remainingOperations;
private boolean somethingChanged; private boolean somethingChanged;
@@ -118,6 +118,16 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
this.max = max; this.max = max;
} }
public boolean isDestroyed()
{
return this.isDestroyed;
}
public ICraftingLink getLastCraftingLink()
{
return this.myLastLink;
}
/** /**
* add a new Listener to the monitor, be sure to properly remove yourself when your done. * add a new Listener to the monitor, be sure to properly remove yourself when your done.
*/ */
@@ -163,10 +173,10 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
for( TileCraftingTile r : this.tiles ) for( TileCraftingTile r : this.tiles )
{ {
IGridNode n = r.getActionableNode(); final IGridNode n = r.getActionableNode();
if( n != null && !posted ) if( n != null && !posted )
{ {
IGrid g = n.getGrid(); final IGrid g = n.getGrid();
if( g != null ) if( g != null )
{ {
g.postEvent( new MENetworkCraftingCpuChange( n ) ); g.postEvent( new MENetworkCraftingCpuChange( n ) );
@@ -214,7 +224,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
{ {
if( input instanceof IAEItemStack ) if( input instanceof IAEItemStack )
{ {
IAEItemStack is = this.waitingFor.findPrecise( (IAEItemStack) input ); final IAEItemStack is = this.waitingFor.findPrecise( (IAEItemStack) input );
if( is != null && is.getStackSize() > 0 ) if( is != null && is.getStackSize() > 0 )
{ {
return true; return true;
@@ -225,11 +235,16 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
public IAEStack injectItems( IAEStack input, Actionable type, BaseActionSource src ) public IAEStack injectItems( IAEStack input, Actionable type, BaseActionSource src )
{ {
if( input instanceof IAEItemStack && type == Actionable.SIMULATE )// causes crafting to lock up? if( !( input instanceof IAEItemStack ) )
{ {
IAEItemStack what = (IAEItemStack) input.copy(); return input;
IAEItemStack is = this.waitingFor.findPrecise( what ); }
final IAEItemStack what = (IAEItemStack) input.copy();
final IAEItemStack is = this.waitingFor.findPrecise( what );
if( type == Actionable.SIMULATE )// causes crafting to lock up?
{
if( is != null && is.getStackSize() > 0 ) if( is != null && is.getStackSize() > 0 )
{ {
if( is.getStackSize() >= what.getStackSize() ) if( is.getStackSize() >= what.getStackSize() )
@@ -247,10 +262,10 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
return null; return null;
} }
IAEItemStack leftOver = what.copy(); final IAEItemStack leftOver = what.copy();
leftOver.decStackSize( is.getStackSize() ); leftOver.decStackSize( is.getStackSize() );
IAEItemStack used = what.copy(); final IAEItemStack used = what.copy();
used.setStackSize( is.getStackSize() ); used.setStackSize( is.getStackSize() );
if( this.finalOutput.equals( what ) ) if( this.finalOutput.equals( what ) )
@@ -267,27 +282,33 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
return leftOver; return leftOver;
} }
} }
else if( input instanceof IAEItemStack && type == Actionable.MODULATE ) else if( type == Actionable.MODULATE )
{ {
IAEItemStack what = (IAEItemStack) input;
IAEItemStack is = this.waitingFor.findPrecise( what );
if( is != null && is.getStackSize() > 0 ) if( is != null && is.getStackSize() > 0 )
{ {
this.waiting = false; this.waiting = false;
this.postChange( (IAEItemStack) input, src ); this.postChange( what, src );
if( is.getStackSize() >= input.getStackSize() ) if( is.getStackSize() >= what.getStackSize() )
{ {
is.decStackSize( input.getStackSize() ); is.decStackSize( what.getStackSize() );
this.updateElapsedTime( (IAEItemStack) input );
this.updateElapsedTime( what );
this.markDirty(); this.markDirty();
this.postCraftingStatusChange( is ); this.postCraftingStatusChange( is );
if( this.finalOutput.equals( input ) ) if( this.finalOutput.equals( what ) )
{ {
this.finalOutput.decStackSize( input.getStackSize() ); IAEStack leftover = what;
this.finalOutput.decStackSize( what.getStackSize() );
if( this.myLastLink != null )
{
leftover = ( (CraftingLink) this.myLastLink ).injectItems( what, type );
}
if( this.finalOutput.getStackSize() <= 0 ) if( this.finalOutput.getStackSize() <= 0 )
{ {
this.completeJob(); this.completeJob();
@@ -295,19 +316,14 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
this.updateCPU(); this.updateCPU();
if( this.myLastLink != null ) return leftover; // ignore it.
{
return ( (CraftingLink) this.myLastLink ).injectItems( (IAEItemStack) input, type );
}
return input; // ignore it.
} }
// 2000 // 2000
return this.inventory.injectItems( what, type, src ); return this.inventory.injectItems( what, type, src );
} }
IAEItemStack insert = what.copy(); final IAEItemStack insert = what.copy();
insert.setStackSize( is.getStackSize() ); insert.setStackSize( is.getStackSize() );
what.decStackSize( is.getStackSize() ); what.decStackSize( is.getStackSize() );
@@ -315,26 +331,25 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
if( this.finalOutput.equals( insert ) ) if( this.finalOutput.equals( insert ) )
{ {
IAEStack leftover = input;
this.finalOutput.decStackSize( insert.getStackSize() ); this.finalOutput.decStackSize( insert.getStackSize() );
if( this.myLastLink != null )
{
what.add( ( (CraftingLink) this.myLastLink ).injectItems( insert.copy(), type ) );
leftover = what;
}
if( this.finalOutput.getStackSize() <= 0 ) if( this.finalOutput.getStackSize() <= 0 )
{ {
this.completeJob(); this.completeJob();
} }
this.updateCPU(); this.updateCPU();
this.markDirty();
if( this.myLastLink != null ) return leftover; // ignore it.
{
what.add( ( (CraftingLink) this.myLastLink ).injectItems( insert.copy(), type ) );
return what;
}
if( this.myLastLink != null )
{
return ( (CraftingLink) this.myLastLink ).injectItems( (IAEItemStack) input, type );
}
return input; // ignore it.
} }
this.inventory.injectItems( insert, type, src ); this.inventory.injectItems( insert, type, src );
@@ -349,29 +364,29 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
protected void postChange( IAEItemStack diff, BaseActionSource src ) protected void postChange( IAEItemStack diff, BaseActionSource src )
{ {
Iterator<Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.getListeners(); final Iterator<Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.getListeners();
ImmutableList<IAEItemStack> single = null;
// protect integrity // protect integrity
if( i.hasNext() ) if( i.hasNext() )
{ {
single = ImmutableList.of( diff.copy() ); final ImmutableList<IAEItemStack> single = ImmutableList.of( diff.copy() );
while( i.hasNext() )
{
final Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> o = i.next();
final IMEMonitorHandlerReceiver<IAEItemStack> receiver = o.getKey();
if( receiver.isValid( o.getValue() ) )
{
receiver.postChange( null, single, src );
}
else
{
i.remove();
}
}
} }
while( i.hasNext() )
{
Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> o = i.next();
IMEMonitorHandlerReceiver<IAEItemStack> receiver = o.getKey();
if( receiver.isValid( o.getValue() ) )
{
receiver.postChange( null, single, src );
}
else
{
i.remove();
}
}
} }
private void markDirty() private void markDirty()
@@ -386,11 +401,11 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
return; return;
} }
CraftingGridCache sg = this.getGrid().getCache( ICraftingGrid.class ); final CraftingGridCache sg = this.getGrid().getCache( ICraftingGrid.class );
if( sg.interestManager.containsKey( diff ) ) if( sg.interestManager.containsKey( diff ) )
{ {
Collection<CraftingWatcher> list = sg.interestManager.get( diff ); final Collection<CraftingWatcher> list = sg.interestManager.get( diff );
if( !list.isEmpty() ) if( !list.isEmpty() )
{ {
@@ -447,10 +462,10 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
{ {
for( TileCraftingTile r : this.tiles ) for( TileCraftingTile r : this.tiles )
{ {
IGridNode gn = r.getActionableNode(); final IGridNode gn = r.getActionableNode();
if( gn != null ) if( gn != null )
{ {
IGrid g = gn.getGrid(); final IGrid g = gn.getGrid();
if( g != null ) if( g != null )
{ {
return r.getActionableNode().getGrid(); return r.getActionableNode().getGrid();
@@ -474,8 +489,8 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
{ {
fuzz = fuzz.copy(); fuzz = fuzz.copy();
fuzz.setStackSize( g.getStackSize() ); fuzz.setStackSize( g.getStackSize() );
IAEItemStack ais = this.inventory.extractItems( fuzz, Actionable.SIMULATE, this.machineSrc ); final IAEItemStack ais = this.inventory.extractItems( fuzz, Actionable.SIMULATE, this.machineSrc );
ItemStack is = ais == null ? null : ais.getItemStack(); final ItemStack is = ais == null ? null : ais.getItemStack();
if( is != null && is.stackSize == g.getStackSize() ) if( is != null && is.stackSize == g.getStackSize() )
{ {
@@ -496,8 +511,8 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
} }
else else
{ {
IAEItemStack ais = this.inventory.extractItems( g.copy(), Actionable.SIMULATE, this.machineSrc ); final IAEItemStack ais = this.inventory.extractItems( g.copy(), Actionable.SIMULATE, this.machineSrc );
ItemStack is = ais == null ? null : ais.getItemStack(); final ItemStack is = ais == null ? null : ais.getItemStack();
if( is == null || is.stackSize < g.getStackSize() ) if( is == null || is.stackSize < g.getStackSize() )
{ {
@@ -527,7 +542,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
this.myLastLink = null; this.myLastLink = null;
this.tasks.clear(); this.tasks.clear();
ImmutableSet<IAEItemStack> items = ImmutableSet.copyOf( this.waitingFor ); final ImmutableSet<IAEItemStack> items = ImmutableSet.copyOf( this.waitingFor );
this.waitingFor.resetStatus(); this.waitingFor.resetStatus();
@@ -576,7 +591,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
} }
this.remainingOperations = this.accelerator + 1 - ( this.usedOps[0] + this.usedOps[1] + this.usedOps[2] ); this.remainingOperations = this.accelerator + 1 - ( this.usedOps[0] + this.usedOps[1] + this.usedOps[2] );
int started = this.remainingOperations; final int started = this.remainingOperations;
if( this.remainingOperations > 0 ) if( this.remainingOperations > 0 )
{ {
@@ -599,17 +614,20 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
private void executeCrafting( IEnergyGrid eg, CraftingGridCache cc ) private void executeCrafting( IEnergyGrid eg, CraftingGridCache cc )
{ {
Iterator<Entry<ICraftingPatternDetails, TaskProgress>> i = this.tasks.entrySet().iterator(); final Iterator<Entry<ICraftingPatternDetails, TaskProgress>> i = this.tasks.entrySet().iterator();
while( i.hasNext() ) while( i.hasNext() )
{ {
Entry<ICraftingPatternDetails, TaskProgress> e = i.next(); final Entry<ICraftingPatternDetails, TaskProgress> e = i.next();
if( e.getValue().value <= 0 ) if( e.getValue().value <= 0 )
{ {
i.remove(); i.remove();
continue; continue;
} }
ICraftingPatternDetails details = e.getKey(); final ICraftingPatternDetails details = e.getKey();
if( this.canCraft( details, details.getCondensedInputs() ) ) if( this.canCraft( details, details.getCondensedInputs() ) )
{ {
InventoryCrafting ic = null; InventoryCrafting ic = null;
@@ -625,9 +643,9 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
{ {
if( ic == null ) if( ic == null )
{ {
IAEItemStack[] input = details.getInputs(); final IAEItemStack[] input = details.getInputs();
double sum = 0; double sum = 0;
for( IAEItemStack anInput : input ) for( IAEItemStack anInput : input )
{ {
if( anInput != null ) if( anInput != null )
@@ -647,10 +665,10 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
for( int x = 0; x < input.length; x++ ) for( int x = 0; x < input.length; x++ )
{ {
if( input[x] != null ) if( input[x] != null )
{ {
found = false; found = false;
if( details.isCraftable() ) if( details.isCraftable() )
{ {
for( IAEItemStack fuzz : this.inventory.getItemList().findFuzzy( input[x], FuzzyMode.IGNORE_ALL ) ) for( IAEItemStack fuzz : this.inventory.getItemList().findFuzzy( input[x], FuzzyMode.IGNORE_ALL ) )
@@ -660,8 +678,8 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
if( details.isValidItemForSlot( x, fuzz.getItemStack(), this.getWorld() ) ) if( details.isValidItemForSlot( x, fuzz.getItemStack(), this.getWorld() ) )
{ {
IAEItemStack ais = this.inventory.extractItems( fuzz, Actionable.MODULATE, this.machineSrc ); final IAEItemStack ais = this.inventory.extractItems( fuzz, Actionable.MODULATE, this.machineSrc );
ItemStack is = ais == null ? null : ais.getItemStack(); final ItemStack is = ais == null ? null : ais.getItemStack();
if( is != null ) if( is != null )
{ {
@@ -675,8 +693,8 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
} }
else else
{ {
IAEItemStack ais = this.inventory.extractItems( input[x].copy(), Actionable.MODULATE, this.machineSrc ); final IAEItemStack ais = this.inventory.extractItems( input[x].copy(), Actionable.MODULATE, this.machineSrc );
ItemStack is = ais == null ? null : ais.getItemStack(); final ItemStack is = ais == null ? null : ais.getItemStack();
if( is != null ) if( is != null )
{ {
@@ -702,7 +720,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
// put stuff back.. // put stuff back..
for( int x = 0; x < ic.getSizeInventory(); x++ ) for( int x = 0; x < ic.getSizeInventory(); x++ )
{ {
ItemStack is = ic.getStackInSlot( x ); final ItemStack is = ic.getStackInSlot( x );
if( is != null ) if( is != null )
{ {
this.inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, this.machineSrc ); this.inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, this.machineSrc );
@@ -731,10 +749,10 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
for( int x = 0; x < ic.getSizeInventory(); x++ ) for( int x = 0; x < ic.getSizeInventory(); x++ )
{ {
ItemStack output = Platform.getContainerItem( ic.getStackInSlot( x ) ); final ItemStack output = Platform.getContainerItem( ic.getStackInSlot( x ) );
if( output != null ) if( output != null )
{ {
IAEItemStack cItem = AEItemStack.create( output ); final IAEItemStack cItem = AEItemStack.create( output );
this.postChange( cItem, this.machineSrc ); this.postChange( cItem, this.machineSrc );
this.waitingFor.add( cItem ); this.waitingFor.add( cItem );
this.postCraftingStatusChange( cItem ); this.postCraftingStatusChange( cItem );
@@ -764,7 +782,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
// put stuff back.. // put stuff back..
for( int x = 0; x < ic.getSizeInventory(); x++ ) for( int x = 0; x < ic.getSizeInventory(); x++ )
{ {
ItemStack is = ic.getStackInSlot( x ); final ItemStack is = ic.getStackInSlot( x );
if( is != null ) if( is != null )
{ {
this.inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, this.machineSrc ); this.inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, this.machineSrc );
@@ -777,14 +795,15 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
private void storeItems() private void storeItems()
{ {
IGrid g = this.getGrid(); final IGrid g = this.getGrid();
if( g == null ) if( g == null )
{ {
return; return;
} }
IStorageGrid sg = g.getCache( IStorageGrid.class ); final IStorageGrid sg = g.getCache( IStorageGrid.class );
IMEInventory<IAEItemStack> ii = sg.getItemInventory(); final IMEInventory<IAEItemStack> ii = sg.getItemInventory();
for( IAEItemStack is : this.inventory.getItemList() ) for( IAEItemStack is : this.inventory.getItemList() )
{ {
@@ -827,9 +846,9 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
return null; return null;
} }
IStorageGrid sg = g.getCache( IStorageGrid.class ); final IStorageGrid sg = g.getCache( IStorageGrid.class );
IMEInventory<IAEItemStack> storage = sg.getItemInventory(); final IMEInventory<IAEItemStack> storage = sg.getItemInventory();
MECraftingInventory ci = new MECraftingInventory( storage, true, false, false ); final MECraftingInventory ci = new MECraftingInventory( storage, true, false, false );
try try
{ {
@@ -843,7 +862,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
this.markDirty(); this.markDirty();
this.updateCPU(); this.updateCPU();
String craftID = this.generateCraftingID(); final String craftID = this.generateCraftingID();
this.myLastLink = new CraftingLink( this.generateLinkData( craftID, requestingMachine == null, false ), this ); this.myLastLink = new CraftingLink( this.generateLinkData( craftID, requestingMachine == null, false ), this );
@@ -854,12 +873,12 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
return this.myLastLink; return this.myLastLink;
} }
ICraftingLink whatLink = new CraftingLink( this.generateLinkData( craftID, false, true ), requestingMachine ); final ICraftingLink whatLink = new CraftingLink( this.generateLinkData( craftID, false, true ), requestingMachine );
this.submitLink( this.myLastLink ); this.submitLink( this.myLastLink );
this.submitLink( whatLink ); this.submitLink( whatLink );
IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList(); final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
this.getListOfItem( list, CraftingItemList.ALL ); this.getListOfItem( list, CraftingItemList.ALL );
for( IAEItemStack ge : list ) for( IAEItemStack ge : list )
{ {
@@ -887,7 +906,8 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
@Override @Override
public boolean isBusy() public boolean isBusy()
{ {
Iterator<Entry<ICraftingPatternDetails, TaskProgress>> i = this.tasks.entrySet().iterator(); final Iterator<Entry<ICraftingPatternDetails, TaskProgress>> i = this.tasks.entrySet().iterator();
while( i.hasNext() ) while( i.hasNext() )
{ {
if( i.next().getValue().value <= 0 ) if( i.next().getValue().value <= 0 )
@@ -925,13 +945,14 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
public boolean isActive() public boolean isActive()
{ {
TileCraftingTile core = this.getCore(); final TileCraftingTile core = this.getCore();
if( core == null ) if( core == null )
{ {
return false; return false;
} }
IGridNode node = core.getActionableNode(); final IGridNode node = core.getActionableNode();
if( node == null ) if( node == null )
{ {
return false; return false;
@@ -942,16 +963,16 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
private String generateCraftingID() private String generateCraftingID()
{ {
long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
int hash = System.identityHashCode( this ); final int hash = System.identityHashCode( this );
int hmm = this.finalOutput == null ? 0 : this.finalOutput.hashCode(); final int hmm = this.finalOutput == null ? 0 : this.finalOutput.hashCode();
return Long.toString( now, Character.MAX_RADIX ) + '-' + Integer.toString( hash, Character.MAX_RADIX ) + '-' + Integer.toString( hmm, Character.MAX_RADIX ); return Long.toString( now, Character.MAX_RADIX ) + '-' + Integer.toString( hash, Character.MAX_RADIX ) + '-' + Integer.toString( hmm, Character.MAX_RADIX );
} }
private NBTTagCompound generateLinkData( String craftingID, boolean standalone, boolean req ) private NBTTagCompound generateLinkData( String craftingID, boolean standalone, boolean req )
{ {
NBTTagCompound tag = new NBTTagCompound(); final NBTTagCompound tag = new NBTTagCompound();
tag.setString( "CraftID", craftingID ); tag.setString( "CraftID", craftingID );
tag.setBoolean( "canceled", false ); tag.setBoolean( "canceled", false );
@@ -966,7 +987,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
{ {
if( this.getGrid() != null ) if( this.getGrid() != null )
{ {
CraftingGridCache cc = this.getGrid().getCache( ICraftingGrid.class ); final CraftingGridCache cc = this.getGrid().getCache( ICraftingGrid.class );
cc.addLink( (CraftingLink) myLastLink2 ); cc.addLink( (CraftingLink) myLastLink2 );
} }
} }
@@ -1043,6 +1064,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
public IAEItemStack getItemStack( IAEItemStack what, CraftingItemList storage2 ) public IAEItemStack getItemStack( IAEItemStack what, CraftingItemList storage2 )
{ {
IAEItemStack is; IAEItemStack is;
switch( storage2 ) switch( storage2 )
{ {
case STORAGE: case STORAGE:
@@ -1092,15 +1114,15 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
if( this.myLastLink != null ) if( this.myLastLink != null )
{ {
NBTTagCompound link = new NBTTagCompound(); final NBTTagCompound link = new NBTTagCompound();
this.myLastLink.writeToNBT( link ); this.myLastLink.writeToNBT( link );
data.setTag( "link", link ); data.setTag( "link", link );
} }
NBTTagList list = new NBTTagList(); final NBTTagList list = new NBTTagList();
for( Entry<ICraftingPatternDetails, TaskProgress> e : this.tasks.entrySet() ) for( Entry<ICraftingPatternDetails, TaskProgress> e : this.tasks.entrySet() )
{ {
NBTTagCompound item = this.writeItem( AEItemStack.create( e.getKey().getPattern() ) ); final NBTTagCompound item = this.writeItem( AEItemStack.create( e.getKey().getPattern() ) );
item.setLong( "craftingProgress", e.getValue().value ); item.setLong( "craftingProgress", e.getValue().value );
list.appendTag( item ); list.appendTag( item );
} }
@@ -1115,7 +1137,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
private NBTTagCompound writeItem( IAEItemStack finalOutput2 ) private NBTTagCompound writeItem( IAEItemStack finalOutput2 )
{ {
NBTTagCompound out = new NBTTagCompound(); final NBTTagCompound out = new NBTTagCompound();
if( finalOutput2 != null ) if( finalOutput2 != null )
{ {
@@ -1127,7 +1149,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
private NBTTagList writeList( IItemList<IAEItemStack> myList ) private NBTTagList writeList( IItemList<IAEItemStack> myList )
{ {
NBTTagList out = new NBTTagList(); final NBTTagList out = new NBTTagList();
for( IAEItemStack ais : myList ) for( IAEItemStack ais : myList )
{ {
@@ -1139,7 +1161,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
public void done() public void done()
{ {
TileCraftingTile core = this.getCore(); final TileCraftingTile core = this.getCore();
core.isCoreBlock = true; core.isCoreBlock = true;
@@ -1166,23 +1188,23 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
if( data.hasKey( "link" ) ) if( data.hasKey( "link" ) )
{ {
NBTTagCompound link = data.getCompoundTag( "link" ); final NBTTagCompound link = data.getCompoundTag( "link" );
this.myLastLink = new CraftingLink( link, this ); this.myLastLink = new CraftingLink( link, this );
this.submitLink( this.myLastLink ); this.submitLink( this.myLastLink );
} }
NBTTagList list = data.getTagList( "tasks", 10 ); final NBTTagList list = data.getTagList( "tasks", 10 );
for( int x = 0; x < list.tagCount(); x++ ) for( int x = 0; x < list.tagCount(); x++ )
{ {
NBTTagCompound item = list.getCompoundTagAt( x ); final NBTTagCompound item = list.getCompoundTagAt( x );
IAEItemStack pattern = AEItemStack.loadItemStackFromNBT( item ); final IAEItemStack pattern = AEItemStack.loadItemStackFromNBT( item );
if( pattern != null && pattern.getItem() instanceof ICraftingPatternItem ) if( pattern != null && pattern.getItem() instanceof ICraftingPatternItem )
{ {
ICraftingPatternItem cpi = (ICraftingPatternItem) pattern.getItem(); final ICraftingPatternItem cpi = (ICraftingPatternItem) pattern.getItem();
ICraftingPatternDetails details = cpi.getPatternForItem( pattern.getItemStack(), this.getWorld() ); final ICraftingPatternDetails details = cpi.getPatternForItem( pattern.getItemStack(), this.getWorld() );
if( details != null ) if( details != null )
{ {
TaskProgress tp = new TaskProgress(); final TaskProgress tp = new TaskProgress();
tp.value = item.getLong( "craftingProgress" ); tp.value = item.getLong( "craftingProgress" );
this.tasks.put( details, tp ); this.tasks.put( details, tp );
} }
@@ -1223,7 +1245,8 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
private IItemList<IAEItemStack> readList( NBTTagList tag ) private IItemList<IAEItemStack> readList( NBTTagList tag )
{ {
IItemList<IAEItemStack> out = AEApi.instance().storage().createItemList(); final IItemList<IAEItemStack> out = AEApi.instance().storage().createItemList();
if( tag == null ) if( tag == null )
{ {
return out; return out;
@@ -1231,7 +1254,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
for( int x = 0; x < tag.tagCount(); x++ ) for( int x = 0; x < tag.tagCount(); x++ )
{ {
IAEItemStack ais = AEItemStack.loadItemStackFromNBT( tag.getCompoundTagAt( x ) ); final IAEItemStack ais = AEItemStack.loadItemStackFromNBT( tag.getCompoundTagAt( x ) );
if( ais != null ) if( ais != null )
{ {
out.add( ais ); out.add( ais );
@@ -1248,13 +1271,14 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
public boolean isMaking( IAEItemStack what ) public boolean isMaking( IAEItemStack what )
{ {
IAEItemStack wat = this.waitingFor.findPrecise( what ); final IAEItemStack wat = this.waitingFor.findPrecise( what );
return wat != null && wat.getStackSize() > 0; return wat != null && wat.getStackSize() > 0;
} }
public void breakCluster() public void breakCluster()
{ {
TileCraftingTile t = this.getCore(); final TileCraftingTile t = this.getCore();
if( t != null ) if( t != null )
{ {
t.breakCluster(); t.breakCluster();
@@ -1265,9 +1289,10 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
{ {
this.lastTime = System.nanoTime(); this.lastTime = System.nanoTime();
this.elapsedTime = 0; this.elapsedTime = 0;
int itemCount = 0;
IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList(); int itemCount = 0;
final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
this.getListOfItem( list, CraftingItemList.ACTIVE ); this.getListOfItem( list, CraftingItemList.ACTIVE );
this.getListOfItem( list, CraftingItemList.PENDING ); this.getListOfItem( list, CraftingItemList.PENDING );
@@ -1305,7 +1330,6 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
static class TaskProgress static class TaskProgress
{ {
long value; long value;
} }
} }