diff --git a/src/main/java/appeng/me/GridNode.java b/src/main/java/appeng/me/GridNode.java index 9b80b3cd7..d2c31eee1 100644 --- a/src/main/java/appeng/me/GridNode.java +++ b/src/main/java/appeng/me/GridNode.java @@ -320,7 +320,7 @@ public class GridNode implements IGridNode, IPathItem { final IPathingGrid pg = g.getCache( IPathingGrid.class ); final IEnergyGrid eg = g.getCache( IEnergyGrid.class ); - return this.meetsChannelRequirements() && eg.isNetworkPowered() && !pg.isNetworkBooting(); + return eg.isNetworkPowered() && !pg.isNetworkBooting() && this.meetsChannelRequirements(); } return false; } diff --git a/src/main/java/appeng/me/cache/NetworkMonitor.java b/src/main/java/appeng/me/cache/NetworkMonitor.java index 7d2d4c90f..efd417b07 100644 --- a/src/main/java/appeng/me/cache/NetworkMonitor.java +++ b/src/main/java/appeng/me/cache/NetworkMonitor.java @@ -31,7 +31,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; +import com.google.common.collect.Queues; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; @@ -49,7 +49,7 @@ import appeng.me.storage.ItemWatcher; public class NetworkMonitor> implements IMEMonitor { @Nonnull - private static final Deque> GLOBAL_DEPTH = Lists.newLinkedList(); + private static final Deque> GLOBAL_DEPTH = Queues.newArrayDeque(); @Nonnull private final GridStorageCache myGridCache; diff --git a/src/main/java/appeng/me/cache/PathGridCache.java b/src/main/java/appeng/me/cache/PathGridCache.java index 80e0c5422..ec36033eb 100644 --- a/src/main/java/appeng/me/cache/PathGridCache.java +++ b/src/main/java/appeng/me/cache/PathGridCache.java @@ -402,7 +402,7 @@ public class PathGridCache implements IPathingGrid @Override public boolean isNetworkBooting() { - return !this.active.isEmpty() && !this.booting; + return !this.booting && !this.active.isEmpty(); } @Override diff --git a/src/main/java/appeng/me/storage/MEMonitorIInventory.java b/src/main/java/appeng/me/storage/MEMonitorIInventory.java index f27d7af46..50f4a1b2b 100644 --- a/src/main/java/appeng/me/storage/MEMonitorIInventory.java +++ b/src/main/java/appeng/me/storage/MEMonitorIInventory.java @@ -19,9 +19,10 @@ package appeng.me.storage; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; +import java.util.List; import java.util.Map.Entry; import java.util.NavigableMap; import java.util.concurrent.ConcurrentSkipListMap; @@ -144,7 +145,7 @@ public class MEMonitorIInventory implements IMEMonitor, ITickingMo public TickRateModulation onTick() { - final LinkedList changes = new LinkedList<>(); + final List changes = new ArrayList<>(); this.list.resetStatus(); int high = 0; diff --git a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java index 2f6472795..4de5d52d9 100644 --- a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java +++ b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java @@ -259,7 +259,6 @@ class ItemHandlerAdapter implements IMEInventory, IBaseMonitor, IBaseMonitor update() { - List changes = new ArrayList<>(); - - int slots = this.itemHandler.getSlots(); + final List changes = new ArrayList<>(); + final int slots = this.itemHandler.getSlots(); // Make room for new slots - if( slots > this.cachedStacks.length ) + if( slots > this.cachedAeStacks.length ) { - this.cachedStacks = Arrays.copyOf( this.cachedStacks, slots ); this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots ); } for( int slot = 0; slot < slots; slot++ ) { // Save the old stuff - ItemStack oldIS = this.getItemStackInCachedSlot( slot ); - IAEItemStack oldAeIS = this.cachedAeStacks[slot]; + final IAEItemStack oldAeIS = this.cachedAeStacks[slot]; + final ItemStack newIS = this.itemHandler.getStackInSlot( slot ); - ItemStack newIS = this.itemHandler.getStackInSlot( slot ); - - if( isDifferent( newIS, oldIS ) ) - { - this.addItemChange( slot, oldAeIS, newIS, changes ); - } - else if( !newIS.isEmpty() && !oldIS.isEmpty() ) - { - this.addPossibleStackSizeChange( slot, oldAeIS, newIS, changes ); - } + this.handlePossibleSlotChanges( slot, oldAeIS, newIS, changes ); } // Handle cases where the number of slots actually is lower now than before - if( slots < this.cachedStacks.length ) + if( slots < this.cachedAeStacks.length ) { - for( int slot = slots; slot < this.cachedStacks.length; slot++ ) + for( int slot = slots; slot < this.cachedAeStacks.length; slot++ ) { - IAEItemStack aeStack = this.cachedAeStacks[slot]; + final IAEItemStack aeStack = this.cachedAeStacks[slot]; + if( aeStack != null ) { - IAEItemStack a = aeStack.copy(); + final IAEItemStack a = aeStack.copy(); a.setStackSize( -a.getStackSize() ); changes.add( a ); } } // Reduce the cache size - this.cachedStacks = Arrays.copyOf( this.cachedStacks, slots ); this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots ); } return changes; } - private void addPossibleStackSizeChange( int slot, IAEItemStack oldAeIS, ItemStack newIS, List changes ) + private void handlePossibleSlotChanges( int slot, IAEItemStack oldAeIS, ItemStack newIS, List changes ) + { + if( oldAeIS != null && oldAeIS.isSameType( newIS ) ) + { + this.handleStackSizeChanged( slot, oldAeIS, newIS, changes ); + } + else + { + this.handleItemChanged( slot, oldAeIS, newIS, changes ); + } + } + + private void handleStackSizeChanged( int slot, IAEItemStack oldAeIS, ItemStack newIS, List changes ) { // Still the same item, but amount might have changed - long diff = newIS.getCount() - oldAeIS.getStackSize(); + final long diff = newIS.getCount() - oldAeIS.getStackSize(); if( diff != 0 ) { - IAEItemStack stack = oldAeIS.copy(); + final IAEItemStack stack = oldAeIS.copy(); stack.setStackSize( newIS.getCount() ); - this.cachedStacks[slot] = newIS; this.cachedAeStacks[slot] = stack; final IAEItemStack a = stack.copy(); @@ -340,28 +339,12 @@ class ItemHandlerAdapter implements IMEInventory, IBaseMonitor this.cachedStacks.length ) - { - return ItemStack.EMPTY; - } - - if( this.cachedStacks[pos] == null ) - { - return ItemStack.EMPTY; - } - - return this.cachedStacks[pos]; - } - - private void addItemChange( int slot, IAEItemStack oldAeIS, ItemStack newIS, List changes ) + private void handleItemChanged( int slot, IAEItemStack oldAeIS, ItemStack newIS, List changes ) { // Completely different item - this.cachedStacks[slot] = newIS; this.cachedAeStacks[slot] = AEItemStack.fromItemStack( newIS ); - // If we had a stack previously in this slot, notify the newtork about its disappearance + // If we had a stack previously in this slot, notify the network about its disappearance if( oldAeIS != null ) { oldAeIS.setStackSize( -oldAeIS.getStackSize() ); @@ -374,16 +357,6 @@ class ItemHandlerAdapter implements IMEInventory, IBaseMonitor implements IAEItemS @Override public String toString() { - return this.getDefinition().toString(); + return this.getStackSize() + "x" + this.getDefinition().getItem().getUnlocalizedName() + "@" + this.getDefinition().getItemDamage(); } @SideOnly( Side.CLIENT ) @@ -347,7 +347,7 @@ public final class AEItemStack extends AEStack implements IAEItemS @Override public ItemStack asItemStackRepresentation() { - return getDefinition().copy(); + return this.getDefinition().copy(); } @Override