Compare commits

...

5 Commits

Author SHA1 Message Date
yueh 84c065ff28 Fixes #3394: Use cache to avoid using removed IItemHandler (#3395) 2018-03-04 14:33:45 +01:00
yueh c9b92a81a3 Fixes #3405: Use cached tooltip for search, then copy craftable as zero. (#3406) 2018-03-04 14:33:23 +01:00
yueh eed4776c6f Fixes #3389: Prevent inventory cache from becoming unmatched. (#3390)
Use slightly faster ArrayDeqeue instead of LinkedList.
Check boolean fields before more complex datatypes
2018-02-17 19:10:09 +01:00
yueh 22807bc619 Updated maven repos. (#3391) 2018-02-16 18:43:09 +01:00
Florian Scandella ae352c093e fix typo in AEItemStack#fuzzyComparison 2018-02-10 19:02:32 +01:00
8 changed files with 73 additions and 88 deletions
+8 -3
View File
@@ -31,7 +31,7 @@ repositories {
maven {
name = "Tesla repo"
url "http://maven.epoxide.xyz"
url "http://maven.mcmoddev.com"
}
maven {
@@ -48,7 +48,7 @@ repositories {
name 'tterrag maven'
url "http://maven.tterrag.com/"
}
maven { // McJtyLib
name 'mcjty'
url "http://maven.k-4u.nl/"
@@ -58,11 +58,16 @@ repositories {
name 'tehnut'
url "http://tehnut.info/maven"
}
maven { // CraftTweaker
name 'jared maven'
url "http://maven.blamejared.com/"
}
maven { // modmaven, maven proxy
name 'modmaven'
url "https://modmaven.k-4u.nl/"
}
}
configurations {
+20 -14
View File
@@ -21,6 +21,7 @@ package appeng.client.me;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
@@ -112,6 +113,8 @@ public class ItemRepo
final Enum viewMode = this.sortSrc.getSortDisplay();
final Enum searchMode = AEConfig.instance().getConfigManager().getSetting( Settings.SEARCH_MODE );
final boolean needsZeroCopy = viewMode == ViewItems.CRAFTABLE;
if( searchMode == SearchBoxMode.JEI_AUTOSEARCH || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH || searchMode == SearchBoxMode.JEI_AUTOSEARCH_KEEP || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH_KEEP )
{
this.updateJEI( this.searchString );
@@ -160,43 +163,46 @@ public class ItemRepo
continue;
}
if( viewMode == ViewItems.CRAFTABLE )
{
is = is.copy();
is.setStackSize( 0 );
}
if( viewMode == ViewItems.STORED && is.getStackSize() == 0 )
{
continue;
}
final String dspName = searchMod ? Platform.getModId( is ) : Platform.getItemDisplayName( is );
boolean foundMatchingItemStack = false;
notDone = true;
if( m.matcher( dspName.toLowerCase() ).find() )
{
this.view.add( is );
notDone = false;
foundMatchingItemStack = true;
}
if( terminalSearchToolTips && notDone && !searchMod )
{
for( final Object lp : Platform.getTooltip( is ) )
final List<String> tooltip = Platform.getTooltip( is );
for( final String line : tooltip )
{
if( lp instanceof String && m.matcher( (CharSequence) lp ).find() )
if( m.matcher( line ).find() )
{
this.view.add( is );
foundMatchingItemStack = true;
notDone = false;
break;
}
}
}
/*
* if ( terminalSearchMods && notDone ) { if ( m.matcher( Platform.getMod( is.getItemStack() ) ).find() ) {
* view.add( is ); notDone = false; } }
*/
if( foundMatchingItemStack )
{
if( needsZeroCopy )
{
is = is.copy();
is.setStackSize( 0 );
}
this.view.add( is );
}
}
final Enum SortBy = this.sortSrc.getSortBy();
+1 -1
View File
@@ -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;
}
+2 -2
View File
@@ -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<T extends IAEStack<T>> implements IMEMonitor<T>
{
@Nonnull
private static final Deque<NetworkMonitor<?>> GLOBAL_DEPTH = Lists.newLinkedList();
private static final Deque<NetworkMonitor<?>> GLOBAL_DEPTH = Queues.newArrayDeque();
@Nonnull
private final GridStorageCache myGridCache;
+1 -1
View File
@@ -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
@@ -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<IAEItemStack>, ITickingMo
public TickRateModulation onTick()
{
final LinkedList<IAEItemStack> changes = new LinkedList<>();
final List<IAEItemStack> changes = new ArrayList<>();
this.list.resetStatus();
int high = 0;
@@ -212,13 +212,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
@Override
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
{
for( int i = 0; i < this.itemHandler.getSlots(); i++ )
{
out.addStorage( AEItemStack.fromItemStack( this.itemHandler.getStackInSlot( i ) ) );
}
return out;
return this.cache.getAvailableItems( out );
}
@Override
@@ -259,7 +253,6 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
private static class InventoryCache
{
private ItemStack[] cachedStacks = new ItemStack[0];
private IAEItemStack[] cachedAeStacks = new IAEItemStack[0];
private final IItemHandler itemHandler;
@@ -268,70 +261,76 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
this.itemHandler = itemHandler;
}
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
{
Arrays.stream( this.cachedAeStacks ).forEach( out::add );
return out;
}
public List<IAEItemStack> update()
{
List<IAEItemStack> changes = new ArrayList<>();
int slots = this.itemHandler.getSlots();
final List<IAEItemStack> 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<IAEItemStack> changes )
private void handlePossibleSlotChanges( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack>, IBaseMonitor<IAE
}
}
private ItemStack getItemStackInCachedSlot( int pos )
{
if( pos > 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<IAEItemStack> changes )
private void handleItemChanged( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> 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<IAEItemStack>, IBaseMonitor<IAE
changes.add( this.cachedAeStacks[slot] );
}
}
private static boolean isDifferent( final ItemStack a, final ItemStack b )
{
if( a == b && b.isEmpty() )
{
return false;
}
return a.isEmpty() || b.isEmpty() || !Platform.itemComparisons().isSameItem( a, b );
}
}
}
@@ -180,7 +180,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return this.fuzzyItemStackComparison( itemStack, otherStack, mode );
}
if( st instanceof IAEItemStack )
if( st instanceof ItemStack )
{
final ItemStack otherStack = (ItemStack) st;
@@ -294,7 +294,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> 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<IAEItemStack> implements IAEItemS
@Override
public ItemStack asItemStackRepresentation()
{
return getDefinition().copy();
return this.getDefinition().copy();
}
@Override