From 533fb5c34be26dab03788298d20e8da697ebc9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salom=C3=A3o?= Date: Sat, 8 May 2021 19:40:58 -0300 Subject: [PATCH 1/2] initial test --- .../parts/misc/ItemRepositoryAdapter.java | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/main/java/appeng/parts/misc/ItemRepositoryAdapter.java b/src/main/java/appeng/parts/misc/ItemRepositoryAdapter.java index 1de85f50d..d70a4d3af 100644 --- a/src/main/java/appeng/parts/misc/ItemRepositoryAdapter.java +++ b/src/main/java/appeng/parts/misc/ItemRepositoryAdapter.java @@ -71,14 +71,9 @@ class ItemRepositoryAdapter implements IMEInventory, IBaseMonitor< if( type == Actionable.MODULATE ) { - try - { - this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() ); - } - catch( GridAccessException ex ) - { - // meh - } + 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(); } return AEItemStack.fromItemStack( remaining ); @@ -107,15 +102,27 @@ class ItemRepositoryAdapter implements IMEInventory, IBaseMonitor< 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; + } + } } } From 366b31b3aa15875bdf7b5e2631db7578d187123c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salom=C3=A3o?= Date: Sat, 8 May 2021 22:11:13 -0300 Subject: [PATCH 2/2] import bus optimization --- .../parts/automation/PartImportBus.java | 12 ++++++++--- .../parts/misc/ItemRepositoryAdapter.java | 20 +++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/appeng/parts/automation/PartImportBus.java b/src/main/java/appeng/parts/automation/PartImportBus.java index a56b5851f..24c10513a 100644 --- a/src/main/java/appeng/parts/automation/PartImportBus.java +++ b/src/main/java/appeng/parts/automation/PartImportBus.java @@ -219,8 +219,9 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin { final int toSend = this.calculateMaximumAmountToImport( myAdaptor, whatToImport, inv, fzMode ); - if( toSend == 0 ){ - return false; + if( toSend == 0 ) + { + return true; } final ItemStack newItems; @@ -291,9 +292,14 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin 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; } diff --git a/src/main/java/appeng/parts/misc/ItemRepositoryAdapter.java b/src/main/java/appeng/parts/misc/ItemRepositoryAdapter.java index d70a4d3af..bcd7886fb 100644 --- a/src/main/java/appeng/parts/misc/ItemRepositoryAdapter.java +++ b/src/main/java/appeng/parts/misc/ItemRepositoryAdapter.java @@ -72,8 +72,24 @@ class ItemRepositoryAdapter implements IMEInventory, IBaseMonitor< 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 );