Applied-Energistics-2-tiler.../src/main/java/appeng/me/storage/CreativeCellInventory.java

136 lines
3.1 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.me.storage;
import net.minecraft.item.ItemStack;
2014-12-29 21:59:05 +01:00
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;
import appeng.api.config.Actionable;
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;
2014-01-20 17:41:37 +01:00
public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
{
final IItemList<IAEItemStack> itemListCache = AEApi.instance().storage().createItemList();
protected CreativeCellInventory( ItemStack o )
2014-10-04 08:08:28 +02:00
{
2014-01-20 17:41:37 +01:00
CellConfig cc = new CellConfig( o );
for( ItemStack is : cc )
2015-04-29 02:30:53 +02:00
{
if( is != null )
2014-01-20 17:41:37 +01:00
{
IAEItemStack i = AEItemStack.create( is );
i.setStackSize( Integer.MAX_VALUE );
2014-12-29 15:13:47 +01:00
this.itemListCache.add( i );
2014-01-20 17:41:37 +01:00
}
2015-04-29 02:30:53 +02:00
}
}
public static IMEInventoryHandler getCell( ItemStack o )
{
return new CellInventoryHandler( new CreativeCellInventory( o ) );
}
@Override
public IAEItemStack injectItems( IAEItemStack input, Actionable mode, BaseActionSource src )
{
2014-12-29 15:13:47 +01:00
IAEItemStack local = this.itemListCache.findPrecise( input );
if( local == null )
2015-04-29 02:30:53 +02:00
{
2014-01-20 17:41:37 +01:00
return input;
2015-04-29 02:30:53 +02:00
}
2014-01-20 17:41:37 +01:00
return null;
}
@Override
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, BaseActionSource src )
{
2014-12-29 15:13:47 +01:00
IAEItemStack local = this.itemListCache.findPrecise( request );
if( local == null )
2015-04-29 02:30:53 +02:00
{
2014-01-20 17:41:37 +01:00
return null;
2015-04-29 02:30:53 +02:00
}
2014-01-20 17:41:37 +01:00
return request.copy();
}
@Override
public IItemList<IAEItemStack> getAvailableItems( IItemList out )
{
for( IAEItemStack ais : this.itemListCache )
2015-04-29 02:30:53 +02:00
{
2014-01-20 17:41:37 +01:00
out.add( ais );
2015-04-29 02:30:53 +02:00
}
2014-01-20 17:41:37 +01:00
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
public boolean isPrioritized( IAEItemStack input )
{
2014-12-29 15:13:47 +01:00
return this.itemListCache.findPrecise( input ) != null;
}
@Override
public boolean canAccept( IAEItemStack input )
{
2014-12-29 15:13:47 +01:00
return this.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;
}
@Override
public boolean validForPass( int i )
{
return true;
}
}