Rework AEItemStack (#3091)

* Use itemstack as itemdef
* HIGH_TAG/LOW_TAG should be compared both directions
* Remove getTagCompound
* Make Itemlist implementation independent
* Cache item id for performance reasons
* Add preconditions to saveguard against external meddling
* Chache itemDamage
* Remove IAEStackSearchKey for now, rename getDisplayStack
This commit is contained in:
fscan
2017-09-30 17:18:30 +02:00
committed by yueh
parent 2ed7a5598a
commit 1e15b23506
75 changed files with 559 additions and 1512 deletions
+16 -18
View File
@@ -36,7 +36,7 @@ import appeng.api.storage.data.IItemList;
public final class ItemList implements IItemList<IAEItemStack>
{
private final NavigableMap<IAEItemStack, IAEItemStack> records = new ConcurrentSkipListMap<>();
private final NavigableMap<AESharedItemStack, IAEItemStack> records = new ConcurrentSkipListMap<>();
@Override
public void add( final IAEItemStack option )
@@ -46,7 +46,7 @@ public final class ItemList implements IItemList<IAEItemStack>
return;
}
final IAEItemStack st = this.records.get( option );
final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() );
if( st != null )
{
@@ -67,7 +67,7 @@ public final class ItemList implements IItemList<IAEItemStack>
return null;
}
return this.records.get( itemStack );
return this.records.get( ( (AEItemStack) itemStack ).getSharedStack() );
}
@Override
@@ -80,15 +80,13 @@ public final class ItemList implements IItemList<IAEItemStack>
final AEItemStack ais = (AEItemStack) filter;
if( ais.isOre() )
return ais.getOre().map( or ->
{
final OreReference or = ais.getDefinition().getIsOre();
if( or.getAEEquivalents().size() == 1 )
{
final IAEItemStack is = or.getAEEquivalents().get( 0 );
return this.findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
return this.findFuzzyDamage( is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
}
else
{
@@ -96,14 +94,13 @@ public final class ItemList implements IItemList<IAEItemStack>
for( final IAEItemStack is : or.getAEEquivalents() )
{
output.addAll( this.findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
output.addAll( this.findFuzzyDamage( is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
}
return output;
}
}
return this.findFuzzyDamage( ais, fuzzy, false );
} )
.orElse( this.findFuzzyDamage( ais, fuzzy, false ) );
}
@Override
@@ -120,7 +117,7 @@ public final class ItemList implements IItemList<IAEItemStack>
return;
}
final IAEItemStack st = this.records.get( option );
final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() );
if( st != null )
{
@@ -146,7 +143,7 @@ public final class ItemList implements IItemList<IAEItemStack>
return;
}
final IAEItemStack st = this.records.get( option );
final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() );
if( st != null )
{
@@ -169,7 +166,7 @@ public final class ItemList implements IItemList<IAEItemStack>
return;
}
final IAEItemStack st = this.records.get( option );
final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() );
if( st != null )
{
@@ -219,13 +216,14 @@ public final class ItemList implements IItemList<IAEItemStack>
private IAEItemStack putItemRecord( final IAEItemStack itemStack )
{
return this.records.put( itemStack, itemStack );
return this.records.put( ( (AEItemStack) itemStack ).getSharedStack(), itemStack );
}
private Collection<IAEItemStack> findFuzzyDamage( final AEItemStack filter, final FuzzyMode fuzzy, final boolean ignoreMeta )
private Collection<IAEItemStack> findFuzzyDamage( final IAEItemStack filter, final FuzzyMode fuzzy, final boolean ignoreMeta )
{
final IAEItemStack low = filter.getLow( fuzzy, ignoreMeta );
final IAEItemStack high = filter.getHigh( fuzzy, ignoreMeta );
final AEItemStack itemStack = (AEItemStack) filter;
final AESharedItemStack low = itemStack.getSharedStack().getLowerBound( fuzzy, ignoreMeta );
final AESharedItemStack high = itemStack.getSharedStack().getUpperBound( fuzzy, ignoreMeta );
return this.records.subMap( low, true, high, true ).descendingMap().values();
}