2013-12-27 23:59:59 +01:00
|
|
|
package appeng.me.storage;
|
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-02-21 21:36:40 +01:00
|
|
|
import appeng.api.AEApi;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.config.AccessRestriction;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.config.Actionable;
|
|
|
|
import appeng.api.exceptions.AppEngException;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.IMEInventoryHandler;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.storage.StorageChannel;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.storage.data.IItemList;
|
2014-01-26 07:48:09 +01:00
|
|
|
import appeng.items.contents.CellConfig;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.util.item.AEItemStack;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-02-21 21:36:40 +01:00
|
|
|
IItemList<IAEItemStack> itemListCache = AEApi.instance().storage().createItemList();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public IAEItemStack injectItems(IAEItemStack input, Actionable mode, BaseActionSource src)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
IAEItemStack local = itemListCache.findPrecise( input );
|
|
|
|
if ( local == null )
|
|
|
|
return input;
|
|
|
|
|
|
|
|
return null;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
IAEItemStack local = itemListCache.findPrecise( request );
|
|
|
|
if ( local == null )
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return request.copy();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public IItemList<IAEItemStack> getAvailableItems(IItemList out)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
for (IAEItemStack ais : itemListCache)
|
|
|
|
out.add( ais );
|
|
|
|
return out;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public StorageChannel getChannel()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
return StorageChannel.ITEMS;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public AccessRestriction getAccess()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
return AccessRestriction.READ_WRITE;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public boolean isPrioritized(IAEItemStack input)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
return itemListCache.findPrecise( input ) != null;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public boolean canAccept(IAEItemStack input)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
return itemListCache.findPrecise( input ) != null;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public int getPriority()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
return 0;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public int getSlot()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
return 0;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|