Applied-Energistics-2-tiler.../me/storage/CreativeCellInventory.java

110 lines
2.3 KiB
Java
Raw Normal View History

package appeng.me.storage;
import net.minecraft.item.ItemStack;
2014-01-20 17:41:37 +01:00
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.exceptions.AppEngException;
2014-01-20 17:41:37 +01:00
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IMEInventoryHandler;
2014-01-20 17:41:37 +01:00
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
2014-01-20 17:41:37 +01:00
import appeng.api.storage.data.IItemList;
import appeng.items.contents.CellConfig;
2014-01-20 17:41:37 +01:00
import appeng.util.item.AEItemStack;
import appeng.util.item.ItemList;
2014-01-20 17:41:37 +01:00
public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
{
2014-01-20 17:41:37 +01:00
ItemList<IAEItemStack> itemListCache = new ItemList();
public static IMEInventoryHandler getCell(ItemStack o)
{
try
{
return new CellInventoryHandler( new CreativeCellInventory( o ) );
}
catch (AppEngException e)
{
}
return null;
}
protected CreativeCellInventory(ItemStack o) throws AppEngException {
2014-01-20 17:41:37 +01:00
CellConfig cc = new CellConfig( o );
for (ItemStack is : cc)
if ( is != null )
{
IAEItemStack i = AEItemStack.create( is );
i.setStackSize( Integer.MAX_VALUE );
itemListCache.add( i );
}
}
@Override
2014-01-20 17:41:37 +01:00
public IAEItemStack injectItems(IAEItemStack input, Actionable mode, BaseActionSource src)
{
2014-01-20 17:41:37 +01:00
IAEItemStack local = itemListCache.findPrecise( input );
if ( local == null )
return input;
return null;
}
@Override
2014-01-20 17:41:37 +01:00
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src)
{
2014-01-20 17:41:37 +01:00
IAEItemStack local = itemListCache.findPrecise( request );
if ( local == null )
return null;
return request.copy();
}
@Override
2014-01-20 17:41:37 +01:00
public IItemList<IAEItemStack> getAvailableItems(IItemList out)
{
2014-01-20 17:41:37 +01:00
for (IAEItemStack ais : itemListCache)
out.add( ais );
return out;
}
@Override
2014-01-20 17:41:37 +01:00
public StorageChannel getChannel()
{
2014-01-20 17:41:37 +01:00
return StorageChannel.ITEMS;
}
@Override
2014-01-20 17:41:37 +01:00
public AccessRestriction getAccess()
{
2014-01-20 17:41:37 +01:00
return AccessRestriction.READ_WRITE;
}
@Override
2014-01-20 17:41:37 +01:00
public boolean isPrioritized(IAEItemStack input)
{
2014-01-20 17:41:37 +01:00
return itemListCache.findPrecise( input ) != null;
}
@Override
2014-01-20 17:41:37 +01:00
public boolean canAccept(IAEItemStack input)
{
2014-01-20 17:41:37 +01:00
return itemListCache.findPrecise( input ) != null;
}
@Override
2014-01-20 17:41:37 +01:00
public int getPriority()
{
2014-01-20 17:41:37 +01:00
return 0;
}
@Override
2014-01-20 17:41:37 +01:00
public int getSlot()
{
2014-01-20 17:41:37 +01:00
return 0;
}
}