2013-12-27 23:59:59 +01:00
|
|
|
package appeng.me.storage;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
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;
|
2013-12-27 23:59:59 +01:00
|
|
|
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;
|
2013-12-27 23:59:59 +01: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
|
|
|
{
|
|
|
|
|
|
|
|
NBTTagCompound openNbtData()
|
|
|
|
{
|
2014-03-28 01:48:38 +01:00
|
|
|
return Platform.openNbtData( getCellInv().getItemStack() );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-03-28 01:48:38 +01:00
|
|
|
@Override
|
|
|
|
public ICellInventory getCellInv()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
Object o = this.internal;
|
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
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);
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CellInventoryHandler(IMEInventory c) {
|
2014-07-23 21:11:12 +02:00
|
|
|
super( c, StorageChannel.ITEMS );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-03-28 01:48:38 +01:00
|
|
|
ICellInventory ci = 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 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
myWhitelist = hasInverter ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST;
|
|
|
|
|
|
|
|
if ( !priorityList.isEmpty() )
|
|
|
|
{
|
|
|
|
if ( hasFuzzy )
|
|
|
|
myPartitionList = new FuzzyPriorityList<IAEItemStack>( priorityList, fzMode );
|
|
|
|
else
|
|
|
|
myPartitionList = new PrecisePriorityList<IAEItemStack>( priorityList );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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 isPreformatted()
|
|
|
|
{
|
|
|
|
return ! myPartitionList.isEmpty();
|
|
|
|
}
|
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2014-09-08 21:22:15 +02:00
|
|
|
public boolean isFuzzy()
|
|
|
|
{
|
|
|
|
return myPartitionList instanceof FuzzyPriorityList;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IncludeExclude getIncludeExcludeMode()
|
|
|
|
{
|
|
|
|
return myWhitelist;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getStatusForCell()
|
|
|
|
{
|
|
|
|
int val = getCellInv().getStatusForCell();
|
|
|
|
|
|
|
|
if ( val == 1 && isPreformatted() )
|
|
|
|
val = 2;
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|