Basic reformat, hit once, hope never again
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
@@ -31,45 +32,46 @@ import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.tile.misc.TileCondenser;
|
||||
|
||||
|
||||
public class AEExternalHandler implements IExternalStorageHandler
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean canHandle(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource mySrc)
|
||||
public boolean canHandle( TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource mySrc )
|
||||
{
|
||||
if ( channel == StorageChannel.ITEMS && te instanceof ITileStorageMonitorable )
|
||||
return ((ITileStorageMonitorable) te).getMonitorable( d, mySrc ) != null;
|
||||
if( channel == StorageChannel.ITEMS && te instanceof ITileStorageMonitorable )
|
||||
return ( (ITileStorageMonitorable) te ).getMonitorable( d, mySrc ) != null;
|
||||
|
||||
return te instanceof TileCondenser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource src)
|
||||
public IMEInventory getInventory( TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource src )
|
||||
{
|
||||
if ( te instanceof TileCondenser )
|
||||
if( te instanceof TileCondenser )
|
||||
{
|
||||
if ( channel == StorageChannel.ITEMS )
|
||||
if( channel == StorageChannel.ITEMS )
|
||||
return new VoidItemInventory( (TileCondenser) te );
|
||||
else
|
||||
return new VoidFluidInventory( (TileCondenser) te );
|
||||
}
|
||||
|
||||
if ( te instanceof ITileStorageMonitorable )
|
||||
if( te instanceof ITileStorageMonitorable )
|
||||
{
|
||||
ITileStorageMonitorable iface = (ITileStorageMonitorable) te;
|
||||
IStorageMonitorable sm = iface.getMonitorable( d, src );
|
||||
|
||||
if ( channel == StorageChannel.ITEMS && sm != null )
|
||||
if( channel == StorageChannel.ITEMS && sm != null )
|
||||
{
|
||||
IMEInventory<IAEItemStack> ii = sm.getItemInventory();
|
||||
if ( ii != null )
|
||||
if( ii != null )
|
||||
return ii;
|
||||
}
|
||||
|
||||
if ( channel == StorageChannel.FLUIDS && sm != null )
|
||||
if( channel == StorageChannel.FLUIDS && sm != null )
|
||||
{
|
||||
IMEInventory<IAEFluidStack> fi = sm.getFluidInventory();
|
||||
if ( fi != null )
|
||||
if( fi != null )
|
||||
return fi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -43,6 +44,7 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
|
||||
public class CellInventory implements ICellInventory
|
||||
{
|
||||
|
||||
@@ -54,50 +56,285 @@ public class CellInventory implements ICellInventory
|
||||
static final String ITEM_PRE_FORMATTED_SLOT = "PF#";
|
||||
static final String ITEM_PRE_FORMATTED_NAME = "PN";
|
||||
static final String ITEM_PRE_FORMATTED_FUZZY = "FP";
|
||||
|
||||
private static final HashSet<Integer> BLACK_LIST = new HashSet<Integer>();
|
||||
static protected String[] ITEM_SLOT_ARR;
|
||||
static protected String[] ITEM_SLOT_COUNT_ARR;
|
||||
|
||||
final protected NBTTagCompound tagCompound;
|
||||
final protected ISaveProvider container;
|
||||
protected int MAX_ITEM_TYPES = 63;
|
||||
protected short storedItems = 0;
|
||||
protected int storedItemCount = 0;
|
||||
protected IItemList<IAEItemStack> cellItems;
|
||||
|
||||
protected ItemStack i;
|
||||
protected IStorageCell CellType;
|
||||
|
||||
final protected ISaveProvider container;
|
||||
|
||||
protected CellInventory(NBTTagCompound data, ISaveProvider container) {
|
||||
protected CellInventory( NBTTagCompound data, ISaveProvider container )
|
||||
{
|
||||
this.tagCompound = data;
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
protected void loadCellItems()
|
||||
protected CellInventory( ItemStack o, ISaveProvider container ) throws AppEngException
|
||||
{
|
||||
if ( this.cellItems == null )
|
||||
this.cellItems = AEApi.instance().storage().createItemList();
|
||||
|
||||
this.cellItems.resetStatus(); // clears totals and stuff.
|
||||
|
||||
int types = (int) this.getStoredItemTypes();
|
||||
|
||||
for (int x = 0; x < types; x++)
|
||||
if( ITEM_SLOT_ARR == null )
|
||||
{
|
||||
ItemStack t = ItemStack.loadItemStackFromNBT( this.tagCompound.getCompoundTag( ITEM_SLOT_ARR[x] ) );
|
||||
if ( t != null )
|
||||
{
|
||||
t.stackSize = this.tagCompound.getInteger( ITEM_SLOT_COUNT_ARR[x] );
|
||||
ITEM_SLOT_ARR = new String[this.MAX_ITEM_TYPES];
|
||||
ITEM_SLOT_COUNT_ARR = new String[this.MAX_ITEM_TYPES];
|
||||
|
||||
if ( t.stackSize > 0 )
|
||||
for( int x = 0; x < this.MAX_ITEM_TYPES; x++ )
|
||||
{
|
||||
ITEM_SLOT_ARR[x] = ITEM_SLOT + x;
|
||||
ITEM_SLOT_COUNT_ARR[x] = ITEM_SLOT_COUNT + x;
|
||||
}
|
||||
}
|
||||
|
||||
if( o == null )
|
||||
{
|
||||
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
||||
}
|
||||
|
||||
this.CellType = null;
|
||||
this.i = o;
|
||||
|
||||
Item type = this.i.getItem();
|
||||
if( type instanceof IStorageCell )
|
||||
{
|
||||
this.CellType = (IStorageCell) this.i.getItem();
|
||||
this.MAX_ITEM_TYPES = this.CellType.getTotalTypes( this.i );
|
||||
}
|
||||
|
||||
if( this.CellType == null )
|
||||
{
|
||||
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
||||
}
|
||||
|
||||
if( !this.CellType.isStorageCell( this.i ) )
|
||||
{
|
||||
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
||||
}
|
||||
|
||||
if( this.MAX_ITEM_TYPES > 63 )
|
||||
this.MAX_ITEM_TYPES = 63;
|
||||
if( this.MAX_ITEM_TYPES < 1 )
|
||||
this.MAX_ITEM_TYPES = 1;
|
||||
|
||||
this.container = container;
|
||||
this.tagCompound = Platform.openNbtData( o );
|
||||
this.storedItems = this.tagCompound.getShort( ITEM_TYPE_TAG );
|
||||
this.storedItemCount = this.tagCompound.getInteger( ITEM_COUNT_TAG );
|
||||
this.cellItems = null;
|
||||
}
|
||||
|
||||
public static IMEInventoryHandler getCell( ItemStack o, ISaveProvider container2 )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new CellInventoryHandler( new CellInventory( o, container2 ) );
|
||||
}
|
||||
catch( AppEngException e )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isStorageCell( ItemStack i )
|
||||
{
|
||||
if( i == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Item type = i.getItem();
|
||||
if( type instanceof IStorageCell )
|
||||
{
|
||||
return !( (IStorageCell) type ).storableInStorageCell();
|
||||
}
|
||||
}
|
||||
catch( Throwable err )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isCell( ItemStack i )
|
||||
{
|
||||
if( i == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Item type = i.getItem();
|
||||
if( type instanceof IStorageCell )
|
||||
{
|
||||
return ( (IStorageCell) type ).isStorageCell( i );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void addBasicBlackList( int itemID, int Meta )
|
||||
{
|
||||
BLACK_LIST.add( ( Meta << Platform.DEF_OFFSET ) | itemID );
|
||||
}
|
||||
|
||||
public static boolean isBlackListed( IAEItemStack input )
|
||||
{
|
||||
if( BLACK_LIST.contains( ( OreDictionary.WILDCARD_VALUE << Platform.DEF_OFFSET ) | Item.getIdFromItem( input.getItem() ) ) )
|
||||
return true;
|
||||
return BLACK_LIST.contains( ( input.getItemDamage() << Platform.DEF_OFFSET ) | Item.getIdFromItem( input.getItem() ) );
|
||||
}
|
||||
|
||||
private boolean isEmpty( IMEInventory meInventory )
|
||||
{
|
||||
return meInventory.getAvailableItems( AEApi.instance().storage().createItemList() ).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems( IAEItemStack input, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
if( input == null )
|
||||
return null;
|
||||
if( input.getStackSize() == 0 )
|
||||
return null;
|
||||
|
||||
if( isBlackListed( input ) || this.CellType.isBlackListed( this.i, input ) )
|
||||
return input;
|
||||
|
||||
ItemStack sharedItemStack = input.getItemStack();
|
||||
|
||||
if( CellInventory.isStorageCell( sharedItemStack ) )
|
||||
{
|
||||
IMEInventory meInventory = getCell( sharedItemStack, null );
|
||||
if( meInventory != null && !this.isEmpty( meInventory ) )
|
||||
return input;
|
||||
}
|
||||
|
||||
IAEItemStack l = this.getCellItems().findPrecise( input );
|
||||
if( l != null )
|
||||
{
|
||||
long remainingItemSlots = this.getRemainingItemCount();
|
||||
if( remainingItemSlots < 0 )
|
||||
return input;
|
||||
|
||||
if( input.getStackSize() > remainingItemSlots )
|
||||
{
|
||||
IAEItemStack r = input.copy();
|
||||
r.setStackSize( r.getStackSize() - remainingItemSlots );
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
this.cellItems.add( AEItemStack.create( t ) );
|
||||
l.setStackSize( l.getStackSize() + remainingItemSlots );
|
||||
this.updateItemCount( remainingItemSlots );
|
||||
this.saveChanges();
|
||||
}
|
||||
return r;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
l.setStackSize( l.getStackSize() + input.getStackSize() );
|
||||
this.updateItemCount( input.getStackSize() );
|
||||
this.saveChanges();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.canHoldNewItem() ) // room for new type, and for at least one item!
|
||||
{
|
||||
int remainingItemCount = (int) this.getRemainingItemCount() - this.getBytesPerType() * 8;
|
||||
if( remainingItemCount > 0 )
|
||||
{
|
||||
if( input.getStackSize() > remainingItemCount )
|
||||
{
|
||||
ItemStack toReturn = Platform.cloneItemStack( sharedItemStack );
|
||||
toReturn.stackSize = sharedItemStack.stackSize - remainingItemCount;
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
ItemStack toWrite = Platform.cloneItemStack( sharedItemStack );
|
||||
toWrite.stackSize = remainingItemCount;
|
||||
|
||||
this.cellItems.add( AEItemStack.create( toWrite ) );
|
||||
this.updateItemCount( toWrite.stackSize );
|
||||
|
||||
this.saveChanges();
|
||||
}
|
||||
return AEItemStack.create( toReturn );
|
||||
}
|
||||
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
this.updateItemCount( input.getStackSize() );
|
||||
this.cellItems.add( input );
|
||||
this.saveChanges();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
if( request == null )
|
||||
return null;
|
||||
|
||||
long size = Math.min( Integer.MAX_VALUE, request.getStackSize() );
|
||||
|
||||
IAEItemStack Results = null;
|
||||
|
||||
IAEItemStack l = this.getCellItems().findPrecise( request );
|
||||
if( l != null )
|
||||
{
|
||||
Results = l.copy();
|
||||
|
||||
if( l.getStackSize() <= size )
|
||||
{
|
||||
Results.setStackSize( l.getStackSize() );
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
this.updateItemCount( -l.getStackSize() );
|
||||
l.setStackSize( 0 );
|
||||
this.saveChanges();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Results.setStackSize( size );
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
l.setStackSize( l.getStackSize() - size );
|
||||
this.updateItemCount( -size );
|
||||
this.saveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cellItems.clean();
|
||||
return Results;
|
||||
}
|
||||
|
||||
IItemList<IAEItemStack> getCellItems()
|
||||
{
|
||||
if( this.cellItems == null )
|
||||
{
|
||||
this.cellItems = AEApi.instance().storage().createItemList();
|
||||
this.loadCellItems();
|
||||
}
|
||||
|
||||
return this.cellItems;
|
||||
}
|
||||
|
||||
private void updateItemCount( long delta )
|
||||
{
|
||||
this.storedItemCount += delta;
|
||||
this.tagCompound.setInteger( ITEM_COUNT_TAG, this.storedItemCount );
|
||||
}
|
||||
|
||||
void saveChanges()
|
||||
@@ -107,12 +344,12 @@ public class CellInventory implements ICellInventory
|
||||
|
||||
// add new pretty stuff...
|
||||
int x = 0;
|
||||
for (IAEItemStack v : this.cellItems)
|
||||
for( IAEItemStack v : this.cellItems )
|
||||
{
|
||||
itemCount += v.getStackSize();
|
||||
|
||||
NBTBase c = this.tagCompound.getTag( ITEM_SLOT_ARR[x] );
|
||||
if ( c instanceof NBTTagCompound )
|
||||
if( c instanceof NBTTagCompound )
|
||||
{
|
||||
v.writeToNBT( (NBTTagCompound) c );
|
||||
}
|
||||
@@ -140,20 +377,20 @@ public class CellInventory implements ICellInventory
|
||||
* if ( tagType instanceof NBTTagShort ) ((NBTTagShort) tagType).data = storedItems = (short) cellItems.size();
|
||||
* else
|
||||
*/
|
||||
if ( this.cellItems.isEmpty() )
|
||||
if( this.cellItems.isEmpty() )
|
||||
{
|
||||
this.tagCompound.removeTag( ITEM_TYPE_TAG );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.storedItems = ( short ) this.cellItems.size();
|
||||
this.storedItems = (short) this.cellItems.size();
|
||||
this.tagCompound.setShort( ITEM_TYPE_TAG, this.storedItems );
|
||||
}
|
||||
|
||||
/*
|
||||
* if ( tagCount instanceof NBTTagInt ) ((NBTTagInt) tagCount).data = storedItemCount = itemCount; else
|
||||
*/
|
||||
if ( itemCount == 0 )
|
||||
if( itemCount == 0 )
|
||||
{
|
||||
this.tagCompound.removeTag( ITEM_COUNT_TAG );
|
||||
}
|
||||
@@ -164,362 +401,46 @@ public class CellInventory implements ICellInventory
|
||||
}
|
||||
|
||||
// clean any old crusty stuff...
|
||||
for (; x < oldStoredItems && x < this.MAX_ITEM_TYPES; x++)
|
||||
for(; x < oldStoredItems && x < this.MAX_ITEM_TYPES; x++ )
|
||||
{
|
||||
this.tagCompound.removeTag( ITEM_SLOT_ARR[x] );
|
||||
this.tagCompound.removeTag( ITEM_SLOT_COUNT_ARR[x] );
|
||||
}
|
||||
|
||||
if ( this.container != null )
|
||||
if( this.container != null )
|
||||
this.container.saveChanges( this );
|
||||
}
|
||||
|
||||
protected CellInventory(ItemStack o, ISaveProvider container) throws AppEngException {
|
||||
if ( ITEM_SLOT_ARR == null )
|
||||
{
|
||||
ITEM_SLOT_ARR = new String[this.MAX_ITEM_TYPES];
|
||||
ITEM_SLOT_COUNT_ARR = new String[this.MAX_ITEM_TYPES];
|
||||
|
||||
for (int x = 0; x < this.MAX_ITEM_TYPES; x++)
|
||||
{
|
||||
ITEM_SLOT_ARR[x] = ITEM_SLOT + x;
|
||||
ITEM_SLOT_COUNT_ARR[x] = ITEM_SLOT_COUNT + x;
|
||||
}
|
||||
}
|
||||
|
||||
if ( o == null )
|
||||
{
|
||||
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
||||
}
|
||||
|
||||
this.CellType = null;
|
||||
this.i = o;
|
||||
|
||||
Item type = this.i.getItem();
|
||||
if ( type instanceof IStorageCell )
|
||||
{
|
||||
this.CellType = (IStorageCell) this.i.getItem();
|
||||
this.MAX_ITEM_TYPES = this.CellType.getTotalTypes( this.i );
|
||||
}
|
||||
|
||||
if ( this.CellType == null )
|
||||
{
|
||||
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
||||
}
|
||||
|
||||
if ( !this.CellType.isStorageCell( this.i ) )
|
||||
{
|
||||
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
||||
}
|
||||
|
||||
if ( this.MAX_ITEM_TYPES > 63 )
|
||||
this.MAX_ITEM_TYPES = 63;
|
||||
if ( this.MAX_ITEM_TYPES < 1 )
|
||||
this.MAX_ITEM_TYPES = 1;
|
||||
|
||||
this.container = container;
|
||||
this.tagCompound = Platform.openNbtData( o );
|
||||
this.storedItems = this.tagCompound.getShort( ITEM_TYPE_TAG );
|
||||
this.storedItemCount = this.tagCompound.getInteger( ITEM_COUNT_TAG );
|
||||
this.cellItems = null;
|
||||
}
|
||||
|
||||
IItemList<IAEItemStack> getCellItems()
|
||||
protected void loadCellItems()
|
||||
{
|
||||
if ( this.cellItems == null )
|
||||
{
|
||||
if( this.cellItems == null )
|
||||
this.cellItems = AEApi.instance().storage().createItemList();
|
||||
this.loadCellItems();
|
||||
}
|
||||
|
||||
return this.cellItems;
|
||||
}
|
||||
this.cellItems.resetStatus(); // clears totals and stuff.
|
||||
|
||||
@Override
|
||||
public int getBytesPerType()
|
||||
{
|
||||
return this.CellType.BytePerType( this.i );
|
||||
}
|
||||
int types = (int) this.getStoredItemTypes();
|
||||
|
||||
@Override
|
||||
public boolean canHoldNewItem()
|
||||
{
|
||||
long bytesFree = this.getFreeBytes();
|
||||
return (bytesFree > this.getBytesPerType() || (bytesFree == this.getBytesPerType() && this.getUnusedItemCount() > 0)) && this.getRemainingItemTypes() > 0;
|
||||
}
|
||||
|
||||
public static IMEInventoryHandler getCell(ItemStack o, ISaveProvider container2)
|
||||
{
|
||||
try
|
||||
for( int x = 0; x < types; x++ )
|
||||
{
|
||||
return new CellInventoryHandler( new CellInventory( o, container2 ) );
|
||||
}
|
||||
catch (AppEngException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isStorageCell(ItemStack i)
|
||||
{
|
||||
if ( i == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Item type = i.getItem();
|
||||
if ( type instanceof IStorageCell )
|
||||
ItemStack t = ItemStack.loadItemStackFromNBT( this.tagCompound.getCompoundTag( ITEM_SLOT_ARR[x] ) );
|
||||
if( t != null )
|
||||
{
|
||||
return !((IStorageCell) type).storableInStorageCell();
|
||||
}
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
t.stackSize = this.tagCompound.getInteger( ITEM_SLOT_COUNT_ARR[x] );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isCell(ItemStack i)
|
||||
{
|
||||
if ( i == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Item type = i.getItem();
|
||||
if ( type instanceof IStorageCell )
|
||||
{
|
||||
return ((IStorageCell) type).isStorageCell( i );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTotalBytes()
|
||||
{
|
||||
return this.CellType.getBytes( this.i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFreeBytes()
|
||||
{
|
||||
return this.getTotalBytes() - this.getUsedBytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUsedBytes()
|
||||
{
|
||||
long bytesForItemCount = (this.getStoredItemCount() + this.getUnusedItemCount()) / 8;
|
||||
return this.getStoredItemTypes() * this.getBytesPerType() + bytesForItemCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTotalItemTypes()
|
||||
{
|
||||
return this.MAX_ITEM_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStoredItemTypes()
|
||||
{
|
||||
return this.storedItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStoredItemCount()
|
||||
{
|
||||
return this.storedItemCount;
|
||||
}
|
||||
|
||||
private void updateItemCount(long delta)
|
||||
{
|
||||
this.storedItemCount += delta;
|
||||
this.tagCompound.setInteger( ITEM_COUNT_TAG, this.storedItemCount );
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRemainingItemTypes()
|
||||
{
|
||||
long basedOnStorage = this.getFreeBytes() / this.getBytesPerType();
|
||||
long baseOnTotal = this.getTotalItemTypes() - this.getStoredItemTypes();
|
||||
return basedOnStorage > baseOnTotal ? baseOnTotal : basedOnStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRemainingItemCount()
|
||||
{
|
||||
long remaining = this.getFreeBytes() * 8 + this.getUnusedItemCount();
|
||||
return remaining > 0 ? remaining : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnusedItemCount()
|
||||
{
|
||||
int div = (int) (this.getStoredItemCount() % 8);
|
||||
|
||||
if ( div == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 8 - div;
|
||||
}
|
||||
|
||||
private static final HashSet<Integer> BLACK_LIST = new HashSet<Integer>();
|
||||
|
||||
public static void addBasicBlackList(int itemID, int Meta)
|
||||
{
|
||||
BLACK_LIST.add( ( Meta << Platform.DEF_OFFSET ) | itemID );
|
||||
}
|
||||
|
||||
public static boolean isBlackListed(IAEItemStack input)
|
||||
{
|
||||
if ( BLACK_LIST.contains( (OreDictionary.WILDCARD_VALUE << Platform.DEF_OFFSET) | Item.getIdFromItem( input.getItem() ) ) )
|
||||
return true;
|
||||
return BLACK_LIST.contains( (input.getItemDamage() << Platform.DEF_OFFSET) | Item.getIdFromItem( input.getItem() ) );
|
||||
}
|
||||
|
||||
private boolean isEmpty(IMEInventory meInventory)
|
||||
{
|
||||
return meInventory.getAvailableItems( AEApi.instance().storage().createItemList() ).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack input, Actionable mode, BaseActionSource src)
|
||||
{
|
||||
if ( input == null )
|
||||
return null;
|
||||
if ( input.getStackSize() == 0 )
|
||||
return null;
|
||||
|
||||
if ( isBlackListed( input ) || this.CellType.isBlackListed( this.i, input ) )
|
||||
return input;
|
||||
|
||||
ItemStack sharedItemStack = input.getItemStack();
|
||||
|
||||
if ( CellInventory.isStorageCell( sharedItemStack ) )
|
||||
{
|
||||
IMEInventory meInventory = getCell( sharedItemStack, null );
|
||||
if ( meInventory != null && !this.isEmpty( meInventory ) )
|
||||
return input;
|
||||
}
|
||||
|
||||
IAEItemStack l = this.getCellItems().findPrecise( input );
|
||||
if ( l != null )
|
||||
{
|
||||
long remainingItemSlots = this.getRemainingItemCount();
|
||||
if ( remainingItemSlots < 0 )
|
||||
return input;
|
||||
|
||||
if ( input.getStackSize() > remainingItemSlots )
|
||||
{
|
||||
IAEItemStack r = input.copy();
|
||||
r.setStackSize( r.getStackSize() - remainingItemSlots );
|
||||
if ( mode == Actionable.MODULATE )
|
||||
if( t.stackSize > 0 )
|
||||
{
|
||||
l.setStackSize( l.getStackSize() + remainingItemSlots );
|
||||
this.updateItemCount( remainingItemSlots );
|
||||
this.saveChanges();
|
||||
}
|
||||
return r;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( mode == Actionable.MODULATE )
|
||||
{
|
||||
l.setStackSize( l.getStackSize() + input.getStackSize() );
|
||||
this.updateItemCount( input.getStackSize() );
|
||||
this.saveChanges();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ( this.canHoldNewItem() ) // room for new type, and for at least one item!
|
||||
{
|
||||
int remainingItemCount = (int) this.getRemainingItemCount() - this.getBytesPerType() * 8;
|
||||
if ( remainingItemCount > 0 )
|
||||
{
|
||||
if ( input.getStackSize() > remainingItemCount )
|
||||
{
|
||||
ItemStack toReturn = Platform.cloneItemStack( sharedItemStack );
|
||||
toReturn.stackSize = sharedItemStack.stackSize - remainingItemCount;
|
||||
if ( mode == Actionable.MODULATE )
|
||||
{
|
||||
ItemStack toWrite = Platform.cloneItemStack( sharedItemStack );
|
||||
toWrite.stackSize = remainingItemCount;
|
||||
|
||||
this.cellItems.add( AEItemStack.create( toWrite ) );
|
||||
this.updateItemCount( toWrite.stackSize );
|
||||
|
||||
this.saveChanges();
|
||||
}
|
||||
return AEItemStack.create( toReturn );
|
||||
}
|
||||
|
||||
if ( mode == Actionable.MODULATE )
|
||||
{
|
||||
this.updateItemCount( input.getStackSize() );
|
||||
this.cellItems.add( input );
|
||||
this.saveChanges();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src)
|
||||
{
|
||||
if ( request == null )
|
||||
return null;
|
||||
|
||||
long size = Math.min( Integer.MAX_VALUE, request.getStackSize() );
|
||||
|
||||
IAEItemStack Results = null;
|
||||
|
||||
IAEItemStack l = this.getCellItems().findPrecise( request );
|
||||
if ( l != null )
|
||||
{
|
||||
Results = l.copy();
|
||||
|
||||
if ( l.getStackSize() <= size )
|
||||
{
|
||||
Results.setStackSize( l.getStackSize() );
|
||||
if ( mode == Actionable.MODULATE )
|
||||
{
|
||||
this.updateItemCount( -l.getStackSize() );
|
||||
l.setStackSize( 0 );
|
||||
this.saveChanges();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Results.setStackSize( size );
|
||||
if ( mode == Actionable.MODULATE )
|
||||
{
|
||||
l.setStackSize( l.getStackSize() - size );
|
||||
this.updateItemCount( -size );
|
||||
this.saveChanges();
|
||||
this.cellItems.add( AEItemStack.create( t ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Results;
|
||||
// cellItems.clean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList getAvailableItems(IItemList out)
|
||||
public IItemList getAvailableItems( IItemList out )
|
||||
{
|
||||
for (IAEItemStack i : this.getCellItems())
|
||||
for( IAEItemStack i : this.getCellItems() )
|
||||
out.add( i );
|
||||
|
||||
return out;
|
||||
@@ -531,6 +452,12 @@ public class CellInventory implements ICellInventory
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return this.i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain()
|
||||
{
|
||||
@@ -556,19 +483,90 @@ public class CellInventory implements ICellInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusForCell()
|
||||
public int getBytesPerType()
|
||||
{
|
||||
if ( this.canHoldNewItem() )
|
||||
return 1;
|
||||
if ( this.getRemainingItemCount() > 0 )
|
||||
return 2;
|
||||
return 3;
|
||||
return this.CellType.BytePerType( this.i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack()
|
||||
public boolean canHoldNewItem()
|
||||
{
|
||||
return this.i;
|
||||
long bytesFree = this.getFreeBytes();
|
||||
return ( bytesFree > this.getBytesPerType() || ( bytesFree == this.getBytesPerType() && this.getUnusedItemCount() > 0 ) ) && this.getRemainingItemTypes() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTotalBytes()
|
||||
{
|
||||
return this.CellType.getBytes( this.i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFreeBytes()
|
||||
{
|
||||
return this.getTotalBytes() - this.getUsedBytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUsedBytes()
|
||||
{
|
||||
long bytesForItemCount = ( this.getStoredItemCount() + this.getUnusedItemCount() ) / 8;
|
||||
return this.getStoredItemTypes() * this.getBytesPerType() + bytesForItemCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTotalItemTypes()
|
||||
{
|
||||
return this.MAX_ITEM_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStoredItemCount()
|
||||
{
|
||||
return this.storedItemCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStoredItemTypes()
|
||||
{
|
||||
return this.storedItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRemainingItemTypes()
|
||||
{
|
||||
long basedOnStorage = this.getFreeBytes() / this.getBytesPerType();
|
||||
long baseOnTotal = this.getTotalItemTypes() - this.getStoredItemTypes();
|
||||
return basedOnStorage > baseOnTotal ? baseOnTotal : basedOnStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRemainingItemCount()
|
||||
{
|
||||
long remaining = this.getFreeBytes() * 8 + this.getUnusedItemCount();
|
||||
return remaining > 0 ? remaining : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnusedItemCount()
|
||||
{
|
||||
int div = (int) ( this.getStoredItemCount() % 8 );
|
||||
|
||||
if( div == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 8 - div;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusForCell()
|
||||
{
|
||||
if( this.canHoldNewItem() )
|
||||
return 1;
|
||||
if( this.getRemainingItemCount() > 0 )
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -38,30 +39,16 @@ import appeng.util.item.AEItemStack;
|
||||
import appeng.util.prioitylist.FuzzyPriorityList;
|
||||
import appeng.util.prioitylist.PrecisePriorityList;
|
||||
|
||||
|
||||
public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> implements ICellInventoryHandler
|
||||
{
|
||||
|
||||
NBTTagCompound openNbtData()
|
||||
CellInventoryHandler( IMEInventory c )
|
||||
{
|
||||
return Platform.openNbtData( this.getCellInv().getItemStack() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICellInventory getCellInv()
|
||||
{
|
||||
Object o = this.internal;
|
||||
|
||||
if ( o instanceof MEPassThrough )
|
||||
o = ((MEPassThrough) o).getInternal();
|
||||
|
||||
return (ICellInventory) (o instanceof ICellInventory ? o : null);
|
||||
}
|
||||
|
||||
CellInventoryHandler(IMEInventory c) {
|
||||
super( c, StorageChannel.ITEMS );
|
||||
|
||||
ICellInventory ci = this.getCellInv();
|
||||
if ( ci != null )
|
||||
if( ci != null )
|
||||
{
|
||||
IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
|
||||
|
||||
@@ -72,40 +59,40 @@ public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> imple
|
||||
boolean hasInverter = false;
|
||||
boolean hasFuzzy = false;
|
||||
|
||||
for (int x = 0; x < upgrades.getSizeInventory(); x++)
|
||||
for( int x = 0; x < upgrades.getSizeInventory(); x++ )
|
||||
{
|
||||
ItemStack is = upgrades.getStackInSlot( x );
|
||||
if ( is != null && is.getItem() instanceof IUpgradeModule )
|
||||
if( is != null && is.getItem() instanceof IUpgradeModule )
|
||||
{
|
||||
Upgrades u = ((IUpgradeModule) is.getItem()).getType( is );
|
||||
if ( u != null )
|
||||
Upgrades u = ( (IUpgradeModule) is.getItem() ).getType( is );
|
||||
if( u != null )
|
||||
{
|
||||
switch (u)
|
||||
switch( u )
|
||||
{
|
||||
case FUZZY:
|
||||
hasFuzzy = true;
|
||||
break;
|
||||
case INVERTER:
|
||||
hasInverter = true;
|
||||
break;
|
||||
default:
|
||||
case FUZZY:
|
||||
hasFuzzy = true;
|
||||
break;
|
||||
case INVERTER:
|
||||
hasInverter = true;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < config.getSizeInventory(); x++)
|
||||
for( int x = 0; x < config.getSizeInventory(); x++ )
|
||||
{
|
||||
ItemStack is = config.getStackInSlot( x );
|
||||
if ( is != null )
|
||||
if( is != null )
|
||||
priorityList.add( AEItemStack.create( is ) );
|
||||
}
|
||||
|
||||
this.setWhitelist( hasInverter ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
|
||||
|
||||
if ( !priorityList.isEmpty() )
|
||||
if( !priorityList.isEmpty() )
|
||||
{
|
||||
if ( hasFuzzy )
|
||||
if( hasFuzzy )
|
||||
this.setPartitionList( new FuzzyPriorityList<IAEItemStack>( priorityList, fzMode ) );
|
||||
else
|
||||
this.setPartitionList( new PrecisePriorityList<IAEItemStack>( priorityList ) );
|
||||
@@ -113,10 +100,21 @@ public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> imple
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICellInventory getCellInv()
|
||||
{
|
||||
Object o = this.internal;
|
||||
|
||||
if( o instanceof MEPassThrough )
|
||||
o = ( (MEPassThrough) o ).getInternal();
|
||||
|
||||
return (ICellInventory) ( o instanceof ICellInventory ? o : null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreformatted()
|
||||
{
|
||||
return ! this.getPartitionList().isEmpty();
|
||||
return !this.getPartitionList().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,14 +129,18 @@ public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> imple
|
||||
return this.getWhitelist();
|
||||
}
|
||||
|
||||
public int getStatusForCell()
|
||||
NBTTagCompound openNbtData()
|
||||
{
|
||||
int val = this.getCellInv().getStatusForCell();
|
||||
|
||||
if ( val == 1 && this.isPreformatted() )
|
||||
val = 2;
|
||||
|
||||
return val;
|
||||
return Platform.openNbtData( this.getCellInv().getItemStack() );
|
||||
}
|
||||
|
||||
public int getStatusForCell()
|
||||
{
|
||||
int val = this.getCellInv().getStatusForCell();
|
||||
|
||||
if( val == 1 && this.isPreformatted() )
|
||||
val = 2;
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -31,21 +32,17 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.items.contents.CellConfig;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
|
||||
public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
{
|
||||
|
||||
final IItemList<IAEItemStack> itemListCache = AEApi.instance().storage().createItemList();
|
||||
|
||||
public static IMEInventoryHandler getCell(ItemStack o)
|
||||
{
|
||||
return new CellInventoryHandler( new CreativeCellInventory( o ) );
|
||||
}
|
||||
|
||||
protected CreativeCellInventory(ItemStack o)
|
||||
protected CreativeCellInventory( ItemStack o )
|
||||
{
|
||||
CellConfig cc = new CellConfig( o );
|
||||
for (ItemStack is : cc)
|
||||
if ( is != null )
|
||||
for( ItemStack is : cc )
|
||||
if( is != null )
|
||||
{
|
||||
IAEItemStack i = AEItemStack.create( is );
|
||||
i.setStackSize( Integer.MAX_VALUE );
|
||||
@@ -53,30 +50,35 @@ public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
}
|
||||
}
|
||||
|
||||
public static IMEInventoryHandler getCell( ItemStack o )
|
||||
{
|
||||
return new CellInventoryHandler( new CreativeCellInventory( o ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack input, Actionable mode, BaseActionSource src)
|
||||
public IAEItemStack injectItems( IAEItemStack input, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
IAEItemStack local = this.itemListCache.findPrecise( input );
|
||||
if ( local == null )
|
||||
if( local == null )
|
||||
return input;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src)
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
IAEItemStack local = this.itemListCache.findPrecise( request );
|
||||
if ( local == null )
|
||||
if( local == null )
|
||||
return null;
|
||||
|
||||
return request.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList out)
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList out )
|
||||
{
|
||||
for (IAEItemStack ais : this.itemListCache)
|
||||
for( IAEItemStack ais : this.itemListCache )
|
||||
out.add( ais );
|
||||
return out;
|
||||
}
|
||||
@@ -94,13 +96,13 @@ public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritized(IAEItemStack input)
|
||||
public boolean isPrioritized( IAEItemStack input )
|
||||
{
|
||||
return this.itemListCache.findPrecise( input ) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccept(IAEItemStack input)
|
||||
public boolean canAccept( IAEItemStack input )
|
||||
{
|
||||
return this.itemListCache.findPrecise( input ) != null;
|
||||
}
|
||||
@@ -118,9 +120,8 @@ public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validForPass(int i)
|
||||
public boolean validForPass( int i )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -27,6 +28,7 @@ import appeng.api.storage.ICellHandler;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
|
||||
public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
{
|
||||
|
||||
@@ -35,7 +37,8 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
final ICellHandler handler;
|
||||
final IChestOrDrive cord;
|
||||
|
||||
public DriveWatcher(IMEInventory<T> i, ItemStack is, ICellHandler han, IChestOrDrive cod) {
|
||||
public DriveWatcher( IMEInventory<T> i, ItemStack is, ICellHandler han, IChestOrDrive cod )
|
||||
{
|
||||
super( i, i.getChannel() );
|
||||
this.is = is;
|
||||
this.handler = han;
|
||||
@@ -43,17 +46,17 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public T injectItems(T input, Actionable type, BaseActionSource src)
|
||||
public T injectItems( T input, Actionable type, BaseActionSource src )
|
||||
{
|
||||
long size = input.getStackSize();
|
||||
|
||||
T a = super.injectItems( input, type, src );
|
||||
|
||||
if ( a == null || a.getStackSize() != size )
|
||||
if( a == null || a.getStackSize() != size )
|
||||
{
|
||||
int newStatus = this.handler.getStatusForCell( this.is, this.getInternal() );
|
||||
|
||||
if ( newStatus != this.oldStatus )
|
||||
if( newStatus != this.oldStatus )
|
||||
{
|
||||
this.cord.blinkCell( this.getSlot() );
|
||||
}
|
||||
@@ -63,15 +66,15 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems(T request, Actionable type, BaseActionSource src)
|
||||
public T extractItems( T request, Actionable type, BaseActionSource src )
|
||||
{
|
||||
T a = super.extractItems( request, type, src );
|
||||
|
||||
if ( a != null )
|
||||
if( a != null )
|
||||
{
|
||||
int newStatus = this.handler.getStatusForCell( this.is, this.getInternal() );
|
||||
|
||||
if ( newStatus != this.oldStatus )
|
||||
if( newStatus != this.oldStatus )
|
||||
{
|
||||
this.cord.blinkCell( this.getSlot() );
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -27,12 +28,134 @@ import appeng.api.networking.storage.IStackWatcherHost;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.me.cache.GridStorageCache;
|
||||
|
||||
|
||||
/**
|
||||
* Maintain my interests, and a global watch list, they should always be fully synchronized.
|
||||
*/
|
||||
public class ItemWatcher implements IStackWatcher
|
||||
{
|
||||
|
||||
final GridStorageCache gsc;
|
||||
final IStackWatcherHost myObject;
|
||||
final HashSet<IAEStack> myInterests = new HashSet<IAEStack>();
|
||||
|
||||
public ItemWatcher( GridStorageCache cache, IStackWatcherHost host )
|
||||
{
|
||||
this.gsc = cache;
|
||||
this.myObject = host;
|
||||
}
|
||||
|
||||
public IStackWatcherHost getHost()
|
||||
{
|
||||
return this.myObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.myInterests.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.myInterests.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains( Object o )
|
||||
{
|
||||
return this.myInterests.contains( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEStack> iterator()
|
||||
{
|
||||
return new ItemWatcherIterator( this, this.myInterests.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray()
|
||||
{
|
||||
return this.myInterests.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray( T[] a )
|
||||
{
|
||||
return this.myInterests.toArray( a );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add( IAEStack e )
|
||||
{
|
||||
if( this.myInterests.contains( e ) )
|
||||
return false;
|
||||
|
||||
return this.myInterests.add( e.copy() ) && this.gsc.interestManager.put( e, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove( Object o )
|
||||
{
|
||||
return this.myInterests.remove( o ) && this.gsc.interestManager.remove( (IAEStack) o, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll( Collection<?> c )
|
||||
{
|
||||
return this.myInterests.containsAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll( Collection<? extends IAEStack> c )
|
||||
{
|
||||
boolean didChange = false;
|
||||
|
||||
for( IAEStack o : c )
|
||||
didChange = this.add( o ) || didChange;
|
||||
|
||||
return didChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll( Collection<?> c )
|
||||
{
|
||||
boolean didSomething = false;
|
||||
for( Object o : c )
|
||||
didSomething = this.remove( o ) || didSomething;
|
||||
return didSomething;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll( Collection<?> c )
|
||||
{
|
||||
boolean changed = false;
|
||||
Iterator<IAEStack> i = this.iterator();
|
||||
|
||||
while( i.hasNext() )
|
||||
{
|
||||
if( !c.contains( i.next() ) )
|
||||
{
|
||||
i.remove();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
Iterator<IAEStack> i = this.myInterests.iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
this.gsc.interestManager.remove( i.next(), this );
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
class ItemWatcherIterator implements Iterator<IAEStack>
|
||||
{
|
||||
|
||||
@@ -40,7 +163,8 @@ public class ItemWatcher implements IStackWatcher
|
||||
final Iterator<IAEStack> interestIterator;
|
||||
IAEStack myLast;
|
||||
|
||||
public ItemWatcherIterator(ItemWatcher parent, Iterator<IAEStack> i) {
|
||||
public ItemWatcherIterator( ItemWatcher parent, Iterator<IAEStack> i )
|
||||
{
|
||||
this.watcher = parent;
|
||||
this.interestIterator = i;
|
||||
}
|
||||
@@ -63,127 +187,5 @@ public class ItemWatcher implements IStackWatcher
|
||||
ItemWatcher.this.gsc.interestManager.remove( this.myLast, this.watcher );
|
||||
this.interestIterator.remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final GridStorageCache gsc;
|
||||
final IStackWatcherHost myObject;
|
||||
final HashSet<IAEStack> myInterests = new HashSet<IAEStack>();
|
||||
|
||||
public ItemWatcher(GridStorageCache cache, IStackWatcherHost host) {
|
||||
this.gsc = cache;
|
||||
this.myObject = host;
|
||||
}
|
||||
|
||||
public IStackWatcherHost getHost()
|
||||
{
|
||||
return this.myObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(IAEStack e)
|
||||
{
|
||||
if ( this.myInterests.contains( e ) )
|
||||
return false;
|
||||
|
||||
return this.myInterests.add( e.copy() ) && this.gsc.interestManager.put( e, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends IAEStack> c)
|
||||
{
|
||||
boolean didChange = false;
|
||||
|
||||
for (IAEStack o : c)
|
||||
didChange = this.add( o ) || didChange;
|
||||
|
||||
return didChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
Iterator<IAEStack> i = this.myInterests.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
this.gsc.interestManager.remove( i.next(), this );
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o)
|
||||
{
|
||||
return this.myInterests.contains( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c)
|
||||
{
|
||||
return this.myInterests.containsAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.myInterests.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEStack> iterator()
|
||||
{
|
||||
return new ItemWatcherIterator( this, this.myInterests.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o)
|
||||
{
|
||||
return this.myInterests.remove( o ) && this.gsc.interestManager.remove( (IAEStack)o, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c)
|
||||
{
|
||||
boolean didSomething = false;
|
||||
for (Object o : c)
|
||||
didSomething = this.remove( o ) || didSomething;
|
||||
return didSomething;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c)
|
||||
{
|
||||
boolean changed = false;
|
||||
Iterator<IAEStack> i = this.iterator();
|
||||
|
||||
while (i.hasNext())
|
||||
{
|
||||
if ( !c.contains( i.next() ) )
|
||||
{
|
||||
i.remove();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.myInterests.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray()
|
||||
{
|
||||
return this.myInterests.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a)
|
||||
{
|
||||
return this.myInterests.toArray( a );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -31,64 +32,60 @@ import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
|
||||
public class MEIInventoryWrapper implements IMEInventory<IAEItemStack>
|
||||
{
|
||||
|
||||
protected final IInventory target;
|
||||
protected final InventoryAdaptor adaptor;
|
||||
|
||||
public MEIInventoryWrapper(IInventory m, InventoryAdaptor ia) {
|
||||
public MEIInventoryWrapper( IInventory m, InventoryAdaptor ia )
|
||||
{
|
||||
this.target = m;
|
||||
this.adaptor = ia;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack iox, Actionable mode, BaseActionSource src)
|
||||
public IAEItemStack injectItems( IAEItemStack iox, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
ItemStack input = iox.getItemStack();
|
||||
|
||||
if ( this.adaptor != null )
|
||||
if( this.adaptor != null )
|
||||
{
|
||||
ItemStack is = mode == Actionable.SIMULATE ? this.adaptor.simulateAdd( input ) : this.adaptor.addItems( input );
|
||||
if ( is == null )
|
||||
if( is == null )
|
||||
return null;
|
||||
return AEItemStack.create( is );
|
||||
}
|
||||
|
||||
ItemStack out = Platform.cloneItemStack( input );
|
||||
|
||||
if ( mode == Actionable.MODULATE ) // absolutely no need for a first run in simulate mode.
|
||||
if( mode == Actionable.MODULATE ) // absolutely no need for a first run in simulate mode.
|
||||
{
|
||||
for (int x = 0; x < this.target.getSizeInventory(); x++)
|
||||
for( int x = 0; x < this.target.getSizeInventory(); x++ )
|
||||
{
|
||||
ItemStack t = this.target.getStackInSlot( x );
|
||||
|
||||
if ( Platform.isSameItem( t, input ) )
|
||||
if( Platform.isSameItem( t, input ) )
|
||||
{
|
||||
int oriStack = t.stackSize;
|
||||
t.stackSize += out.stackSize;
|
||||
|
||||
this.target.setInventorySlotContents( x, t );
|
||||
|
||||
if ( t.stackSize > this.target.getInventoryStackLimit() )
|
||||
if( t.stackSize > this.target.getInventoryStackLimit() )
|
||||
{
|
||||
t.stackSize = this.target.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
if ( t.stackSize > t.getMaxStackSize() )
|
||||
if( t.stackSize > t.getMaxStackSize() )
|
||||
{
|
||||
t.stackSize = t.getMaxStackSize();
|
||||
}
|
||||
|
||||
out.stackSize -= t.stackSize - oriStack;
|
||||
|
||||
if ( out.stackSize <= 0 )
|
||||
if( out.stackSize <= 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -96,25 +93,25 @@ public class MEIInventoryWrapper implements IMEInventory<IAEItemStack>
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < this.target.getSizeInventory(); x++)
|
||||
for( int x = 0; x < this.target.getSizeInventory(); x++ )
|
||||
{
|
||||
ItemStack t = this.target.getStackInSlot( x );
|
||||
|
||||
if ( t == null )
|
||||
if( t == null )
|
||||
{
|
||||
t = Platform.cloneItemStack( input );
|
||||
t.stackSize = out.stackSize;
|
||||
|
||||
if ( t.stackSize > this.target.getInventoryStackLimit() )
|
||||
if( t.stackSize > this.target.getInventoryStackLimit() )
|
||||
{
|
||||
t.stackSize = this.target.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
out.stackSize -= t.stackSize;
|
||||
if ( mode == Actionable.MODULATE )
|
||||
if( mode == Actionable.MODULATE )
|
||||
this.target.setInventorySlotContents( x, t );
|
||||
|
||||
if ( out.stackSize <= 0 )
|
||||
if( out.stackSize <= 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -125,21 +122,21 @@ public class MEIInventoryWrapper implements IMEInventory<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src)
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
ItemStack Gathered = null;
|
||||
ItemStack Req = request.getItemStack();
|
||||
|
||||
int request_stackSize = Req.stackSize;
|
||||
|
||||
if ( request_stackSize > Req.getMaxStackSize() )
|
||||
if( request_stackSize > Req.getMaxStackSize() )
|
||||
{
|
||||
request_stackSize = Req.getMaxStackSize();
|
||||
}
|
||||
|
||||
Req.stackSize = request_stackSize;
|
||||
|
||||
if ( this.adaptor != null )
|
||||
if( this.adaptor != null )
|
||||
{
|
||||
Gathered = this.adaptor.removeItems( Req.stackSize, Req, null );
|
||||
}
|
||||
@@ -149,22 +146,22 @@ public class MEIInventoryWrapper implements IMEInventory<IAEItemStack>
|
||||
Gathered.stackSize = 0;
|
||||
|
||||
// try to find matching inventories that already have it...
|
||||
for (int x = 0; x < this.target.getSizeInventory(); x++)
|
||||
for( int x = 0; x < this.target.getSizeInventory(); x++ )
|
||||
{
|
||||
ItemStack sub = this.target.getStackInSlot( x );
|
||||
|
||||
if ( Platform.isSameItem( sub, Req ) )
|
||||
if( Platform.isSameItem( sub, Req ) )
|
||||
{
|
||||
int reqNum = Req.stackSize;
|
||||
|
||||
if ( reqNum > sub.stackSize )
|
||||
if( reqNum > sub.stackSize )
|
||||
{
|
||||
reqNum = Req.stackSize;
|
||||
}
|
||||
|
||||
ItemStack retrieved = null;
|
||||
|
||||
if ( sub.stackSize < Req.stackSize )
|
||||
if( sub.stackSize < Req.stackSize )
|
||||
{
|
||||
retrieved = Platform.cloneItemStack( sub );
|
||||
sub.stackSize = 0;
|
||||
@@ -174,38 +171,37 @@ public class MEIInventoryWrapper implements IMEInventory<IAEItemStack>
|
||||
retrieved = sub.splitStack( Req.stackSize );
|
||||
}
|
||||
|
||||
if ( sub.stackSize <= 0 )
|
||||
if( sub.stackSize <= 0 )
|
||||
this.target.setInventorySlotContents( x, null );
|
||||
else
|
||||
this.target.setInventorySlotContents( x, sub );
|
||||
|
||||
if ( retrieved != null )
|
||||
if( retrieved != null )
|
||||
{
|
||||
Gathered.stackSize += retrieved.stackSize;
|
||||
Req.stackSize -= retrieved.stackSize;
|
||||
}
|
||||
|
||||
if ( request_stackSize == Gathered.stackSize )
|
||||
if( request_stackSize == Gathered.stackSize )
|
||||
{
|
||||
return AEItemStack.create( Gathered );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( Gathered.stackSize == 0 )
|
||||
if( Gathered.stackSize == 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return AEItemStack.create( Gathered );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out)
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||
{
|
||||
for (int x = 0; x < this.target.getSizeInventory(); x++)
|
||||
for( int x = 0; x < this.target.getSizeInventory(); x++ )
|
||||
{
|
||||
out.addStorage( AEItemStack.create( this.target.getStackInSlot( x ) ) );
|
||||
}
|
||||
@@ -213,4 +209,9 @@ public class MEIInventoryWrapper implements IMEInventory<IAEItemStack>
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,9 @@ import appeng.util.prioitylist.IPartitionList;
|
||||
public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHandler<T>
|
||||
{
|
||||
|
||||
final StorageChannel channel;
|
||||
final protected IMEMonitor<T> monitor;
|
||||
final protected IMEInventoryHandler<T> internal;
|
||||
|
||||
final StorageChannel channel;
|
||||
private int myPriority;
|
||||
private IncludeExclude myWhitelist;
|
||||
private AccessRestriction myAccess;
|
||||
@@ -53,12 +52,12 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
||||
{
|
||||
this.channel = channel;
|
||||
|
||||
if ( i instanceof IMEInventoryHandler )
|
||||
this.internal = ( IMEInventoryHandler<T> ) i;
|
||||
if( i instanceof IMEInventoryHandler )
|
||||
this.internal = (IMEInventoryHandler<T>) i;
|
||||
else
|
||||
this.internal = new MEPassThrough<T>( i, channel );
|
||||
|
||||
this.monitor = this.internal instanceof IMEMonitor ? ( IMEMonitor<T> ) this.internal : null;
|
||||
this.monitor = this.internal instanceof IMEMonitor ? (IMEMonitor<T>) this.internal : null;
|
||||
|
||||
this.myPriority = 0;
|
||||
this.myWhitelist = IncludeExclude.WHITELIST;
|
||||
@@ -66,17 +65,6 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
||||
this.myPartitionList = new DefaultPriorityList<T>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return this.myPriority;
|
||||
}
|
||||
|
||||
public void setPriority( int myPriority )
|
||||
{
|
||||
this.myPriority = myPriority;
|
||||
}
|
||||
|
||||
public IncludeExclude getWhitelist()
|
||||
{
|
||||
return this.myWhitelist;
|
||||
@@ -113,7 +101,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
||||
@Override
|
||||
public T injectItems( T input, Actionable type, BaseActionSource src )
|
||||
{
|
||||
if ( !this.canAccept( input ) )
|
||||
if( !this.canAccept( input ) )
|
||||
return input;
|
||||
|
||||
return this.internal.injectItems( input, type, src );
|
||||
@@ -122,7 +110,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
||||
@Override
|
||||
public T extractItems( T request, Actionable type, BaseActionSource src )
|
||||
{
|
||||
if ( !this.hasReadAccess )
|
||||
if( !this.hasReadAccess )
|
||||
return null;
|
||||
|
||||
return this.internal.extractItems( request, type, src );
|
||||
@@ -131,7 +119,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
||||
@Override
|
||||
public IItemList<T> getAvailableItems( IItemList<T> out )
|
||||
{
|
||||
if ( !this.hasReadAccess )
|
||||
if( !this.hasReadAccess )
|
||||
return out;
|
||||
|
||||
return this.internal.getAvailableItems( out );
|
||||
@@ -152,7 +140,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
||||
@Override
|
||||
public boolean isPrioritized( T input )
|
||||
{
|
||||
if ( this.myWhitelist == IncludeExclude.WHITELIST )
|
||||
if( this.myWhitelist == IncludeExclude.WHITELIST )
|
||||
return this.myPartitionList.isListed( input ) || this.internal.isPrioritized( input );
|
||||
return false;
|
||||
}
|
||||
@@ -160,31 +148,41 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
||||
@Override
|
||||
public boolean canAccept( T input )
|
||||
{
|
||||
if ( !this.hasWriteAccess )
|
||||
if( !this.hasWriteAccess )
|
||||
return false;
|
||||
|
||||
if ( this.myWhitelist == IncludeExclude.BLACKLIST && this.myPartitionList.isListed( input ) )
|
||||
if( this.myWhitelist == IncludeExclude.BLACKLIST && this.myPartitionList.isListed( input ) )
|
||||
return false;
|
||||
if ( this.myPartitionList.isEmpty() || this.myWhitelist == IncludeExclude.BLACKLIST )
|
||||
if( this.myPartitionList.isEmpty() || this.myWhitelist == IncludeExclude.BLACKLIST )
|
||||
return this.internal.canAccept( input );
|
||||
return this.myPartitionList.isListed( input ) && this.internal.canAccept( input );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return this.myPriority;
|
||||
}
|
||||
|
||||
public void setPriority( int myPriority )
|
||||
{
|
||||
this.myPriority = myPriority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlot()
|
||||
{
|
||||
return this.internal.getSlot();
|
||||
}
|
||||
|
||||
public IMEInventory<T> getInternal()
|
||||
{
|
||||
return this.internal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validForPass( int i )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public IMEInventory<T> getInternal()
|
||||
{
|
||||
return this.internal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
@@ -42,70 +43,48 @@ import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.ItemSlot;
|
||||
|
||||
|
||||
public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>
|
||||
{
|
||||
|
||||
static class CachedItemStack
|
||||
{
|
||||
|
||||
public CachedItemStack(ItemStack is)
|
||||
{
|
||||
if ( is == null )
|
||||
{
|
||||
this.itemStack = null;
|
||||
this.aeStack = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.itemStack = is.copy();
|
||||
this.aeStack = AEApi.instance().storage().createItemStack( is );
|
||||
}
|
||||
}
|
||||
|
||||
final ItemStack itemStack;
|
||||
final IAEItemStack aeStack;
|
||||
}
|
||||
|
||||
final InventoryAdaptor adaptor;
|
||||
|
||||
private final NavigableMap<Integer, CachedItemStack> memory;
|
||||
final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
|
||||
final HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object>();
|
||||
|
||||
private final NavigableMap<Integer, CachedItemStack> memory;
|
||||
public BaseActionSource mySource;
|
||||
public StorageFilter mode = StorageFilter.EXTRACTABLE_ONLY;
|
||||
|
||||
@Override
|
||||
public void addListener(IMEMonitorHandlerReceiver<IAEItemStack> l, Object verificationToken)
|
||||
{
|
||||
this.listeners.put( l, verificationToken );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(IMEMonitorHandlerReceiver<IAEItemStack> l)
|
||||
{
|
||||
this.listeners.remove( l );
|
||||
}
|
||||
|
||||
public MEMonitorIInventory(InventoryAdaptor adaptor)
|
||||
public MEMonitorIInventory( InventoryAdaptor adaptor )
|
||||
{
|
||||
this.adaptor = adaptor;
|
||||
this.memory = new ConcurrentSkipListMap<Integer, CachedItemStack>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src)
|
||||
public void addListener( IMEMonitorHandlerReceiver<IAEItemStack> l, Object verificationToken )
|
||||
{
|
||||
this.listeners.put( l, verificationToken );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener( IMEMonitorHandlerReceiver<IAEItemStack> l )
|
||||
{
|
||||
this.listeners.remove( l );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems( IAEItemStack input, Actionable type, BaseActionSource src )
|
||||
{
|
||||
ItemStack out = null;
|
||||
|
||||
if ( type == Actionable.SIMULATE )
|
||||
if( type == Actionable.SIMULATE )
|
||||
out = this.adaptor.simulateAdd( input.getItemStack() );
|
||||
else
|
||||
out = this.adaptor.addItems( input.getItemStack() );
|
||||
|
||||
this.onTick();
|
||||
|
||||
if ( out == null )
|
||||
if( out == null )
|
||||
return null;
|
||||
|
||||
// better then doing construction from scratch :3
|
||||
@@ -114,6 +93,146 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable type, BaseActionSource src )
|
||||
{
|
||||
ItemStack out = null;
|
||||
|
||||
if( type == Actionable.SIMULATE )
|
||||
out = this.adaptor.simulateRemove( (int) request.getStackSize(), request.getItemStack(), null );
|
||||
else
|
||||
out = this.adaptor.removeItems( (int) request.getStackSize(), request.getItemStack(), null );
|
||||
|
||||
if( out == null )
|
||||
return null;
|
||||
|
||||
// better then doing construction from scratch :3
|
||||
IAEItemStack o = request.copy();
|
||||
o.setStackSize( out.stackSize );
|
||||
|
||||
this.onTick();
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
public TickRateModulation onTick()
|
||||
{
|
||||
boolean changed = false;
|
||||
|
||||
LinkedList<IAEItemStack> changes = new LinkedList<IAEItemStack>();
|
||||
|
||||
int high = 0;
|
||||
this.list.resetStatus();
|
||||
for( ItemSlot is : this.adaptor )
|
||||
{
|
||||
CachedItemStack old = this.memory.get( is.slot );
|
||||
high = Math.max( high, is.slot );
|
||||
|
||||
ItemStack newIS = !is.isExtractable && this.mode == StorageFilter.EXTRACTABLE_ONLY ? null : is.getItemStack();
|
||||
ItemStack oldIS = old == null ? null : old.itemStack;
|
||||
|
||||
if( this.isDifferent( newIS, oldIS ) )
|
||||
{
|
||||
CachedItemStack cis = new CachedItemStack( is.getItemStack() );
|
||||
this.memory.put( is.slot, cis );
|
||||
|
||||
if( old != null && old.aeStack != null )
|
||||
{
|
||||
old.aeStack.setStackSize( -old.aeStack.getStackSize() );
|
||||
changes.add( old.aeStack );
|
||||
}
|
||||
|
||||
if( cis.aeStack != null )
|
||||
{
|
||||
changes.add( cis.aeStack );
|
||||
this.list.add( cis.aeStack );
|
||||
}
|
||||
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int newSize = ( newIS == null ? 0 : newIS.stackSize );
|
||||
int diff = newSize - ( oldIS == null ? 0 : oldIS.stackSize );
|
||||
|
||||
IAEItemStack stack = ( old == null || old.aeStack == null ? AEApi.instance().storage().createItemStack( newIS ) : old.aeStack.copy() );
|
||||
if( stack != null )
|
||||
{
|
||||
stack.setStackSize( newSize );
|
||||
this.list.add( stack );
|
||||
}
|
||||
|
||||
if( diff != 0 && stack != null )
|
||||
{
|
||||
CachedItemStack cis = new CachedItemStack( is.getItemStack() );
|
||||
this.memory.put( is.slot, cis );
|
||||
|
||||
IAEItemStack a = stack.copy();
|
||||
a.setStackSize( diff );
|
||||
changes.add( a );
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// detect dropped items; should fix non IISided Inventory Changes.
|
||||
NavigableMap<Integer, CachedItemStack> end = this.memory.tailMap( high, false );
|
||||
if( !end.isEmpty() )
|
||||
{
|
||||
for( CachedItemStack cis : end.values() )
|
||||
{
|
||||
if( cis != null && cis.aeStack != null )
|
||||
{
|
||||
IAEItemStack a = cis.aeStack.copy();
|
||||
a.setStackSize( -a.getStackSize() );
|
||||
changes.add( a );
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
end.clear();
|
||||
}
|
||||
|
||||
if( !changes.isEmpty() )
|
||||
this.postDifference( changes );
|
||||
|
||||
return changed ? TickRateModulation.URGENT : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
private boolean isDifferent( ItemStack a, ItemStack b )
|
||||
{
|
||||
if( a == b && b == null )
|
||||
return false;
|
||||
|
||||
if( ( a == null && b != null ) || ( a != null && b == null ) )
|
||||
return true;
|
||||
|
||||
return !Platform.isSameItemPrecise( a, b );
|
||||
}
|
||||
|
||||
private void postDifference( Iterable<IAEItemStack> a )
|
||||
{
|
||||
// AELog.info( a.getItemStack().getUnlocalizedName() + " @ " + a.getStackSize() );
|
||||
if( a != null )
|
||||
{
|
||||
Iterator<Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
|
||||
IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
||||
if( key.isValid( l.getValue() ) )
|
||||
key.postChange( this, a, this.mySource );
|
||||
else
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessRestriction getAccess()
|
||||
{
|
||||
@@ -121,13 +240,13 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritized(IAEItemStack input)
|
||||
public boolean isPrioritized( IAEItemStack input )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccept(IAEItemStack input)
|
||||
public boolean canAccept( IAEItemStack input )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -145,164 +264,44 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getStorageList()
|
||||
public boolean validForPass( int i )
|
||||
{
|
||||
return this.list;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList out)
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList out )
|
||||
{
|
||||
for (CachedItemStack is : this.memory.values())
|
||||
for( CachedItemStack is : this.memory.values() )
|
||||
out.addStorage( is.aeStack );
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable type, BaseActionSource src)
|
||||
public IItemList<IAEItemStack> getStorageList()
|
||||
{
|
||||
ItemStack out = null;
|
||||
|
||||
if ( type == Actionable.SIMULATE )
|
||||
out = this.adaptor.simulateRemove( (int) request.getStackSize(), request.getItemStack(), null );
|
||||
else
|
||||
out = this.adaptor.removeItems( (int) request.getStackSize(), request.getItemStack(), null );
|
||||
|
||||
if ( out == null )
|
||||
return null;
|
||||
|
||||
// better then doing construction from scratch :3
|
||||
IAEItemStack o = request.copy();
|
||||
o.setStackSize( out.stackSize );
|
||||
|
||||
this.onTick();
|
||||
|
||||
return o;
|
||||
return this.list;
|
||||
}
|
||||
|
||||
public TickRateModulation onTick()
|
||||
static class CachedItemStack
|
||||
{
|
||||
boolean changed = false;
|
||||
|
||||
LinkedList<IAEItemStack> changes = new LinkedList<IAEItemStack>();
|
||||
final ItemStack itemStack;
|
||||
final IAEItemStack aeStack;
|
||||
|
||||
int high = 0;
|
||||
this.list.resetStatus();
|
||||
for (ItemSlot is : this.adaptor)
|
||||
public CachedItemStack( ItemStack is )
|
||||
{
|
||||
CachedItemStack old = this.memory.get( is.slot );
|
||||
high = Math.max( high, is.slot );
|
||||
|
||||
ItemStack newIS = !is.isExtractable && this.mode == StorageFilter.EXTRACTABLE_ONLY ? null : is.getItemStack();
|
||||
ItemStack oldIS = old == null ? null : old.itemStack;
|
||||
|
||||
if ( this.isDifferent( newIS, oldIS ) )
|
||||
if( is == null )
|
||||
{
|
||||
CachedItemStack cis = new CachedItemStack( is.getItemStack() );
|
||||
this.memory.put( is.slot, cis );
|
||||
|
||||
if ( old != null && old.aeStack != null )
|
||||
{
|
||||
old.aeStack.setStackSize( -old.aeStack.getStackSize() );
|
||||
changes.add( old.aeStack );
|
||||
}
|
||||
|
||||
if ( cis.aeStack != null )
|
||||
{
|
||||
changes.add( cis.aeStack );
|
||||
this.list.add( cis.aeStack );
|
||||
}
|
||||
|
||||
changed = true;
|
||||
this.itemStack = null;
|
||||
this.aeStack = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
int newSize = (newIS == null ? 0 : newIS.stackSize);
|
||||
int diff = newSize - (oldIS == null ? 0 : oldIS.stackSize);
|
||||
|
||||
IAEItemStack stack = (old == null || old.aeStack == null ? AEApi.instance().storage().createItemStack( newIS ) : old.aeStack.copy());
|
||||
if ( stack != null )
|
||||
{
|
||||
stack.setStackSize( newSize );
|
||||
this.list.add( stack );
|
||||
}
|
||||
|
||||
if ( diff != 0 && stack != null )
|
||||
{
|
||||
CachedItemStack cis = new CachedItemStack( is.getItemStack() );
|
||||
this.memory.put( is.slot, cis );
|
||||
|
||||
IAEItemStack a = stack.copy();
|
||||
a.setStackSize( diff );
|
||||
changes.add( a );
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// detect dropped items; should fix non IISided Inventory Changes.
|
||||
NavigableMap<Integer, CachedItemStack> end = this.memory.tailMap( high, false );
|
||||
if ( !end.isEmpty() )
|
||||
{
|
||||
for (CachedItemStack cis : end.values())
|
||||
{
|
||||
if ( cis != null && cis.aeStack != null )
|
||||
{
|
||||
IAEItemStack a = cis.aeStack.copy();
|
||||
a.setStackSize( -a.getStackSize() );
|
||||
changes.add( a );
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
end.clear();
|
||||
}
|
||||
|
||||
if ( !changes.isEmpty() )
|
||||
this.postDifference( changes );
|
||||
|
||||
return changed ? TickRateModulation.URGENT : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
private boolean isDifferent(ItemStack a, ItemStack b)
|
||||
{
|
||||
if ( a == b && b == null )
|
||||
return false;
|
||||
|
||||
if ( (a == null && b != null) || (a != null && b == null) )
|
||||
return true;
|
||||
|
||||
return !Platform.isSameItemPrecise( a, b );
|
||||
}
|
||||
|
||||
private void postDifference(Iterable<IAEItemStack> a)
|
||||
{
|
||||
// AELog.info( a.getItemStack().getUnlocalizedName() + " @ " + a.getStackSize() );
|
||||
if ( a != null )
|
||||
{
|
||||
Iterator<Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
|
||||
IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
||||
if ( key.isValid( l.getValue() ) )
|
||||
key.postChange( this, a, this.mySource );
|
||||
else
|
||||
i.remove();
|
||||
this.itemStack = is.copy();
|
||||
this.aeStack = AEApi.instance().storage().createItemStack( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validForPass(int i)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
@@ -33,58 +34,57 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.ItemListIgnoreCrafting;
|
||||
|
||||
|
||||
public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T> implements IMEMonitor<T>, IMEMonitorHandlerReceiver<T>
|
||||
{
|
||||
|
||||
final HashMap<IMEMonitorHandlerReceiver<T>, Object> listeners = new HashMap<IMEMonitorHandlerReceiver<T>, Object>();
|
||||
public BaseActionSource changeSource;
|
||||
IMEMonitor<T> monitor;
|
||||
|
||||
public BaseActionSource changeSource;
|
||||
|
||||
public MEMonitorPassThrough(IMEInventory<T> i, StorageChannel channel) {
|
||||
public MEMonitorPassThrough( IMEInventory<T> i, StorageChannel channel )
|
||||
{
|
||||
super( i, channel );
|
||||
if ( i instanceof IMEMonitor )
|
||||
if( i instanceof IMEMonitor )
|
||||
this.monitor = (IMEMonitor<T>) i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInternal(IMEInventory<T> i)
|
||||
public void setInternal( IMEInventory<T> i )
|
||||
{
|
||||
if ( this.monitor != null )
|
||||
if( this.monitor != null )
|
||||
this.monitor.removeListener( this );
|
||||
|
||||
this.monitor = null;
|
||||
IItemList<T> before = this.getInternal() == null ? this.channel.createList() : this.getInternal()
|
||||
.getAvailableItems( new ItemListIgnoreCrafting( this.channel.createList() ) );
|
||||
IItemList<T> before = this.getInternal() == null ? this.channel.createList() : this.getInternal().getAvailableItems( new ItemListIgnoreCrafting( this.channel.createList() ) );
|
||||
|
||||
super.setInternal( i );
|
||||
if ( i instanceof IMEMonitor )
|
||||
if( i instanceof IMEMonitor )
|
||||
this.monitor = (IMEMonitor<T>) i;
|
||||
|
||||
IItemList<T> after = this.getInternal() == null ? this.channel.createList() : this.getInternal()
|
||||
.getAvailableItems( new ItemListIgnoreCrafting( this.channel.createList() ) );
|
||||
IItemList<T> after = this.getInternal() == null ? this.channel.createList() : this.getInternal().getAvailableItems( new ItemListIgnoreCrafting( this.channel.createList() ) );
|
||||
|
||||
if ( this.monitor != null )
|
||||
if( this.monitor != null )
|
||||
this.monitor.addListener( this, this.monitor );
|
||||
|
||||
Platform.postListChanges( before, after, this, this.changeSource );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<T> getAvailableItems(IItemList out)
|
||||
public IItemList<T> getAvailableItems( IItemList out )
|
||||
{
|
||||
super.getAvailableItems( new ItemListIgnoreCrafting( out ) );
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(IMEMonitorHandlerReceiver<T> l, Object verificationToken)
|
||||
public void addListener( IMEMonitorHandlerReceiver<T> l, Object verificationToken )
|
||||
{
|
||||
this.listeners.put( l, verificationToken );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(IMEMonitorHandlerReceiver<T> l)
|
||||
public void removeListener( IMEMonitorHandlerReceiver<T> l )
|
||||
{
|
||||
this.listeners.remove( l );
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T
|
||||
@Override
|
||||
public IItemList<T> getStorageList()
|
||||
{
|
||||
if ( this.monitor == null )
|
||||
if( this.monitor == null )
|
||||
{
|
||||
IItemList<T> out = this.channel.createList();
|
||||
this.getInternal().getAvailableItems( new ItemListIgnoreCrafting( out ) );
|
||||
@@ -102,20 +102,20 @@ public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Object verificationToken)
|
||||
public boolean isValid( Object verificationToken )
|
||||
{
|
||||
return verificationToken == this.monitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChange(IBaseMonitor<T> monitor, Iterable<T> change, BaseActionSource source)
|
||||
public void postChange( IBaseMonitor<T> monitor, Iterable<T> change, BaseActionSource source )
|
||||
{
|
||||
Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while (i.hasNext())
|
||||
while( i.hasNext() )
|
||||
{
|
||||
Entry<IMEMonitorHandlerReceiver<T>, Object> e = i.next();
|
||||
IMEMonitorHandlerReceiver<T> receiver = e.getKey();
|
||||
if ( receiver.isValid( e.getValue() ) )
|
||||
if( receiver.isValid( e.getValue() ) )
|
||||
receiver.postChange( this, change, source );
|
||||
else
|
||||
i.remove();
|
||||
@@ -126,11 +126,11 @@ public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T
|
||||
public void onListUpdate()
|
||||
{
|
||||
Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while (i.hasNext())
|
||||
while( i.hasNext() )
|
||||
{
|
||||
Entry<IMEMonitorHandlerReceiver<T>, Object> e = i.next();
|
||||
IMEMonitorHandlerReceiver<T> receiver = e.getKey();
|
||||
if ( receiver.isValid( e.getValue() ) )
|
||||
if( receiver.isValid( e.getValue() ) )
|
||||
receiver.onListUpdate();
|
||||
else
|
||||
i.remove();
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
@@ -27,41 +28,43 @@ import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
|
||||
public class MEPassThrough<T extends IAEStack<T>> implements IMEInventoryHandler<T>
|
||||
{
|
||||
|
||||
private IMEInventory<T> internal;
|
||||
final protected StorageChannel channel;
|
||||
private IMEInventory<T> internal;
|
||||
|
||||
public MEPassThrough( IMEInventory<T> i, StorageChannel channel )
|
||||
{
|
||||
this.channel = channel;
|
||||
this.setInternal( i );
|
||||
}
|
||||
|
||||
protected IMEInventory<T> getInternal()
|
||||
{
|
||||
return this.internal;
|
||||
}
|
||||
|
||||
public MEPassThrough(IMEInventory<T> i, StorageChannel channel) {
|
||||
this.channel = channel;
|
||||
this.setInternal( i );
|
||||
}
|
||||
|
||||
public void setInternal(IMEInventory<T> i)
|
||||
public void setInternal( IMEInventory<T> i )
|
||||
{
|
||||
this.internal = i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T injectItems(T input, Actionable type, BaseActionSource src)
|
||||
public T injectItems( T input, Actionable type, BaseActionSource src )
|
||||
{
|
||||
return this.internal.injectItems( input, type, src );
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems(T request, Actionable type, BaseActionSource src)
|
||||
public T extractItems( T request, Actionable type, BaseActionSource src )
|
||||
{
|
||||
return this.internal.extractItems( request, type, src );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<T> getAvailableItems(IItemList out)
|
||||
public IItemList<T> getAvailableItems( IItemList out )
|
||||
{
|
||||
return this.internal.getAvailableItems( out );
|
||||
}
|
||||
@@ -79,13 +82,13 @@ public class MEPassThrough<T extends IAEStack<T>> implements IMEInventoryHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritized(T input)
|
||||
public boolean isPrioritized( T input )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccept(T input)
|
||||
public boolean canAccept( T input )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -103,9 +106,8 @@ public class MEPassThrough<T extends IAEStack<T>> implements IMEInventoryHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validForPass(int i)
|
||||
public boolean validForPass( int i )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
@@ -42,157 +43,75 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.me.cache.SecurityCache;
|
||||
import appeng.util.ItemSorters;
|
||||
|
||||
|
||||
public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHandler<T>
|
||||
{
|
||||
|
||||
private final static Comparator<Integer> PRIORITY_SORTER = new Comparator<Integer>() {
|
||||
static final ThreadLocal<LinkedList> DEPTH_MOD = new ThreadLocal<LinkedList>();
|
||||
static final ThreadLocal<LinkedList> DEPTH_SIM = new ThreadLocal<LinkedList>();
|
||||
private final static Comparator<Integer> PRIORITY_SORTER = new Comparator<Integer>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2)
|
||||
public int compare( Integer o1, Integer o2 )
|
||||
{
|
||||
return ItemSorters.compareInt( o2, o1 );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static int currentPass = 0;
|
||||
final StorageChannel myChannel;
|
||||
final SecurityCache security;
|
||||
|
||||
// final TreeMultimap<Integer, IMEInventoryHandler<T>> priorityInventory;
|
||||
private final NavigableMap<Integer, List<IMEInventoryHandler<T>>> priorityInventory;
|
||||
int myPass = 0;
|
||||
|
||||
public NetworkInventoryHandler(StorageChannel chan, SecurityCache security) {
|
||||
public NetworkInventoryHandler( StorageChannel chan, SecurityCache security )
|
||||
{
|
||||
this.myChannel = chan;
|
||||
this.security = security;
|
||||
this.priorityInventory = new TreeMap<Integer, List<IMEInventoryHandler<T>>>( PRIORITY_SORTER ); // TreeMultimap.create( prioritySorter, hashSorter );
|
||||
}
|
||||
|
||||
public void addNewStorage(IMEInventoryHandler<T> h)
|
||||
public void addNewStorage( IMEInventoryHandler<T> h )
|
||||
{
|
||||
int priority = h.getPriority();
|
||||
List<IMEInventoryHandler<T>> list = this.priorityInventory.get( priority );
|
||||
if ( list == null )
|
||||
if( list == null )
|
||||
this.priorityInventory.put( priority, list = new ArrayList<IMEInventoryHandler<T>>() );
|
||||
|
||||
list.add( h );
|
||||
}
|
||||
|
||||
static int currentPass = 0;
|
||||
int myPass = 0;
|
||||
static final ThreadLocal<LinkedList> DEPTH_MOD = new ThreadLocal<LinkedList>();
|
||||
static final ThreadLocal<LinkedList> DEPTH_SIM = new ThreadLocal<LinkedList>();
|
||||
|
||||
private LinkedList getDepth(Actionable type)
|
||||
{
|
||||
ThreadLocal<LinkedList> depth = type == Actionable.MODULATE ? DEPTH_MOD : DEPTH_SIM;
|
||||
|
||||
LinkedList s = depth.get();
|
||||
|
||||
if ( s == null )
|
||||
depth.set( s = new LinkedList() );
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private boolean diveList(NetworkInventoryHandler<T> networkInventoryHandler, Actionable type)
|
||||
{
|
||||
LinkedList cDepth = this.getDepth( type );
|
||||
if ( cDepth.contains( networkInventoryHandler ) )
|
||||
return true;
|
||||
|
||||
cDepth.push( this );
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean diveIteration(NetworkInventoryHandler<T> networkInventoryHandler, Actionable type)
|
||||
{
|
||||
LinkedList cDepth = this.getDepth( type );
|
||||
if ( cDepth.isEmpty() )
|
||||
{
|
||||
currentPass++;
|
||||
this.myPass = currentPass;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( currentPass == this.myPass )
|
||||
return true;
|
||||
else
|
||||
this.myPass = currentPass;
|
||||
}
|
||||
|
||||
cDepth.push( this );
|
||||
return false;
|
||||
}
|
||||
|
||||
private void surface(NetworkInventoryHandler<T> networkInventoryHandler, Actionable type)
|
||||
{
|
||||
if ( this.getDepth( type ).pop() != this )
|
||||
throw new RuntimeException( "Invalid Access to Networked Storage API detected." );
|
||||
}
|
||||
|
||||
private boolean testPermission(BaseActionSource src, SecurityPermissions permission)
|
||||
{
|
||||
if ( src.isPlayer() )
|
||||
{
|
||||
if ( !this.security.hasPermission( ((PlayerSource) src).player, permission ) )
|
||||
return true;
|
||||
}
|
||||
else if ( src.isMachine() )
|
||||
{
|
||||
if ( this.security.isAvailable() )
|
||||
{
|
||||
IGridNode n = ((MachineSource) src).via.getActionableNode();
|
||||
if ( n == null )
|
||||
return true;
|
||||
|
||||
IGrid gn = n.getGrid();
|
||||
if ( gn != this.security.myGrid )
|
||||
{
|
||||
int playerID = -1;
|
||||
|
||||
ISecurityGrid sg = gn.getCache( ISecurityGrid.class );
|
||||
playerID = sg.getOwner();
|
||||
|
||||
if ( !this.security.hasPermission( playerID, permission ) )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T injectItems(T input, Actionable type, BaseActionSource src)
|
||||
public T injectItems( T input, Actionable type, BaseActionSource src )
|
||||
{
|
||||
if ( this.diveList( this, type ) )
|
||||
if( this.diveList( this, type ) )
|
||||
return input;
|
||||
|
||||
if ( this.testPermission( src, SecurityPermissions.INJECT ) )
|
||||
if( this.testPermission( src, SecurityPermissions.INJECT ) )
|
||||
{
|
||||
this.surface( this, type );
|
||||
return input;
|
||||
}
|
||||
|
||||
for (List<IMEInventoryHandler<T>> invList : this.priorityInventory.values())
|
||||
for( List<IMEInventoryHandler<T>> invList : this.priorityInventory.values() )
|
||||
{
|
||||
Iterator<IMEInventoryHandler<T>> ii = invList.iterator();
|
||||
while (ii.hasNext() && input != null)
|
||||
while( ii.hasNext() && input != null )
|
||||
{
|
||||
IMEInventoryHandler<T> inv = ii.next();
|
||||
|
||||
if ( inv.validForPass( 1 ) && inv.canAccept( input )
|
||||
&& (inv.isPrioritized( input ) || inv.extractItems( input, Actionable.SIMULATE, src ) != null) )
|
||||
if( inv.validForPass( 1 ) && inv.canAccept( input ) && ( inv.isPrioritized( input ) || inv.extractItems( input, Actionable.SIMULATE, src ) != null ) )
|
||||
{
|
||||
input = inv.injectItems( input, type, src );
|
||||
}
|
||||
}
|
||||
|
||||
ii = invList.iterator();
|
||||
while (ii.hasNext() && input != null)
|
||||
while( ii.hasNext() && input != null )
|
||||
{
|
||||
IMEInventoryHandler<T> inv = ii.next();
|
||||
if ( inv.validForPass( 2 ) && inv.canAccept( input ) )// ignore crafting on the second pass.
|
||||
if( inv.validForPass( 2 ) && inv.canAccept( input ) )// ignore crafting on the second pass.
|
||||
{
|
||||
input = inv.injectItems( input, type, src );
|
||||
}
|
||||
@@ -204,13 +123,73 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems(T request, Actionable mode, BaseActionSource src)
|
||||
private boolean diveList( NetworkInventoryHandler<T> networkInventoryHandler, Actionable type )
|
||||
{
|
||||
if ( this.diveList( this, mode ) )
|
||||
LinkedList cDepth = this.getDepth( type );
|
||||
if( cDepth.contains( networkInventoryHandler ) )
|
||||
return true;
|
||||
|
||||
cDepth.push( this );
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean testPermission( BaseActionSource src, SecurityPermissions permission )
|
||||
{
|
||||
if( src.isPlayer() )
|
||||
{
|
||||
if( !this.security.hasPermission( ( (PlayerSource) src ).player, permission ) )
|
||||
return true;
|
||||
}
|
||||
else if( src.isMachine() )
|
||||
{
|
||||
if( this.security.isAvailable() )
|
||||
{
|
||||
IGridNode n = ( (MachineSource) src ).via.getActionableNode();
|
||||
if( n == null )
|
||||
return true;
|
||||
|
||||
IGrid gn = n.getGrid();
|
||||
if( gn != this.security.myGrid )
|
||||
{
|
||||
int playerID = -1;
|
||||
|
||||
ISecurityGrid sg = gn.getCache( ISecurityGrid.class );
|
||||
playerID = sg.getOwner();
|
||||
|
||||
if( !this.security.hasPermission( playerID, permission ) )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void surface( NetworkInventoryHandler<T> networkInventoryHandler, Actionable type )
|
||||
{
|
||||
if( this.getDepth( type ).pop() != this )
|
||||
throw new RuntimeException( "Invalid Access to Networked Storage API detected." );
|
||||
}
|
||||
|
||||
private LinkedList getDepth( Actionable type )
|
||||
{
|
||||
ThreadLocal<LinkedList> depth = type == Actionable.MODULATE ? DEPTH_MOD : DEPTH_SIM;
|
||||
|
||||
LinkedList s = depth.get();
|
||||
|
||||
if( s == null )
|
||||
depth.set( s = new LinkedList() );
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems( T request, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
if( this.diveList( this, mode ) )
|
||||
return null;
|
||||
|
||||
if ( this.testPermission( src, SecurityPermissions.EXTRACT ) )
|
||||
if( this.testPermission( src, SecurityPermissions.EXTRACT ) )
|
||||
{
|
||||
this.surface( this, mode );
|
||||
return null;
|
||||
@@ -223,12 +202,12 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
|
||||
output.setStackSize( 0 );
|
||||
long req = request.getStackSize();
|
||||
|
||||
while (i.hasNext())
|
||||
while( i.hasNext() )
|
||||
{
|
||||
List<IMEInventoryHandler<T>> invList = i.next();
|
||||
|
||||
Iterator<IMEInventoryHandler<T>> ii = invList.iterator();
|
||||
while (ii.hasNext() && output.getStackSize() < req)
|
||||
while( ii.hasNext() && output.getStackSize() < req )
|
||||
{
|
||||
IMEInventoryHandler<T> inv = ii.next();
|
||||
|
||||
@@ -239,21 +218,21 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
|
||||
|
||||
this.surface( this, mode );
|
||||
|
||||
if ( output.getStackSize() <= 0 )
|
||||
if( output.getStackSize() <= 0 )
|
||||
return null;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<T> getAvailableItems(IItemList out)
|
||||
public IItemList<T> getAvailableItems( IItemList out )
|
||||
{
|
||||
if ( this.diveIteration( this, Actionable.SIMULATE ) )
|
||||
if( this.diveIteration( this, Actionable.SIMULATE ) )
|
||||
return out;
|
||||
|
||||
// for (Entry<Integer, IMEInventoryHandler<T>> h : priorityInventory.entries())
|
||||
for (List<IMEInventoryHandler<T>> i : this.priorityInventory.values())
|
||||
for (IMEInventoryHandler<T> j : i)
|
||||
for( List<IMEInventoryHandler<T>> i : this.priorityInventory.values() )
|
||||
for( IMEInventoryHandler<T> j : i )
|
||||
out = j.getAvailableItems( out );
|
||||
|
||||
this.surface( this, Actionable.SIMULATE );
|
||||
@@ -261,6 +240,26 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
|
||||
return out;
|
||||
}
|
||||
|
||||
private boolean diveIteration( NetworkInventoryHandler<T> networkInventoryHandler, Actionable type )
|
||||
{
|
||||
LinkedList cDepth = this.getDepth( type );
|
||||
if( cDepth.isEmpty() )
|
||||
{
|
||||
currentPass++;
|
||||
this.myPass = currentPass;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( currentPass == this.myPass )
|
||||
return true;
|
||||
else
|
||||
this.myPass = currentPass;
|
||||
}
|
||||
|
||||
cDepth.push( this );
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
@@ -274,13 +273,13 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritized(T input)
|
||||
public boolean isPrioritized( T input )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccept(T input)
|
||||
public boolean canAccept( T input )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -298,9 +297,8 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validForPass(int i)
|
||||
public boolean validForPass( int i )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
@@ -26,33 +27,34 @@ import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
|
||||
public class NullInventory<T extends IAEStack<T>> implements IMEInventoryHandler<T>
|
||||
{
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T injectItems(T input, Actionable mode, BaseActionSource src)
|
||||
public T injectItems( T input, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems(T request, Actionable mode, BaseActionSource src)
|
||||
public T extractItems( T request, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<T> getAvailableItems(IItemList out)
|
||||
public IItemList<T> getAvailableItems( IItemList out )
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessRestriction getAccess()
|
||||
{
|
||||
@@ -60,13 +62,13 @@ public class NullInventory<T extends IAEStack<T>> implements IMEInventoryHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritized(T input)
|
||||
public boolean isPrioritized( T input )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccept(T input)
|
||||
public boolean canAccept( T input )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -84,9 +86,8 @@ public class NullInventory<T extends IAEStack<T>> implements IMEInventoryHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validForPass(int i)
|
||||
public boolean validForPass( int i )
|
||||
{
|
||||
return i == 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -34,42 +35,28 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.misc.TileSecurity;
|
||||
|
||||
|
||||
public class SecurityInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
{
|
||||
|
||||
final TileSecurity securityTile;
|
||||
final public IItemList<IAEItemStack> storedItems = AEApi.instance().storage().createItemList();
|
||||
final TileSecurity securityTile;
|
||||
|
||||
public SecurityInventory(TileSecurity ts) {
|
||||
public SecurityInventory( TileSecurity ts )
|
||||
{
|
||||
this.securityTile = ts;
|
||||
}
|
||||
|
||||
private boolean hasPermission(BaseActionSource src)
|
||||
{
|
||||
if ( src.isPlayer() )
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.securityTile.getProxy().getSecurity().hasPermission( ((PlayerSource) src).player, SecurityPermissions.SECURITY );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src)
|
||||
public IAEItemStack injectItems( IAEItemStack input, Actionable type, BaseActionSource src )
|
||||
{
|
||||
if ( this.hasPermission( src ) )
|
||||
if( this.hasPermission( src ) )
|
||||
{
|
||||
if ( AEApi.instance().definitions().items().biometricCard().isSameAs( input.getItemStack() ) )
|
||||
if( AEApi.instance().definitions().items().biometricCard().isSameAs( input.getItemStack() ) )
|
||||
{
|
||||
if ( this.canAccept( input ) )
|
||||
if( this.canAccept( input ) )
|
||||
{
|
||||
if ( type == Actionable.SIMULATE )
|
||||
if( type == Actionable.SIMULATE )
|
||||
return null;
|
||||
|
||||
this.storedItems.add( input );
|
||||
@@ -81,17 +68,33 @@ public class SecurityInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src)
|
||||
private boolean hasPermission( BaseActionSource src )
|
||||
{
|
||||
if ( this.hasPermission( src ) )
|
||||
if( src.isPlayer() )
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.securityTile.getProxy().getSecurity().hasPermission( ( (PlayerSource) src ).player, SecurityPermissions.SECURITY );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
if( this.hasPermission( src ) )
|
||||
{
|
||||
IAEItemStack target = this.storedItems.findPrecise( request );
|
||||
if ( target != null )
|
||||
if( target != null )
|
||||
{
|
||||
IAEItemStack output = target.copy();
|
||||
|
||||
if ( mode == Actionable.SIMULATE )
|
||||
if( mode == Actionable.SIMULATE )
|
||||
return output;
|
||||
|
||||
target.setStackSize( 0 );
|
||||
@@ -103,9 +106,9 @@ public class SecurityInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList out)
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList out )
|
||||
{
|
||||
for (IAEItemStack ais : this.storedItems)
|
||||
for( IAEItemStack ais : this.storedItems )
|
||||
out.add( ais );
|
||||
|
||||
return out;
|
||||
@@ -124,32 +127,32 @@ public class SecurityInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritized(IAEItemStack input)
|
||||
public boolean isPrioritized( IAEItemStack input )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccept(IAEItemStack input)
|
||||
public boolean canAccept( IAEItemStack input )
|
||||
{
|
||||
if ( input.getItem() instanceof IBiometricCard )
|
||||
if( input.getItem() instanceof IBiometricCard )
|
||||
{
|
||||
IBiometricCard tbc = (IBiometricCard) input.getItem();
|
||||
GameProfile newUser = tbc.getProfile( input.getItemStack() );
|
||||
|
||||
int PlayerID = AEApi.instance().registries().players().getID( newUser );
|
||||
if ( this.securityTile.getOwner() == PlayerID )
|
||||
if( this.securityTile.getOwner() == PlayerID )
|
||||
return false;
|
||||
|
||||
for (IAEItemStack ais : this.storedItems)
|
||||
for( IAEItemStack ais : this.storedItems )
|
||||
{
|
||||
if ( ais.isMeaningful() )
|
||||
if( ais.isMeaningful() )
|
||||
{
|
||||
GameProfile thisUser = tbc.getProfile( ais.getItemStack() );
|
||||
if ( thisUser == newUser )
|
||||
if( thisUser == newUser )
|
||||
return false;
|
||||
|
||||
if ( thisUser != null && thisUser.equals( newUser ) )
|
||||
if( thisUser != null && thisUser.equals( newUser ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -172,9 +175,8 @@ public class SecurityInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validForPass(int i)
|
||||
public boolean validForPass( int i )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,20 +42,14 @@ public class VoidFluidInventory implements IMEInventoryHandler<IAEFluidStack>
|
||||
@Override
|
||||
public IAEFluidStack injectItems( IAEFluidStack input, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
if ( mode == Actionable.SIMULATE )
|
||||
if( mode == Actionable.SIMULATE )
|
||||
return null;
|
||||
|
||||
if ( input != null )
|
||||
if( input != null )
|
||||
this.target.addPower( input.getStackSize() / 1000.0 );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.FLUIDS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack extractItems( IAEFluidStack request, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
@@ -68,6 +62,12 @@ public class VoidFluidInventory implements IMEInventoryHandler<IAEFluidStack>
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.FLUIDS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessRestriction getAccess()
|
||||
{
|
||||
@@ -103,5 +103,4 @@ public class VoidFluidInventory implements IMEInventoryHandler<IAEFluidStack>
|
||||
{
|
||||
return i == 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,20 +42,14 @@ public class VoidItemInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
@Override
|
||||
public IAEItemStack injectItems( IAEItemStack input, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
if ( mode == Actionable.SIMULATE )
|
||||
if( mode == Actionable.SIMULATE )
|
||||
return null;
|
||||
|
||||
if ( input != null )
|
||||
if( input != null )
|
||||
this.target.addPower( input.getStackSize() );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, BaseActionSource src )
|
||||
{
|
||||
@@ -68,6 +62,12 @@ public class VoidItemInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessRestriction getAccess()
|
||||
{
|
||||
@@ -103,5 +103,4 @@ public class VoidItemInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
{
|
||||
return i == 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user