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

145 lines
3.8 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;
2014-01-20 17:41:37 +01:00
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
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.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;
import appeng.api.storage.IMEInventory;
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.util.Platform;
2014-01-20 17:41:37 +01:00
import appeng.util.item.AEItemStack;
import appeng.util.prioitylist.FuzzyPriorityList;
import appeng.util.prioitylist.PrecisePriorityList;
2014-03-28 01:48:38 +01:00
public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> implements ICellInventoryHandler
{
NBTTagCompound openNbtData()
{
2014-12-29 15:13:47 +01:00
return Platform.openNbtData( this.getCellInv().getItemStack() );
}
2014-03-28 01:48:38 +01:00
@Override
public ICellInventory getCellInv()
{
2014-01-20 17:41:37 +01:00
Object o = this.internal;
if ( o instanceof MEPassThrough )
o = ((MEPassThrough) o).getInternal();
2014-01-20 17:41:37 +01:00
2014-03-28 01:48:38 +01:00
return (ICellInventory) (o instanceof ICellInventory ? o : null);
}
CellInventoryHandler(IMEInventory c) {
super( c, StorageChannel.ITEMS );
2014-12-29 15:13:47 +01:00
ICellInventory ci = this.getCellInv();
2014-01-20 17:41:37 +01:00
if ( ci != null )
{
2014-02-21 21:36:40 +01:00
IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
2014-01-20 17:41:37 +01:00
IInventory upgrades = ci.getUpgradesInventory();
IInventory config = ci.getConfigInventory();
FuzzyMode fzMode = ci.getFuzzyMode();
boolean hasInverter = false;
boolean hasFuzzy = false;
for (int x = 0; x < upgrades.getSizeInventory(); x++)
{
ItemStack is = upgrades.getStackInSlot( x );
if ( is != null && is.getItem() instanceof IUpgradeModule )
{
Upgrades u = ((IUpgradeModule) is.getItem()).getType( is );
if ( u != null )
{
switch (u)
{
case FUZZY:
hasFuzzy = true;
break;
case INVERTER:
hasInverter = true;
break;
default:
}
}
}
}
for (int x = 0; x < config.getSizeInventory(); x++)
{
ItemStack is = config.getStackInSlot( x );
if ( is != null )
priorityList.add( AEItemStack.create( is ) );
}
2014-12-29 15:13:47 +01:00
this.myWhitelist = hasInverter ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST;
2014-01-20 17:41:37 +01:00
if ( !priorityList.isEmpty() )
{
if ( hasFuzzy )
2014-12-29 15:13:47 +01:00
this.myPartitionList = new FuzzyPriorityList<IAEItemStack>( priorityList, fzMode );
2014-01-20 17:41:37 +01:00
else
2014-12-29 15:13:47 +01:00
this.myPartitionList = new PrecisePriorityList<IAEItemStack>( priorityList );
2014-01-20 17:41:37 +01:00
}
}
}
2014-09-08 21:22:15 +02:00
@Override
2015-02-03 12:04:13 +01:00
public boolean isPreformatted()
2014-09-08 21:22:15 +02:00
{
2014-12-29 15:13:47 +01:00
return ! this.myPartitionList.isEmpty();
2014-09-08 21:22:15 +02:00
}
@Override
2014-09-08 21:22:15 +02:00
public boolean isFuzzy()
{
2014-12-29 15:13:47 +01:00
return this.myPartitionList instanceof FuzzyPriorityList;
2014-09-08 21:22:15 +02:00
}
@Override
public IncludeExclude getIncludeExcludeMode()
{
2014-12-29 15:13:47 +01:00
return this.myWhitelist;
2014-09-08 21:22:15 +02:00
}
public int getStatusForCell()
{
2014-12-29 15:13:47 +01:00
int val = this.getCellInv().getStatusForCell();
2015-02-03 12:04:13 +01:00
2014-12-29 15:13:47 +01:00
if ( val == 1 && this.isPreformatted() )
2014-09-08 21:22:15 +02:00
val = 2;
2015-02-03 12:04:13 +01:00
2014-09-08 21:22:15 +02:00
return val;
}
}