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>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.me.storage;
|
|
|
|
|
2015-04-03 08:54:31 +02: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.FuzzyMode;
|
|
|
|
import appeng.api.config.IncludeExclude;
|
|
|
|
import appeng.api.config.Upgrades;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.items.IUpgradeModule;
|
2014-03-28 01:48:38 +01:00
|
|
|
import appeng.api.storage.ICellInventory;
|
|
|
|
import appeng.api.storage.ICellInventoryHandler;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.IMEInventory;
|
2014-07-23 21:11:12 +02: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;
|
|
|
|
import appeng.util.item.AEItemStack;
|
|
|
|
import appeng.util.prioitylist.FuzzyPriorityList;
|
|
|
|
import appeng.util.prioitylist.PrecisePriorityList;
|
2017-04-12 16:10:13 +02:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-03-28 01:48:38 +01:00
|
|
|
public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> implements ICellInventoryHandler
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2015-09-25 21:26:52 +02:00
|
|
|
CellInventoryHandler( final IMEInventory<IAEItemStack> c )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-07-23 21:11:12 +02:00
|
|
|
super( c, StorageChannel.ITEMS );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final ICellInventory ci = this.getCellInv();
|
2015-09-25 21:26:52 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ci != null )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final IInventory upgrades = ci.getUpgradesInventory();
|
|
|
|
final IInventory config = ci.getConfigInventory();
|
|
|
|
final FuzzyMode fzMode = ci.getFuzzyMode();
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
boolean hasInverter = false;
|
|
|
|
boolean hasFuzzy = false;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < upgrades.getSizeInventory(); x++ )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ItemStack is = upgrades.getStackInSlot( x );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is != null && is.getItem() instanceof IUpgradeModule )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final Upgrades u = ( (IUpgradeModule) is.getItem() ).getType( is );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( u != null )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( u )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case FUZZY:
|
|
|
|
hasFuzzy = true;
|
|
|
|
break;
|
|
|
|
case INVERTER:
|
|
|
|
hasInverter = true;
|
|
|
|
break;
|
|
|
|
default:
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < config.getSizeInventory(); x++ )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ItemStack is = config.getStackInSlot( x );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
priorityList.add( AEItemStack.create( is ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2015-03-15 15:03:45 +01:00
|
|
|
this.setWhitelist( hasInverter ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !priorityList.isEmpty() )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hasFuzzy )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-15 15:03:45 +01:00
|
|
|
this.setPartitionList( new FuzzyPriorityList<IAEItemStack>( priorityList, fzMode ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-15 15:03:45 +01:00
|
|
|
this.setPartitionList( new PrecisePriorityList<IAEItemStack>( priorityList ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-08 21:22:15 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public ICellInventory getCellInv()
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
Object o = this.getInternal();
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
if( o instanceof MEPassThrough )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
o = ( (MEPassThrough) o ).getInternal();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
return (ICellInventory) ( o instanceof ICellInventory ? o : null );
|
|
|
|
}
|
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2015-02-03 12:04:13 +01:00
|
|
|
public boolean isPreformatted()
|
2014-09-08 21:22:15 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return !this.getPartitionList().isEmpty();
|
2014-09-08 21:22:15 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2014-09-08 21:22:15 +02:00
|
|
|
public boolean isFuzzy()
|
|
|
|
{
|
2015-03-15 15:03:45 +01:00
|
|
|
return this.getPartitionList() instanceof FuzzyPriorityList;
|
2014-09-08 21:22:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IncludeExclude getIncludeExcludeMode()
|
|
|
|
{
|
2015-03-15 15:03:45 +01:00
|
|
|
return this.getWhitelist();
|
2014-09-08 21:22:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getStatusForCell()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
int val = this.getCellInv().getStatusForCell();
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( val == 1 && this.isPreformatted() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
val = 2;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return val;
|
2014-09-08 21:22:15 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|