Skip to content

Commit

Permalink
import bus optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers committed May 9, 2021
1 parent 533fb5c commit 366b31b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 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
20 changes: 18 additions & 2 deletions src/main/java/appeng/parts/misc/ItemRepositoryAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,24 @@ public IAEItemStack injectItems( IAEItemStack iox, Actionable type, IActionSourc
if( type == Actionable.MODULATE )
{
if (this.cache.cachedAeStacks.length == 0) this.cache.update();
this.cache.cachedAeStacks = Arrays.copyOf( this.cache.cachedAeStacks, this.cache.cachedAeStacks.length + 1 );
this.cache.cachedAeStacks[this.cache.cachedAeStacks.length - 1] = iox.copy();
boolean found = false;
for (IAEItemStack iaeItemStack : this.cache.cachedAeStacks)
{
if( iaeItemStack == null )
{
continue;
}
if( iaeItemStack.equals( iox ) )
{
found = true;
iaeItemStack.incStackSize( iox.getStackSize() );
}
}
if (!found)
{
this.cache.cachedAeStacks = Arrays.copyOf( this.cache.cachedAeStacks, this.cache.cachedAeStacks.length + 1 );
this.cache.cachedAeStacks[this.cache.cachedAeStacks.length - 1] = iox.copy();
}
}

return AEItemStack.fromItemStack( remaining );
Expand Down

0 comments on commit 366b31b

Please sign in to comment.