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
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.HashSet;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTBase;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-02-21 21:36:40 +01:00
|
|
|
import appeng.api.AEApi;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.config.Actionable;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.config.FuzzyMode;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.exceptions.AppEngException;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.items.IStorageCell;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
2014-03-28 01:48:38 +01:00
|
|
|
import appeng.api.storage.ICellInventory;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.IMEInventory;
|
|
|
|
import appeng.api.storage.IMEInventoryHandler;
|
2014-07-28 07:11:34 +02:00
|
|
|
import appeng.api.storage.ISaveProvider;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.StorageChannel;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.storage.data.IItemList;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
import appeng.util.item.AEItemStack;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-03-28 01:48:38 +01:00
|
|
|
public class CellInventory implements ICellInventory
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
static final String ITEM_TYPE_TAG = "it";
|
|
|
|
static final String ITEM_COUNT_TAG = "ic";
|
|
|
|
static final String ITEM_SLOT = "#";
|
2014-09-28 11:47:17 +02:00
|
|
|
static final String ITEM_SLOT_COUNT = "@";
|
2014-09-21 01:03:46 +02:00
|
|
|
static final String ITEM_PRE_FORMATTED_COUNT = "PF";
|
|
|
|
static final String ITEM_PRE_FORMATTED_SLOT = "PF#";
|
|
|
|
static final String ITEM_PRE_FORMATTED_NAME = "PN";
|
|
|
|
static final String ITEM_PRE_FORMATTED_FUZZY = "FP";
|
2015-04-03 08:54:31 +02:00
|
|
|
private static final HashSet<Integer> BLACK_LIST = new HashSet<Integer>();
|
2015-04-06 00:35:42 +02:00
|
|
|
protected static String[] ITEM_SLOT_ARR;
|
|
|
|
protected static String[] ITEM_SLOT_COUNT_ARR;
|
|
|
|
protected final NBTTagCompound tagCompound;
|
|
|
|
protected final ISaveProvider container;
|
2013-12-27 23:59:59 +01:00
|
|
|
protected int MAX_ITEM_TYPES = 63;
|
|
|
|
protected short storedItems = 0;
|
|
|
|
protected int storedItemCount = 0;
|
2014-02-21 21:36:40 +01:00
|
|
|
protected IItemList<IAEItemStack> cellItems;
|
2013-12-27 23:59:59 +01:00
|
|
|
protected ItemStack i;
|
|
|
|
protected IStorageCell CellType;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
protected CellInventory( NBTTagCompound data, ISaveProvider container )
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tagCompound = data;
|
2014-07-28 07:11:34 +02:00
|
|
|
this.container = container;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
protected CellInventory( ItemStack o, ISaveProvider container ) throws AppEngException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ITEM_SLOT_ARR == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ITEM_SLOT_ARR = new String[this.MAX_ITEM_TYPES];
|
|
|
|
ITEM_SLOT_COUNT_ARR = new String[this.MAX_ITEM_TYPES];
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < this.MAX_ITEM_TYPES; x++ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
ITEM_SLOT_ARR[x] = ITEM_SLOT + x;
|
2014-09-28 11:47:17 +02:00
|
|
|
ITEM_SLOT_COUNT_ARR[x] = ITEM_SLOT_COUNT + x;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( o == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.CellType = null;
|
|
|
|
this.i = o;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
Item type = this.i.getItem();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( type instanceof IStorageCell )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.CellType = (IStorageCell) this.i.getItem();
|
|
|
|
this.MAX_ITEM_TYPES = this.CellType.getTotalTypes( this.i );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.CellType == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.CellType.isStorageCell( this.i ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.MAX_ITEM_TYPES > 63 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.MAX_ITEM_TYPES = 63;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.MAX_ITEM_TYPES < 1 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.MAX_ITEM_TYPES = 1;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-07-28 07:11:34 +02:00
|
|
|
this.container = container;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tagCompound = Platform.openNbtData( o );
|
|
|
|
this.storedItems = this.tagCompound.getShort( ITEM_TYPE_TAG );
|
|
|
|
this.storedItemCount = this.tagCompound.getInteger( ITEM_COUNT_TAG );
|
|
|
|
this.cellItems = null;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static IMEInventoryHandler getCell( ItemStack o, ISaveProvider container2 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-07-28 07:11:34 +02:00
|
|
|
return new CellInventoryHandler( new CellInventory( o, container2 ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( AppEngException e )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private static boolean isStorageCell( ItemStack i )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( i == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Item type = i.getItem();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( type instanceof IStorageCell )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return !( (IStorageCell) type ).storableInStorageCell();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable err )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean isCell( ItemStack i )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( i == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Item type = i.getItem();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( type instanceof IStorageCell )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return ( (IStorageCell) type ).isStorageCell( i );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static void addBasicBlackList( int itemID, int Meta )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-01-01 22:13:10 +01:00
|
|
|
BLACK_LIST.add( ( Meta << Platform.DEF_OFFSET ) | itemID );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean isBlackListed( IAEItemStack input )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( BLACK_LIST.contains( ( OreDictionary.WILDCARD_VALUE << Platform.DEF_OFFSET ) | Item.getIdFromItem( input.getItem() ) ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return BLACK_LIST.contains( ( input.getItemDamage() << Platform.DEF_OFFSET ) | Item.getIdFromItem( input.getItem() ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private boolean isEmpty( IMEInventory meInventory )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
return meInventory.getAvailableItems( AEApi.instance().storage().createItemList() ).isEmpty();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public IAEItemStack injectItems( IAEItemStack input, Actionable mode, BaseActionSource src )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( input == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( input.getStackSize() == 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( isBlackListed( input ) || this.CellType.isBlackListed( this.i, input ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return input;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
ItemStack sharedItemStack = input.getItemStack();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( CellInventory.isStorageCell( sharedItemStack ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
IMEInventory meInventory = getCell( sharedItemStack, null );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( meInventory != null && !this.isEmpty( meInventory ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return input;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
IAEItemStack l = this.getCellItems().findPrecise( input );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( l != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
long remainingItemSlots = this.getRemainingItemCount();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( remainingItemSlots < 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return input;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( input.getStackSize() > remainingItemSlots )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
IAEItemStack r = input.copy();
|
|
|
|
r.setStackSize( r.getStackSize() - remainingItemSlots );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( mode == Actionable.MODULATE )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
l.setStackSize( l.getStackSize() + remainingItemSlots );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.updateItemCount( remainingItemSlots );
|
|
|
|
this.saveChanges();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( mode == Actionable.MODULATE )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
l.setStackSize( l.getStackSize() + input.getStackSize() );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.updateItemCount( input.getStackSize() );
|
|
|
|
this.saveChanges();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.canHoldNewItem() ) // room for new type, and for at least one item!
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
int remainingItemCount = (int) this.getRemainingItemCount() - this.getBytesPerType() * 8;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( remainingItemCount > 0 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( input.getStackSize() > remainingItemCount )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
ItemStack toReturn = Platform.cloneItemStack( sharedItemStack );
|
|
|
|
toReturn.stackSize = sharedItemStack.stackSize - remainingItemCount;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( mode == Actionable.MODULATE )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
ItemStack toWrite = Platform.cloneItemStack( sharedItemStack );
|
|
|
|
toWrite.stackSize = remainingItemCount;
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.cellItems.add( AEItemStack.create( toWrite ) );
|
|
|
|
this.updateItemCount( toWrite.stackSize );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.saveChanges();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
return AEItemStack.create( toReturn );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( mode == Actionable.MODULATE )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.updateItemCount( input.getStackSize() );
|
|
|
|
this.cellItems.add( input );
|
|
|
|
this.saveChanges();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, BaseActionSource src )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( request == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-03-07 15:45:59 +01:00
|
|
|
long size = Math.min( Integer.MAX_VALUE, request.getStackSize() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
IAEItemStack Results = null;
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
IAEItemStack l = this.getCellItems().findPrecise( request );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( l != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
Results = l.copy();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( l.getStackSize() <= size )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
Results.setStackSize( l.getStackSize() );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( mode == Actionable.MODULATE )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.updateItemCount( -l.getStackSize() );
|
2013-12-27 23:59:59 +01:00
|
|
|
l.setStackSize( 0 );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.saveChanges();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Results.setStackSize( size );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( mode == Actionable.MODULATE )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
l.setStackSize( l.getStackSize() - size );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.updateItemCount( -size );
|
|
|
|
this.saveChanges();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Results;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
IItemList<IAEItemStack> getCellItems()
|
|
|
|
{
|
|
|
|
if( this.cellItems == null )
|
|
|
|
{
|
|
|
|
this.cellItems = AEApi.instance().storage().createItemList();
|
|
|
|
this.loadCellItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.cellItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateItemCount( long delta )
|
|
|
|
{
|
|
|
|
this.storedItemCount += delta;
|
|
|
|
this.tagCompound.setInteger( ITEM_COUNT_TAG, this.storedItemCount );
|
|
|
|
}
|
|
|
|
|
|
|
|
void saveChanges()
|
|
|
|
{
|
|
|
|
// cellItems.clean();
|
|
|
|
int itemCount = 0;
|
|
|
|
|
|
|
|
// add new pretty stuff...
|
|
|
|
int x = 0;
|
|
|
|
for( IAEItemStack v : this.cellItems )
|
|
|
|
{
|
|
|
|
itemCount += v.getStackSize();
|
|
|
|
|
|
|
|
NBTBase c = this.tagCompound.getTag( ITEM_SLOT_ARR[x] );
|
|
|
|
if( c instanceof NBTTagCompound )
|
|
|
|
{
|
|
|
|
v.writeToNBT( (NBTTagCompound) c );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NBTTagCompound g = new NBTTagCompound();
|
|
|
|
v.writeToNBT( g );
|
|
|
|
this.tagCompound.setTag( ITEM_SLOT_ARR[x], g );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NBTBase tagSlotCount = tagCompound.getTag( ITEM_SLOT_COUNT_ARR[x] ); if ( tagSlotCount instanceof
|
|
|
|
* NBTTagInt ) ((NBTTagInt) tagSlotCount).data = (int) v.getStackSize(); else
|
|
|
|
*/
|
|
|
|
this.tagCompound.setInteger( ITEM_SLOT_COUNT_ARR[x], (int) v.getStackSize() );
|
|
|
|
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NBTBase tagType = tagCompound.getTag( ITEM_TYPE_TAG );
|
|
|
|
// NBTBase tagCount = tagCompound.getTag( ITEM_COUNT_TAG );
|
|
|
|
short oldStoredItems = this.storedItems;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if ( tagType instanceof NBTTagShort ) ((NBTTagShort) tagType).data = storedItems = (short) cellItems.size();
|
|
|
|
* else
|
|
|
|
*/
|
|
|
|
if( this.cellItems.isEmpty() )
|
|
|
|
{
|
|
|
|
this.tagCompound.removeTag( ITEM_TYPE_TAG );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.storedItems = (short) this.cellItems.size();
|
|
|
|
this.tagCompound.setShort( ITEM_TYPE_TAG, this.storedItems );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if ( tagCount instanceof NBTTagInt ) ((NBTTagInt) tagCount).data = storedItemCount = itemCount; else
|
|
|
|
*/
|
|
|
|
if( itemCount == 0 )
|
|
|
|
{
|
|
|
|
this.tagCompound.removeTag( ITEM_COUNT_TAG );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.storedItemCount = itemCount;
|
|
|
|
this.tagCompound.setInteger( ITEM_COUNT_TAG, itemCount );
|
|
|
|
}
|
|
|
|
|
|
|
|
// clean any old crusty stuff...
|
|
|
|
for(; x < oldStoredItems && x < this.MAX_ITEM_TYPES; x++ )
|
|
|
|
{
|
|
|
|
this.tagCompound.removeTag( ITEM_SLOT_ARR[x] );
|
|
|
|
this.tagCompound.removeTag( ITEM_SLOT_COUNT_ARR[x] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( this.container != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.container.saveChanges( this );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void loadCellItems()
|
|
|
|
{
|
|
|
|
if( this.cellItems == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.cellItems = AEApi.instance().storage().createItemList();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
this.cellItems.resetStatus(); // clears totals and stuff.
|
|
|
|
|
|
|
|
int types = (int) this.getStoredItemTypes();
|
|
|
|
|
|
|
|
for( int x = 0; x < types; x++ )
|
|
|
|
{
|
|
|
|
ItemStack t = ItemStack.loadItemStackFromNBT( this.tagCompound.getCompoundTag( ITEM_SLOT_ARR[x] ) );
|
|
|
|
if( t != null )
|
|
|
|
{
|
|
|
|
t.stackSize = this.tagCompound.getInteger( ITEM_SLOT_COUNT_ARR[x] );
|
|
|
|
|
|
|
|
if( t.stackSize > 0 )
|
|
|
|
{
|
|
|
|
this.cellItems.add( AEItemStack.create( t ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// cellItems.clean();
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public IItemList getAvailableItems( IItemList out )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IAEItemStack i : this.getCellItems() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
out.add( i );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StorageChannel getChannel()
|
|
|
|
{
|
|
|
|
return StorageChannel.ITEMS;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public ItemStack getItemStack()
|
|
|
|
{
|
|
|
|
return this.i;
|
|
|
|
}
|
|
|
|
|
2014-03-28 01:48:38 +01:00
|
|
|
@Override
|
2013-12-27 23:59:59 +01:00
|
|
|
public double getIdleDrain()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.CellType.getIdleDrain();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-03-28 01:48:38 +01:00
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public FuzzyMode getFuzzyMode()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.CellType.getFuzzyMode( this.i );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2014-03-28 01:48:38 +01:00
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public IInventory getConfigInventory()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.CellType.getConfigInventory( this.i );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2014-03-28 01:48:38 +01:00
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public IInventory getUpgradesInventory()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.CellType.getUpgradesInventory( this.i );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2014-03-28 01:48:38 +01:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public int getBytesPerType()
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.CellType.BytePerType( this.i );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2014-03-28 01:48:38 +01:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean canHoldNewItem()
|
2014-03-28 01:48:38 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
long bytesFree = this.getFreeBytes();
|
|
|
|
return ( bytesFree > this.getBytesPerType() || ( bytesFree == this.getBytesPerType() && this.getUnusedItemCount() > 0 ) ) && this.getRemainingItemTypes() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getTotalBytes()
|
|
|
|
{
|
|
|
|
return this.CellType.getBytes( this.i );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getFreeBytes()
|
|
|
|
{
|
|
|
|
return this.getTotalBytes() - this.getUsedBytes();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getUsedBytes()
|
|
|
|
{
|
|
|
|
long bytesForItemCount = ( this.getStoredItemCount() + this.getUnusedItemCount() ) / 8;
|
|
|
|
return this.getStoredItemTypes() * this.getBytesPerType() + bytesForItemCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getTotalItemTypes()
|
|
|
|
{
|
|
|
|
return this.MAX_ITEM_TYPES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getStoredItemCount()
|
|
|
|
{
|
|
|
|
return this.storedItemCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getStoredItemTypes()
|
|
|
|
{
|
|
|
|
return this.storedItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getRemainingItemTypes()
|
|
|
|
{
|
|
|
|
long basedOnStorage = this.getFreeBytes() / this.getBytesPerType();
|
|
|
|
long baseOnTotal = this.getTotalItemTypes() - this.getStoredItemTypes();
|
|
|
|
return basedOnStorage > baseOnTotal ? baseOnTotal : basedOnStorage;
|
2014-03-28 01:48:38 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public long getRemainingItemCount()
|
|
|
|
{
|
|
|
|
long remaining = this.getFreeBytes() * 8 + this.getUnusedItemCount();
|
|
|
|
return remaining > 0 ? remaining : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getUnusedItemCount()
|
|
|
|
{
|
|
|
|
int div = (int) ( this.getStoredItemCount() % 8 );
|
|
|
|
|
|
|
|
if( div == 0 )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 8 - div;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getStatusForCell()
|
|
|
|
{
|
|
|
|
if( this.canHoldNewItem() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return 1;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.getRemainingItemCount() > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return 2;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return 3;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|