Merge pull request #1908 from yueh/feature-1906
Closes #1906: Using a constant time collection for cells
This commit is contained in:
commit
64e4dc08d9
|
@ -20,6 +20,7 @@ package appeng.me.storage;
|
||||||
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
@ -28,7 +29,6 @@ import net.minecraft.nbt.NBTBase;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
import appeng.api.AEApi;
|
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.config.FuzzyMode;
|
import appeng.api.config.FuzzyMode;
|
||||||
import appeng.api.exceptions.AppEngException;
|
import appeng.api.exceptions.AppEngException;
|
||||||
|
@ -43,38 +43,29 @@ import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
import appeng.util.item.AEItemStack;
|
import appeng.util.item.AEItemStack;
|
||||||
|
import appeng.util.item.UnsortedItemList;
|
||||||
|
|
||||||
|
|
||||||
public class CellInventory implements ICellInventory
|
public class CellInventory implements ICellInventory
|
||||||
{
|
{
|
||||||
|
|
||||||
static final String ITEM_TYPE_TAG = "it";
|
private static final String ITEM_TYPE_TAG = "it";
|
||||||
static final String ITEM_COUNT_TAG = "ic";
|
private static final String ITEM_COUNT_TAG = "ic";
|
||||||
static final String ITEM_SLOT = "#";
|
private static final String ITEM_SLOT = "#";
|
||||||
static final String ITEM_SLOT_COUNT = "@";
|
private static final String ITEM_SLOT_COUNT = "@";
|
||||||
static final String ITEM_PRE_FORMATTED_COUNT = "PF";
|
private static final Set<Integer> BLACK_LIST = new HashSet<Integer>();
|
||||||
static final String ITEM_PRE_FORMATTED_SLOT = "PF#";
|
private static String[] itemSlots;
|
||||||
static final String ITEM_PRE_FORMATTED_NAME = "PN";
|
private static String[] itemSlotCount;
|
||||||
static final String ITEM_PRE_FORMATTED_FUZZY = "FP";
|
private final NBTTagCompound tagCompound;
|
||||||
private static final HashSet<Integer> BLACK_LIST = new HashSet<Integer>();
|
private final ISaveProvider container;
|
||||||
protected static String[] itemSlots;
|
private int maxItemTypes = 63;
|
||||||
protected static String[] itemSlotCount;
|
private short storedItems = 0;
|
||||||
protected final NBTTagCompound tagCompound;
|
private int storedItemCount = 0;
|
||||||
protected final ISaveProvider container;
|
private IItemList<IAEItemStack> cellItems;
|
||||||
protected int maxItemTypes = 63;
|
private ItemStack cellItem;
|
||||||
protected short storedItems = 0;
|
private IStorageCell cellType;
|
||||||
protected int storedItemCount = 0;
|
|
||||||
protected IItemList<IAEItemStack> cellItems;
|
|
||||||
protected ItemStack i;
|
|
||||||
protected IStorageCell CellType;
|
|
||||||
|
|
||||||
protected CellInventory( final NBTTagCompound data, final ISaveProvider container )
|
private CellInventory( final ItemStack o, final ISaveProvider container ) throws AppEngException
|
||||||
{
|
|
||||||
this.tagCompound = data;
|
|
||||||
this.container = container;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CellInventory( final ItemStack o, final ISaveProvider container ) throws AppEngException
|
|
||||||
{
|
{
|
||||||
if( itemSlots == null )
|
if( itemSlots == null )
|
||||||
{
|
{
|
||||||
|
@ -93,22 +84,23 @@ public class CellInventory implements ICellInventory
|
||||||
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
||||||
}
|
}
|
||||||
|
|
||||||
this.CellType = null;
|
this.cellType = null;
|
||||||
this.i = o;
|
this.cellItem = o;
|
||||||
|
|
||||||
|
final Item type = this.cellItem.getItem();
|
||||||
|
|
||||||
final Item type = this.i.getItem();
|
|
||||||
if( type instanceof IStorageCell )
|
if( type instanceof IStorageCell )
|
||||||
{
|
{
|
||||||
this.CellType = (IStorageCell) this.i.getItem();
|
this.cellType = (IStorageCell) this.cellItem.getItem();
|
||||||
this.maxItemTypes = this.CellType.getTotalTypes( this.i );
|
this.maxItemTypes = this.cellType.getTotalTypes( this.cellItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( this.CellType == null )
|
if( this.cellType == null )
|
||||||
{
|
{
|
||||||
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !this.CellType.isStorageCell( this.i ) )
|
if( !this.cellType.isStorageCell( this.cellItem ) )
|
||||||
{
|
{
|
||||||
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
||||||
}
|
}
|
||||||
|
@ -129,7 +121,7 @@ public class CellInventory implements ICellInventory
|
||||||
this.cellItems = null;
|
this.cellItems = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMEInventoryHandler getCell( final ItemStack o, final ISaveProvider container2 )
|
public static IMEInventoryHandler<IAEItemStack> getCell( final ItemStack o, final ISaveProvider container2 )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -141,16 +133,17 @@ public class CellInventory implements ICellInventory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isStorageCell( final ItemStack i )
|
private static boolean isStorageCell( final ItemStack itemStack )
|
||||||
{
|
{
|
||||||
if( i == null )
|
if( itemStack == null )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final Item type = i.getItem();
|
final Item type = itemStack.getItem();
|
||||||
|
|
||||||
if( type instanceof IStorageCell )
|
if( type instanceof IStorageCell )
|
||||||
{
|
{
|
||||||
return !( (IStorageCell) type ).storableInStorageCell();
|
return !( (IStorageCell) type ).storableInStorageCell();
|
||||||
|
@ -164,17 +157,18 @@ public class CellInventory implements ICellInventory
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isCell( final ItemStack i )
|
public static boolean isCell( final ItemStack itemStack )
|
||||||
{
|
{
|
||||||
if( i == null )
|
if( itemStack == null )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Item type = i.getItem();
|
final Item type = itemStack.getItem();
|
||||||
|
|
||||||
if( type instanceof IStorageCell )
|
if( type instanceof IStorageCell )
|
||||||
{
|
{
|
||||||
return ( (IStorageCell) type ).isStorageCell( i );
|
return ( (IStorageCell) type ).isStorageCell( itemStack );
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -191,12 +185,13 @@ public class CellInventory implements ICellInventory
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BLACK_LIST.contains( ( input.getItemDamage() << Platform.DEF_OFFSET ) | Item.getIdFromItem( input.getItem() ) );
|
return BLACK_LIST.contains( ( input.getItemDamage() << Platform.DEF_OFFSET ) | Item.getIdFromItem( input.getItem() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEmpty( final IMEInventory meInventory )
|
private boolean isEmpty( final IMEInventory<IAEItemStack> meInventory )
|
||||||
{
|
{
|
||||||
return meInventory.getAvailableItems( AEApi.instance().storage().createItemList() ).isEmpty();
|
return meInventory.getAvailableItems( new UnsortedItemList() ).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -206,12 +201,13 @@ public class CellInventory implements ICellInventory
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( input.getStackSize() == 0 )
|
if( input.getStackSize() == 0 )
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( isBlackListed( input ) || this.CellType.isBlackListed( this.i, input ) )
|
if( isBlackListed( input ) || this.cellType.isBlackListed( this.cellItem, input ) )
|
||||||
{
|
{
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +216,8 @@ public class CellInventory implements ICellInventory
|
||||||
|
|
||||||
if( CellInventory.isStorageCell( sharedItemStack ) )
|
if( CellInventory.isStorageCell( sharedItemStack ) )
|
||||||
{
|
{
|
||||||
final IMEInventory meInventory = getCell( sharedItemStack, null );
|
final IMEInventory<IAEItemStack> meInventory = getCell( sharedItemStack, null );
|
||||||
|
|
||||||
if( meInventory != null && !this.isEmpty( meInventory ) )
|
if( meInventory != null && !this.isEmpty( meInventory ) )
|
||||||
{
|
{
|
||||||
return input;
|
return input;
|
||||||
|
@ -228,9 +225,11 @@ public class CellInventory implements ICellInventory
|
||||||
}
|
}
|
||||||
|
|
||||||
final IAEItemStack l = this.getCellItems().findPrecise( input );
|
final IAEItemStack l = this.getCellItems().findPrecise( input );
|
||||||
|
|
||||||
if( l != null )
|
if( l != null )
|
||||||
{
|
{
|
||||||
final long remainingItemSlots = this.getRemainingItemCount();
|
final long remainingItemSlots = this.getRemainingItemCount();
|
||||||
|
|
||||||
if( remainingItemSlots < 0 )
|
if( remainingItemSlots < 0 )
|
||||||
{
|
{
|
||||||
return input;
|
return input;
|
||||||
|
@ -240,12 +239,14 @@ public class CellInventory implements ICellInventory
|
||||||
{
|
{
|
||||||
final IAEItemStack r = input.copy();
|
final IAEItemStack r = input.copy();
|
||||||
r.setStackSize( r.getStackSize() - remainingItemSlots );
|
r.setStackSize( r.getStackSize() - remainingItemSlots );
|
||||||
|
|
||||||
if( mode == Actionable.MODULATE )
|
if( mode == Actionable.MODULATE )
|
||||||
{
|
{
|
||||||
l.setStackSize( l.getStackSize() + remainingItemSlots );
|
l.setStackSize( l.getStackSize() + remainingItemSlots );
|
||||||
this.updateItemCount( remainingItemSlots );
|
this.updateItemCount( remainingItemSlots );
|
||||||
this.saveChanges();
|
this.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -256,6 +257,7 @@ public class CellInventory implements ICellInventory
|
||||||
this.updateItemCount( input.getStackSize() );
|
this.updateItemCount( input.getStackSize() );
|
||||||
this.saveChanges();
|
this.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,12 +265,14 @@ public class CellInventory implements ICellInventory
|
||||||
if( this.canHoldNewItem() ) // room for new type, and for at least one item!
|
if( this.canHoldNewItem() ) // room for new type, and for at least one item!
|
||||||
{
|
{
|
||||||
final int remainingItemCount = (int) this.getRemainingItemCount() - this.getBytesPerType() * 8;
|
final int remainingItemCount = (int) this.getRemainingItemCount() - this.getBytesPerType() * 8;
|
||||||
|
|
||||||
if( remainingItemCount > 0 )
|
if( remainingItemCount > 0 )
|
||||||
{
|
{
|
||||||
if( input.getStackSize() > remainingItemCount )
|
if( input.getStackSize() > remainingItemCount )
|
||||||
{
|
{
|
||||||
final ItemStack toReturn = Platform.cloneItemStack( sharedItemStack );
|
final ItemStack toReturn = Platform.cloneItemStack( sharedItemStack );
|
||||||
toReturn.stackSize = sharedItemStack.stackSize - remainingItemCount;
|
toReturn.stackSize = sharedItemStack.stackSize - remainingItemCount;
|
||||||
|
|
||||||
if( mode == Actionable.MODULATE )
|
if( mode == Actionable.MODULATE )
|
||||||
{
|
{
|
||||||
final ItemStack toWrite = Platform.cloneItemStack( sharedItemStack );
|
final ItemStack toWrite = Platform.cloneItemStack( sharedItemStack );
|
||||||
|
@ -279,6 +283,7 @@ public class CellInventory implements ICellInventory
|
||||||
|
|
||||||
this.saveChanges();
|
this.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
return AEItemStack.create( toReturn );
|
return AEItemStack.create( toReturn );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,16 +311,18 @@ public class CellInventory implements ICellInventory
|
||||||
|
|
||||||
final long size = Math.min( Integer.MAX_VALUE, request.getStackSize() );
|
final long size = Math.min( Integer.MAX_VALUE, request.getStackSize() );
|
||||||
|
|
||||||
IAEItemStack Results = null;
|
IAEItemStack results = null;
|
||||||
|
|
||||||
final IAEItemStack l = this.getCellItems().findPrecise( request );
|
final IAEItemStack l = this.getCellItems().findPrecise( request );
|
||||||
|
|
||||||
if( l != null )
|
if( l != null )
|
||||||
{
|
{
|
||||||
Results = l.copy();
|
results = l.copy();
|
||||||
|
|
||||||
if( l.getStackSize() <= size )
|
if( l.getStackSize() <= size )
|
||||||
{
|
{
|
||||||
Results.setStackSize( l.getStackSize() );
|
results.setStackSize( l.getStackSize() );
|
||||||
|
|
||||||
if( mode == Actionable.MODULATE )
|
if( mode == Actionable.MODULATE )
|
||||||
{
|
{
|
||||||
this.updateItemCount( -l.getStackSize() );
|
this.updateItemCount( -l.getStackSize() );
|
||||||
|
@ -325,7 +332,8 @@ public class CellInventory implements ICellInventory
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Results.setStackSize( size );
|
results.setStackSize( size );
|
||||||
|
|
||||||
if( mode == Actionable.MODULATE )
|
if( mode == Actionable.MODULATE )
|
||||||
{
|
{
|
||||||
l.setStackSize( l.getStackSize() - size );
|
l.setStackSize( l.getStackSize() - size );
|
||||||
|
@ -335,14 +343,13 @@ public class CellInventory implements ICellInventory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
IItemList<IAEItemStack> getCellItems()
|
private IItemList<IAEItemStack> getCellItems()
|
||||||
{
|
{
|
||||||
if( this.cellItems == null )
|
if( this.cellItems == null )
|
||||||
{
|
{
|
||||||
this.cellItems = AEApi.instance().storage().createItemList();
|
|
||||||
this.loadCellItems();
|
this.loadCellItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,18 +362,20 @@ public class CellInventory implements ICellInventory
|
||||||
this.tagCompound.setInteger( ITEM_COUNT_TAG, this.storedItemCount );
|
this.tagCompound.setInteger( ITEM_COUNT_TAG, this.storedItemCount );
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveChanges()
|
private void saveChanges()
|
||||||
{
|
{
|
||||||
// cellItems.clean();
|
// cellItems.clean();
|
||||||
int itemCount = 0;
|
int itemCount = 0;
|
||||||
|
|
||||||
// add new pretty stuff...
|
// add new pretty stuff...
|
||||||
int x = 0;
|
int x = 0;
|
||||||
|
|
||||||
for( final IAEItemStack v : this.cellItems )
|
for( final IAEItemStack v : this.cellItems )
|
||||||
{
|
{
|
||||||
itemCount += v.getStackSize();
|
itemCount += v.getStackSize();
|
||||||
|
|
||||||
final NBTBase c = this.tagCompound.getTag( itemSlots[x] );
|
final NBTBase c = this.tagCompound.getTag( itemSlots[x] );
|
||||||
|
|
||||||
if( c instanceof NBTTagCompound )
|
if( c instanceof NBTTagCompound )
|
||||||
{
|
{
|
||||||
v.writeToNBT( (NBTTagCompound) c );
|
v.writeToNBT( (NBTTagCompound) c );
|
||||||
|
@ -396,6 +405,7 @@ public class CellInventory implements ICellInventory
|
||||||
* else
|
* else
|
||||||
*/
|
*/
|
||||||
this.storedItems = (short) this.cellItems.size();
|
this.storedItems = (short) this.cellItems.size();
|
||||||
|
|
||||||
if( this.cellItems.isEmpty() )
|
if( this.cellItems.isEmpty() )
|
||||||
{
|
{
|
||||||
this.tagCompound.removeTag( ITEM_TYPE_TAG );
|
this.tagCompound.removeTag( ITEM_TYPE_TAG );
|
||||||
|
@ -409,6 +419,7 @@ public class CellInventory implements ICellInventory
|
||||||
* if ( tagCount instanceof NBTTagInt ) ((NBTTagInt) tagCount).data = storedItemCount = itemCount; else
|
* if ( tagCount instanceof NBTTagInt ) ((NBTTagInt) tagCount).data = storedItemCount = itemCount; else
|
||||||
*/
|
*/
|
||||||
this.storedItemCount = itemCount;
|
this.storedItemCount = itemCount;
|
||||||
|
|
||||||
if( itemCount == 0 )
|
if( itemCount == 0 )
|
||||||
{
|
{
|
||||||
this.tagCompound.removeTag( ITEM_COUNT_TAG );
|
this.tagCompound.removeTag( ITEM_COUNT_TAG );
|
||||||
|
@ -431,11 +442,11 @@ public class CellInventory implements ICellInventory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadCellItems()
|
private void loadCellItems()
|
||||||
{
|
{
|
||||||
if( this.cellItems == null )
|
if( this.cellItems == null )
|
||||||
{
|
{
|
||||||
this.cellItems = AEApi.instance().storage().createItemList();
|
this.cellItems = new UnsortedItemList();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cellItems.resetStatus(); // clears totals and stuff.
|
this.cellItems.resetStatus(); // clears totals and stuff.
|
||||||
|
@ -445,6 +456,7 @@ public class CellInventory implements ICellInventory
|
||||||
for( int x = 0; x < types; x++ )
|
for( int x = 0; x < types; x++ )
|
||||||
{
|
{
|
||||||
final ItemStack t = ItemStack.loadItemStackFromNBT( this.tagCompound.getCompoundTag( itemSlots[x] ) );
|
final ItemStack t = ItemStack.loadItemStackFromNBT( this.tagCompound.getCompoundTag( itemSlots[x] ) );
|
||||||
|
|
||||||
if( t != null )
|
if( t != null )
|
||||||
{
|
{
|
||||||
t.stackSize = this.tagCompound.getInteger( itemSlotCount[x] );
|
t.stackSize = this.tagCompound.getInteger( itemSlotCount[x] );
|
||||||
|
@ -460,7 +472,7 @@ public class CellInventory implements ICellInventory
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IItemList getAvailableItems( final IItemList out )
|
public IItemList<IAEItemStack> getAvailableItems( final IItemList<IAEItemStack> out )
|
||||||
{
|
{
|
||||||
for( final IAEItemStack i : this.getCellItems() )
|
for( final IAEItemStack i : this.getCellItems() )
|
||||||
{
|
{
|
||||||
|
@ -479,50 +491,51 @@ public class CellInventory implements ICellInventory
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItemStack()
|
public ItemStack getItemStack()
|
||||||
{
|
{
|
||||||
return this.i;
|
return this.cellItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getIdleDrain()
|
public double getIdleDrain()
|
||||||
{
|
{
|
||||||
return this.CellType.getIdleDrain();
|
return this.cellType.getIdleDrain();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FuzzyMode getFuzzyMode()
|
public FuzzyMode getFuzzyMode()
|
||||||
{
|
{
|
||||||
return this.CellType.getFuzzyMode( this.i );
|
return this.cellType.getFuzzyMode( this.cellItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IInventory getConfigInventory()
|
public IInventory getConfigInventory()
|
||||||
{
|
{
|
||||||
return this.CellType.getConfigInventory( this.i );
|
return this.cellType.getConfigInventory( this.cellItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IInventory getUpgradesInventory()
|
public IInventory getUpgradesInventory()
|
||||||
{
|
{
|
||||||
return this.CellType.getUpgradesInventory( this.i );
|
return this.cellType.getUpgradesInventory( this.cellItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBytesPerType()
|
public int getBytesPerType()
|
||||||
{
|
{
|
||||||
return this.CellType.BytePerType( this.i );
|
return this.cellType.getBytesPerType( this.cellItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canHoldNewItem()
|
public boolean canHoldNewItem()
|
||||||
{
|
{
|
||||||
final long bytesFree = this.getFreeBytes();
|
final long bytesFree = this.getFreeBytes();
|
||||||
|
|
||||||
return ( bytesFree > this.getBytesPerType() || ( bytesFree == this.getBytesPerType() && this.getUnusedItemCount() > 0 ) ) && this.getRemainingItemTypes() > 0;
|
return ( bytesFree > this.getBytesPerType() || ( bytesFree == this.getBytesPerType() && this.getUnusedItemCount() > 0 ) ) && this.getRemainingItemTypes() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTotalBytes()
|
public long getTotalBytes()
|
||||||
{
|
{
|
||||||
return this.CellType.getBytes( this.i );
|
return this.cellType.getBytes( this.cellItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -535,6 +548,7 @@ public class CellInventory implements ICellInventory
|
||||||
public long getUsedBytes()
|
public long getUsedBytes()
|
||||||
{
|
{
|
||||||
final long bytesForItemCount = ( this.getStoredItemCount() + this.getUnusedItemCount() ) / 8;
|
final long bytesForItemCount = ( this.getStoredItemCount() + this.getUnusedItemCount() ) / 8;
|
||||||
|
|
||||||
return this.getStoredItemTypes() * this.getBytesPerType() + bytesForItemCount;
|
return this.getStoredItemTypes() * this.getBytesPerType() + bytesForItemCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -561,6 +575,7 @@ public class CellInventory implements ICellInventory
|
||||||
{
|
{
|
||||||
final long basedOnStorage = this.getFreeBytes() / this.getBytesPerType();
|
final long basedOnStorage = this.getFreeBytes() / this.getBytesPerType();
|
||||||
final long baseOnTotal = this.getTotalItemTypes() - this.getStoredItemTypes();
|
final long baseOnTotal = this.getTotalItemTypes() - this.getStoredItemTypes();
|
||||||
|
|
||||||
return basedOnStorage > baseOnTotal ? baseOnTotal : basedOnStorage;
|
return basedOnStorage > baseOnTotal ? baseOnTotal : basedOnStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,6 +583,7 @@ public class CellInventory implements ICellInventory
|
||||||
public long getRemainingItemCount()
|
public long getRemainingItemCount()
|
||||||
{
|
{
|
||||||
final long remaining = this.getFreeBytes() * 8 + this.getUnusedItemCount();
|
final long remaining = this.getFreeBytes() * 8 + this.getUnusedItemCount();
|
||||||
|
|
||||||
return remaining > 0 ? remaining : 0;
|
return remaining > 0 ? remaining : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ package appeng.me.storage;
|
||||||
|
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
|
|
||||||
import appeng.api.AEApi;
|
import appeng.api.AEApi;
|
||||||
import appeng.api.config.FuzzyMode;
|
import appeng.api.config.FuzzyMode;
|
||||||
|
@ -34,7 +33,6 @@ import appeng.api.storage.IMEInventory;
|
||||||
import appeng.api.storage.StorageChannel;
|
import appeng.api.storage.StorageChannel;
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
import appeng.util.Platform;
|
|
||||||
import appeng.util.item.AEItemStack;
|
import appeng.util.item.AEItemStack;
|
||||||
import appeng.util.prioitylist.FuzzyPriorityList;
|
import appeng.util.prioitylist.FuzzyPriorityList;
|
||||||
import appeng.util.prioitylist.PrecisePriorityList;
|
import appeng.util.prioitylist.PrecisePriorityList;
|
||||||
|
@ -43,11 +41,12 @@ import appeng.util.prioitylist.PrecisePriorityList;
|
||||||
public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> implements ICellInventoryHandler
|
public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> implements ICellInventoryHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
CellInventoryHandler( final IMEInventory c )
|
CellInventoryHandler( final IMEInventory<IAEItemStack> c )
|
||||||
{
|
{
|
||||||
super( c, StorageChannel.ITEMS );
|
super( c, StorageChannel.ITEMS );
|
||||||
|
|
||||||
final ICellInventory ci = this.getCellInv();
|
final ICellInventory ci = this.getCellInv();
|
||||||
|
|
||||||
if( ci != null )
|
if( ci != null )
|
||||||
{
|
{
|
||||||
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
|
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
|
||||||
|
@ -137,11 +136,6 @@ public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> imple
|
||||||
return this.getWhitelist();
|
return this.getWhitelist();
|
||||||
}
|
}
|
||||||
|
|
||||||
NBTTagCompound openNbtData()
|
|
||||||
{
|
|
||||||
return Platform.openNbtData( this.getCellInv().getItemStack() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStatusForCell()
|
public int getStatusForCell()
|
||||||
{
|
{
|
||||||
int val = this.getCellInv().getStatusForCell();
|
int val = this.getCellInv().getStatusForCell();
|
||||||
|
|
179
src/main/java/appeng/util/item/UnsortedItemList.java
Normal file
179
src/main/java/appeng/util/item/UnsortedItemList.java
Normal file
|
@ -0,0 +1,179 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Applied Energistics 2.
|
||||||
|
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package appeng.util.item;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Iterators;
|
||||||
|
|
||||||
|
import appeng.api.config.FuzzyMode;
|
||||||
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
|
import appeng.api.storage.data.IItemList;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An unsorted {@link IItemList} providing constant access time instead of logarithmic time.
|
||||||
|
*
|
||||||
|
* As tradeoff it will no longer support fuzzy operations.
|
||||||
|
* Also no advanced features like storing craftable or requestable items is supported.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public final class UnsortedItemList implements IItemList<IAEItemStack>
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Predicate} to filter all meaningful entries with {@link Iterators}
|
||||||
|
*/
|
||||||
|
private static final Predicate<IAEItemStack> MEANINGFUL_PREDICATE = new Predicate<IAEItemStack>()
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply( @Nonnull IAEItemStack input )
|
||||||
|
{
|
||||||
|
return input.isMeaningful();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final Map<IAEItemStack, IAEItemStack> records = new HashMap<IAEItemStack, IAEItemStack>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add( IAEItemStack option )
|
||||||
|
{
|
||||||
|
if( option == null )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final IAEItemStack st = this.records.get( option );
|
||||||
|
|
||||||
|
if( st != null )
|
||||||
|
{
|
||||||
|
st.add( option );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final IAEItemStack opt = option.copy();
|
||||||
|
|
||||||
|
this.records.put( opt, opt );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IAEItemStack findPrecise( IAEItemStack itemStack )
|
||||||
|
{
|
||||||
|
if( itemStack == null )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.records.get( itemStack );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty()
|
||||||
|
{
|
||||||
|
return this.records.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size()
|
||||||
|
{
|
||||||
|
return this.records.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<IAEItemStack> iterator()
|
||||||
|
{
|
||||||
|
return Iterators.filter( this.records.values().iterator(), MEANINGFUL_PREDICATE );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IAEItemStack getFirstItem()
|
||||||
|
{
|
||||||
|
for( final IAEItemStack stackType : this )
|
||||||
|
{
|
||||||
|
return stackType;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetStatus()
|
||||||
|
{
|
||||||
|
for( final IAEItemStack i : this )
|
||||||
|
{
|
||||||
|
i.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsupported due to being a unsorted collection and thus only solvable in linear or worse time.
|
||||||
|
*
|
||||||
|
* @deprecated to indicate this method is unsupported.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public Collection<IAEItemStack> findFuzzy( IAEItemStack filter, FuzzyMode fuzzy )
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException( "Unsupported on an unsorted collection" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsupported to avoid being used as anything but a plain collection to store real item stacks.
|
||||||
|
*
|
||||||
|
* @deprecated to indicate this method is unsupported.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public void addStorage( IAEItemStack option )
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException( "Purely designed for item storage" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsupported to avoid being used as anything but a plain collection to store real item stacks.
|
||||||
|
*
|
||||||
|
* @deprecated to indicate this method is unsupported.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public void addCrafting( IAEItemStack option )
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException( "Purely designed for item storage" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsupported to avoid being used as anything but a plain collection to store real item stacks.
|
||||||
|
*
|
||||||
|
* @deprecated to indicate this method is unsupported.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public void addRequestable( IAEItemStack option )
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException( "Purely designed for item storage" );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue