Reverts some of the changes to ItemList.
Removes the split collection as in some rare corner cases the insertion order is important to maintain the correct data in terms of self cleaning. Keeps the general cleanups and split of Fluid/ItemList. Fixes #1964
This commit is contained in:
parent
18d10e4cc4
commit
f9835e589a
3 changed files with 19 additions and 61 deletions
|
@ -27,6 +27,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
|
@ -418,7 +419,7 @@ public class CellInventory implements ICellInventory
|
|||
}
|
||||
|
||||
// clean any old crusty stuff...
|
||||
for(; x < oldStoredItems && x < this.maxItemTypes; x++ )
|
||||
for( ; x < oldStoredItems && x < this.maxItemTypes; x++ )
|
||||
{
|
||||
this.tagCompound.removeTag( itemSlots[x] );
|
||||
this.tagCompound.removeTag( itemSlotCount[x] );
|
||||
|
|
|
@ -21,14 +21,11 @@ package appeng.util.item;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
@ -40,7 +37,7 @@ import com.google.common.collect.Lists;
|
|||
public final class ItemList implements IItemList<IAEItemStack>
|
||||
{
|
||||
|
||||
private final Map<Item, NavigableMap<IAEItemStack, IAEItemStack>> records = new IdentityHashMap<Item, NavigableMap<IAEItemStack, IAEItemStack>>();
|
||||
private final NavigableMap<IAEItemStack, IAEItemStack> records = new ConcurrentSkipListMap<IAEItemStack, IAEItemStack>();
|
||||
|
||||
@Override
|
||||
public void add( final IAEItemStack option )
|
||||
|
@ -50,7 +47,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.getItemRecord( option.getItem() ).get( option );
|
||||
final IAEItemStack st = this.records.get( option );
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
|
@ -71,7 +68,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
return null;
|
||||
}
|
||||
|
||||
return this.getItemRecord( itemStack.getItem() ).get( itemStack );
|
||||
return this.records.get( itemStack );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -124,7 +121,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.getItemRecord( option.getItem() ).get( option );
|
||||
final IAEItemStack st = this.records.get( option );
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
|
@ -150,7 +147,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.getItemRecord( option.getItem() ).get( option );
|
||||
final IAEItemStack st = this.records.get( option );
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
|
@ -173,7 +170,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.getItemRecord( option.getItem() ).get( option );
|
||||
final IAEItemStack st = this.records.get( option );
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
|
@ -203,14 +200,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
@Override
|
||||
public int size()
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
for( final Map<IAEItemStack, IAEItemStack> element : this.records.values() )
|
||||
{
|
||||
size += element.size();
|
||||
}
|
||||
|
||||
return size;
|
||||
return this.records.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -228,22 +218,9 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
}
|
||||
}
|
||||
|
||||
private NavigableMap<IAEItemStack, IAEItemStack> getItemRecord( final Item item )
|
||||
{
|
||||
NavigableMap<IAEItemStack, IAEItemStack> itemRecords = this.records.get( item );
|
||||
|
||||
if( itemRecords == null )
|
||||
{
|
||||
itemRecords = new ConcurrentSkipListMap<IAEItemStack, IAEItemStack>();
|
||||
this.records.put( item, itemRecords );
|
||||
}
|
||||
|
||||
return itemRecords;
|
||||
}
|
||||
|
||||
private IAEItemStack putItemRecord( final IAEItemStack itemStack )
|
||||
{
|
||||
return this.getItemRecord( itemStack.getItem() ).put( itemStack, itemStack );
|
||||
return this.records.put( itemStack, itemStack );
|
||||
}
|
||||
|
||||
private Collection<IAEItemStack> findFuzzyDamage( final AEItemStack filter, final FuzzyMode fuzzy, final boolean ignoreMeta )
|
||||
|
@ -251,6 +228,6 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
final IAEItemStack low = filter.getLow( fuzzy, ignoreMeta );
|
||||
final IAEItemStack high = filter.getHigh( fuzzy, ignoreMeta );
|
||||
|
||||
return this.getItemRecord( filter.getItem() ).subMap( low, true, high, true ).descendingMap().values();
|
||||
return this.records.subMap( low, true, high, true ).descendingMap().values();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package appeng.util.item;
|
|||
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
@ -29,47 +28,28 @@ import appeng.api.storage.data.IAEItemStack;
|
|||
public class MeaningfulItemIterator<T extends IAEItemStack> implements Iterator<T>
|
||||
{
|
||||
|
||||
private final Iterator<NavigableMap<T, T>> parent;
|
||||
private Iterator<T> innerIterater = null;
|
||||
private final Iterator<T> parent;
|
||||
private T next;
|
||||
|
||||
public MeaningfulItemIterator( final Iterator<NavigableMap<T, T>> iterator )
|
||||
public MeaningfulItemIterator( final Iterator<T> iterator )
|
||||
{
|
||||
this.parent = iterator;
|
||||
|
||||
if( this.parent.hasNext() )
|
||||
{
|
||||
this.innerIterater = this.parent.next().values().iterator();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
if( this.innerIterater == null )
|
||||
while( this.parent.hasNext() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.next = this.parent.next();
|
||||
|
||||
while( this.innerIterater.hasNext() || this.parent.hasNext() )
|
||||
{
|
||||
if( this.innerIterater.hasNext() )
|
||||
if( this.next.isMeaningful() )
|
||||
{
|
||||
this.next = this.innerIterater.next();
|
||||
|
||||
if( this.next.isMeaningful() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.innerIterater.remove(); // self cleaning :3
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if( this.parent.hasNext() )
|
||||
else
|
||||
{
|
||||
this.innerIterater = this.parent.next().values().iterator();
|
||||
this.parent.remove(); // self cleaning :3
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue