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>.
|
|
|
|
*/
|
|
|
|
|
2014-03-04 08:52:07 +01:00
|
|
|
package appeng.items.storage;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2014-03-04 08:52:07 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-09-17 06:24:21 +02:00
|
|
|
import appeng.api.AEApi;
|
2014-03-04 08:52:07 +01:00
|
|
|
import appeng.api.config.FuzzyMode;
|
2014-09-17 06:24:21 +02:00
|
|
|
import appeng.api.config.Upgrades;
|
|
|
|
import appeng.api.implementations.items.IUpgradeModule;
|
2014-03-04 08:52:07 +01:00
|
|
|
import appeng.api.storage.ICellWorkbenchItem;
|
2014-09-17 06:24:21 +02:00
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.storage.data.IItemList;
|
2014-03-04 08:52:07 +01:00
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.items.AEBaseItem;
|
|
|
|
import appeng.items.contents.CellConfig;
|
|
|
|
import appeng.items.contents.CellUpgrades;
|
|
|
|
import appeng.util.Platform;
|
2014-09-17 06:24:21 +02:00
|
|
|
import appeng.util.item.AEItemStack;
|
|
|
|
import appeng.util.prioitylist.FuzzyPriorityList;
|
|
|
|
import appeng.util.prioitylist.IPartitionList;
|
|
|
|
import appeng.util.prioitylist.MergedPriorityList;
|
|
|
|
import appeng.util.prioitylist.PrecisePriorityList;
|
2014-03-04 08:52:07 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2014-03-04 08:52:07 +01:00
|
|
|
public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem
|
|
|
|
{
|
2014-09-17 06:24:21 +02:00
|
|
|
public ItemViewCell()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setFeature( EnumSet.of( AEFeature.Core ) );
|
|
|
|
this.setMaxStackSize( 1 );
|
2014-03-04 08:52:07 +01:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
public static IPartitionList<IAEItemStack> createFilter( ItemStack[] list )
|
2014-09-17 06:24:21 +02:00
|
|
|
{
|
|
|
|
IPartitionList<IAEItemStack> myPartitionList = null;
|
|
|
|
|
|
|
|
MergedPriorityList<IAEItemStack> myMergedList = new MergedPriorityList<IAEItemStack>();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack currentViewCell : list )
|
2014-09-17 06:24:21 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( currentViewCell == null )
|
2014-09-17 06:24:21 +02:00
|
|
|
continue;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( currentViewCell.getItem() instanceof ItemViewCell ) )
|
2014-09-17 06:24:21 +02:00
|
|
|
{
|
|
|
|
IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
ICellWorkbenchItem vc = (ICellWorkbenchItem) currentViewCell.getItem();
|
2014-09-17 06:24:21 +02:00
|
|
|
IInventory upgrades = vc.getUpgradesInventory( currentViewCell );
|
|
|
|
IInventory config = vc.getConfigInventory( currentViewCell );
|
|
|
|
FuzzyMode fzMode = vc.getFuzzyMode( currentViewCell );
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
boolean hasInverter = false;
|
|
|
|
boolean hasFuzzy = false;
|
2014-09-17 06:24:21 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < upgrades.getSizeInventory(); x++ )
|
2014-09-17 06:24:21 +02:00
|
|
|
{
|
|
|
|
ItemStack is = upgrades.getStackInSlot( x );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is != null && is.getItem() instanceof IUpgradeModule )
|
2014-09-17 06:24:21 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
Upgrades u = ( (IUpgradeModule) is.getItem() ).getType( is );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( u != null )
|
2014-09-17 06:24:21 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( u )
|
2014-09-17 06:24:21 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
case FUZZY:
|
|
|
|
hasFuzzy = true;
|
|
|
|
break;
|
|
|
|
case INVERTER:
|
|
|
|
hasInverter = true;
|
|
|
|
break;
|
|
|
|
default:
|
2014-09-17 06:24:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < config.getSizeInventory(); x++ )
|
2014-09-17 06:24:21 +02:00
|
|
|
{
|
|
|
|
ItemStack is = config.getStackInSlot( x );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is != null )
|
2014-09-17 06:24:21 +02:00
|
|
|
priorityList.add( AEItemStack.create( is ) );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !priorityList.isEmpty() )
|
2014-09-17 06:24:21 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hasFuzzy )
|
2014-09-17 06:24:21 +02:00
|
|
|
myMergedList.addNewList( new FuzzyPriorityList<IAEItemStack>( priorityList, fzMode ), !hasInverter );
|
|
|
|
else
|
|
|
|
myMergedList.addNewList( new PrecisePriorityList<IAEItemStack>( priorityList ), !hasInverter );
|
|
|
|
|
|
|
|
myPartitionList = myMergedList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return myPartitionList;
|
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEditable( ItemStack is )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getUpgradesInventory( ItemStack is )
|
|
|
|
{
|
|
|
|
return new CellUpgrades( is, 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getConfigInventory( ItemStack is )
|
|
|
|
{
|
|
|
|
return new CellConfig( is );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FuzzyMode getFuzzyMode( ItemStack is )
|
|
|
|
{
|
|
|
|
String fz = Platform.openNbtData( is ).getString( "FuzzyMode" );
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return FuzzyMode.valueOf( fz );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable t )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
return FuzzyMode.IGNORE_ALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFuzzyMode( ItemStack is, FuzzyMode fzMode )
|
|
|
|
{
|
|
|
|
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
|
|
|
|
}
|
2014-03-04 08:52:07 +01:00
|
|
|
}
|