Skip to content

Commit

Permalink
Merge branch 'iir-cache' into AE2-Omnifactory
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers committed May 9, 2021
2 parents 62d1d90 + 366b31b commit f3877aa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
12 changes: 9 additions & 3 deletions src/main/java/appeng/parts/automation/PartImportBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ private boolean importStuff( final InventoryAdaptor myAdaptor, final IAEItemStac
{
final int toSend = this.calculateMaximumAmountToImport( myAdaptor, whatToImport, inv, fzMode );

if( toSend == 0 ){
return false;
if( toSend == 0 )
{
return true;
}

final ItemStack newItems;
Expand Down Expand Up @@ -291,9 +292,14 @@ private int calculateMaximumAmountToImport( final InventoryAdaptor myAdaptor, fi
itemAmountNotStorable = inv.injectItems( AEItemStack.fromItemStack( simResult ), Actionable.SIMULATE, this.source );
}

if( simResult.isEmpty() )
{
return 0;
}

if( itemAmountNotStorable != null )
{
if (simResult.getCount() == itemAmountNotStorable.getStackSize())
if( simResult.getCount() == itemAmountNotStorable.getStackSize() )
{
return 0;
}
Expand Down
43 changes: 33 additions & 10 deletions src/main/java/appeng/parts/misc/ItemRepositoryAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,24 @@ public IAEItemStack injectItems( IAEItemStack iox, Actionable type, IActionSourc

if( type == Actionable.MODULATE )
{
try
if (this.cache.cachedAeStacks.length == 0) this.cache.update();
boolean found = false;
for (IAEItemStack iaeItemStack : this.cache.cachedAeStacks)
{
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
if( iaeItemStack == null )
{
continue;
}
if( iaeItemStack.equals( iox ) )
{
found = true;
iaeItemStack.incStackSize( iox.getStackSize() );
}
}
catch( GridAccessException ex )
if (!found)
{
// meh
this.cache.cachedAeStacks = Arrays.copyOf( this.cache.cachedAeStacks, this.cache.cachedAeStacks.length + 1 );
this.cache.cachedAeStacks[this.cache.cachedAeStacks.length - 1] = iox.copy();
}
}

Expand Down Expand Up @@ -107,15 +118,27 @@ public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IAction

if( !extracted.isEmpty() )
{
if (this.cache.cachedAeStacks.length == 0) this.cache.update();
IAEItemStack iaeExtracted = AEItemStack.fromItemStack( extracted );

if( mode == Actionable.MODULATE )
{
try
for ( int i = 0; i < this.cache.cachedAeStacks.length; i++ )
{
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
}
catch( GridAccessException ex )
{
// meh
IAEItemStack iaeItemStack = this.cache.cachedAeStacks[i];
if( iaeExtracted.equals( iaeItemStack ) )
{
if( iaeExtracted.getStackSize() >= iaeItemStack.getStackSize() )
{
iaeExtracted.decStackSize( iaeItemStack.getStackSize() );
this.cache.cachedAeStacks[i] = null;
}
else
{
iaeItemStack.decStackSize( iaeExtracted.getStackSize() );
break;
}
}
}
}

Expand Down

0 comments on commit f3877aa

Please sign in to comment.