API"ed the Storage Cell Classes.

This commit is contained in:
AlgorithmX2 2014-03-27 19:48:38 -05:00
parent a5379c82f8
commit 404cc08128
6 changed files with 44 additions and 15 deletions

View file

@ -5,6 +5,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import appeng.api.implementations.tiles.IChestOrDrive; import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.storage.ICellHandler; import appeng.api.storage.ICellHandler;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel; import appeng.api.storage.StorageChannel;
@ -58,7 +60,7 @@ public class BasicCellHandler implements ICellHandler
@Override @Override
public double cellIdleDrain(ItemStack is, IMEInventory handler) public double cellIdleDrain(ItemStack is, IMEInventory handler)
{ {
CellInventory inv = ((CellInventoryHandler) handler).getCellInv(); ICellInventory inv = ((ICellInventoryHandler) handler).getCellInv();
return inv.getIdleDrain(); return inv.getIdleDrain();
} }
} }

View file

@ -13,6 +13,8 @@ import appeng.api.AEApi;
import appeng.api.config.FuzzyMode; import appeng.api.config.FuzzyMode;
import appeng.api.implementations.items.IItemGroup; import appeng.api.implementations.items.IItemGroup;
import appeng.api.implementations.items.IStorageCell; import appeng.api.implementations.items.IStorageCell;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel; import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
@ -23,7 +25,6 @@ import appeng.items.AEBaseItem;
import appeng.items.contents.CellConfig; import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades; import appeng.items.contents.CellUpgrades;
import appeng.items.materials.MaterialType; import appeng.items.materials.MaterialType;
import appeng.me.storage.CellInventory;
import appeng.me.storage.CellInventoryHandler; import appeng.me.storage.CellInventoryHandler;
import appeng.util.InventoryAdaptor; import appeng.util.InventoryAdaptor;
import appeng.util.Platform; import appeng.util.Platform;
@ -68,7 +69,7 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II
if ( cdi instanceof CellInventoryHandler ) if ( cdi instanceof CellInventoryHandler )
{ {
CellInventory cd = ((CellInventoryHandler) cdi).getCellInv(); ICellInventory cd = ((ICellInventoryHandler) cdi).getCellInv();
if ( cd != null ) if ( cd != null )
{ {
l.add( cd.usedBytes() + " " + GuiText.Of.getLocal() + " " + cd.totalBytes() + " " + GuiText.BytesUsed.getLocal() ); l.add( cd.usedBytes() + " " + GuiText.Of.getLocal() + " " + cd.totalBytes() + " " + GuiText.BytesUsed.getLocal() );

View file

@ -24,6 +24,8 @@ import appeng.api.config.FuzzyMode;
import appeng.api.config.Upgrades; import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IStorageCell; import appeng.api.implementations.items.IStorageCell;
import appeng.api.networking.security.PlayerSource; import appeng.api.networking.security.PlayerSource;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel; import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
@ -40,7 +42,6 @@ import appeng.hooks.DispenserMatterCannon;
import appeng.items.contents.CellConfig; import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades; import appeng.items.contents.CellUpgrades;
import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.me.storage.CellInventory;
import appeng.me.storage.CellInventoryHandler; import appeng.me.storage.CellInventoryHandler;
import appeng.util.Platform; import appeng.util.Platform;
@ -69,7 +70,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
if ( cdi instanceof CellInventoryHandler ) if ( cdi instanceof CellInventoryHandler )
{ {
CellInventory cd = ((CellInventoryHandler) cdi).getCellInv(); ICellInventory cd = ((ICellInventoryHandler) cdi).getCellInv();
if ( cd != null ) if ( cd != null )
{ {
lines.add( cd.usedBytes() + " " + GuiText.Of.getLocal() + " " + cd.totalBytes() + " " + GuiText.BytesUsed.getLocal() ); lines.add( cd.usedBytes() + " " + GuiText.Of.getLocal() + " " + cd.totalBytes() + " " + GuiText.BytesUsed.getLocal() );

View file

@ -14,6 +14,8 @@ import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.implementations.items.IItemGroup; import appeng.api.implementations.items.IItemGroup;
import appeng.api.implementations.items.IStorageCell; import appeng.api.implementations.items.IStorageCell;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel; import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
@ -25,7 +27,6 @@ import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades; import appeng.items.contents.CellUpgrades;
import appeng.items.contents.PortableCellViewer; import appeng.items.contents.PortableCellViewer;
import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.me.storage.CellInventory;
import appeng.me.storage.CellInventoryHandler; import appeng.me.storage.CellInventoryHandler;
import appeng.util.Platform; import appeng.util.Platform;
@ -54,7 +55,7 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell,
if ( cdi instanceof CellInventoryHandler ) if ( cdi instanceof CellInventoryHandler )
{ {
CellInventory cd = ((CellInventoryHandler) cdi).getCellInv(); ICellInventory cd = ((ICellInventoryHandler) cdi).getCellInv();
if ( cd != null ) if ( cd != null )
{ {
lines.add( cd.usedBytes() + " " + GuiText.Of.getLocal() + " " + cd.totalBytes() + " " + GuiText.BytesUsed.getLocal() ); lines.add( cd.usedBytes() + " " + GuiText.Of.getLocal() + " " + cd.totalBytes() + " " + GuiText.BytesUsed.getLocal() );

View file

@ -15,6 +15,7 @@ import appeng.api.config.FuzzyMode;
import appeng.api.exceptions.AppEngException; import appeng.api.exceptions.AppEngException;
import appeng.api.implementations.items.IStorageCell; import appeng.api.implementations.items.IStorageCell;
import appeng.api.networking.security.BaseActionSource; import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel; import appeng.api.storage.StorageChannel;
@ -23,7 +24,7 @@ import appeng.api.storage.data.IItemList;
import appeng.util.Platform; import appeng.util.Platform;
import appeng.util.item.AEItemStack; import appeng.util.item.AEItemStack;
public class CellInventory implements IMEInventory<IAEItemStack> public class CellInventory implements ICellInventory
{ {
static final String ITEM_TYPE_TAG = "it"; static final String ITEM_TYPE_TAG = "it";
@ -192,11 +193,13 @@ public class CellInventory implements IMEInventory<IAEItemStack>
return cellItems; return cellItems;
} }
@Override
public int BytesPerType() public int BytesPerType()
{ {
return CellType.BytePerType( i ); return CellType.BytePerType( i );
} }
@Override
public boolean canHoldNewItem() public boolean canHoldNewItem()
{ {
long bytesFree = freeBytes(); long bytesFree = freeBytes();
@ -254,32 +257,38 @@ public class CellInventory implements IMEInventory<IAEItemStack>
return false; return false;
} }
@Override
public long totalBytes() public long totalBytes()
{ {
return CellType.getBytes( i ); return CellType.getBytes( i );
} }
@Override
public long freeBytes() public long freeBytes()
{ {
return totalBytes() - usedBytes(); return totalBytes() - usedBytes();
} }
@Override
public long usedBytes() public long usedBytes()
{ {
long bytesForItemCount = (storedItemCount() + unusedItemCount()) / 8; long bytesForItemCount = (storedItemCount() + unusedItemCount()) / 8;
return storedItemTypes() * BytesPerType() + bytesForItemCount; return storedItemTypes() * BytesPerType() + bytesForItemCount;
} }
@Override
public long getTotalItemTypes() public long getTotalItemTypes()
{ {
return MAX_ITEM_TYPES; return MAX_ITEM_TYPES;
} }
@Override
public long storedItemTypes() public long storedItemTypes()
{ {
return storedItems; return storedItems;
} }
@Override
public long storedItemCount() public long storedItemCount()
{ {
return storedItemCount; return storedItemCount;
@ -290,6 +299,7 @@ public class CellInventory implements IMEInventory<IAEItemStack>
tagCompound.setInteger( ITEM_COUNT_TAG, storedItemCount = (int) (storedItemCount + delta) ); tagCompound.setInteger( ITEM_COUNT_TAG, storedItemCount = (int) (storedItemCount + delta) );
} }
@Override
public long remainingItemTypes() public long remainingItemTypes()
{ {
long basedOnStorage = freeBytes() / BytesPerType(); long basedOnStorage = freeBytes() / BytesPerType();
@ -297,14 +307,14 @@ public class CellInventory implements IMEInventory<IAEItemStack>
return basedOnStorage > baseOnTotal ? baseOnTotal : basedOnStorage; return basedOnStorage > baseOnTotal ? baseOnTotal : basedOnStorage;
} }
@Override
public long remainingItemCount() public long remainingItemCount()
{ {
long remaining = freeBytes() * 8 + unusedItemCount(); long remaining = freeBytes() * 8 + unusedItemCount();
return remaining > 0 ? remaining : 0; return remaining > 0 ? remaining : 0;
} }
// returns the number of items that can be added without using an additional @Override
// byte!
public int unusedItemCount() public int unusedItemCount()
{ {
int div = (int) (storedItemCount() % 8); int div = (int) (storedItemCount() % 8);
@ -479,26 +489,31 @@ public class CellInventory implements IMEInventory<IAEItemStack>
return StorageChannel.ITEMS; return StorageChannel.ITEMS;
} }
@Override
public double getIdleDrain() public double getIdleDrain()
{ {
return CellType.getIdleDrain(); return CellType.getIdleDrain();
} }
@Override
public FuzzyMode getFuzzyMode() public FuzzyMode getFuzzyMode()
{ {
return CellType.getFuzzyMode( this.i ); return CellType.getFuzzyMode( this.i );
} }
@Override
public IInventory getConfigInventory() public IInventory getConfigInventory()
{ {
return CellType.getConfigInventory( this.i ); return CellType.getConfigInventory( this.i );
} }
@Override
public IInventory getUpgradesInventory() public IInventory getUpgradesInventory()
{ {
return CellType.getUpgradesInventory( this.i ); return CellType.getUpgradesInventory( this.i );
} }
@Override
public int getStatusForCell() public int getStatusForCell()
{ {
if ( canHoldNewItem() ) if ( canHoldNewItem() )
@ -508,4 +523,10 @@ public class CellInventory implements IMEInventory<IAEItemStack>
return 3; return 3;
} }
@Override
public ItemStack getItemStack()
{
return i;
}
} }

View file

@ -8,6 +8,8 @@ import appeng.api.config.FuzzyMode;
import appeng.api.config.IncludeExclude; import appeng.api.config.IncludeExclude;
import appeng.api.config.Upgrades; import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IUpgradeModule; import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEInventory;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList; import appeng.api.storage.data.IItemList;
@ -16,28 +18,29 @@ import appeng.util.item.AEItemStack;
import appeng.util.prioitylist.FuzzyPriorityList; import appeng.util.prioitylist.FuzzyPriorityList;
import appeng.util.prioitylist.PrecisePriorityList; import appeng.util.prioitylist.PrecisePriorityList;
public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> implements ICellInventoryHandler
{ {
NBTTagCompound openNbtData() NBTTagCompound openNbtData()
{ {
return Platform.openNbtData( getCellInv().i ); return Platform.openNbtData( getCellInv().getItemStack() );
} }
public CellInventory getCellInv() @Override
public ICellInventory getCellInv()
{ {
Object o = this.internal; Object o = this.internal;
if ( o instanceof MEPassthru ) if ( o instanceof MEPassthru )
o = ((MEPassthru) o).getInternal(); o = ((MEPassthru) o).getInternal();
return (CellInventory) (o instanceof CellInventory ? o : null); return (ICellInventory) (o instanceof ICellInventory ? o : null);
} }
CellInventoryHandler(IMEInventory c) { CellInventoryHandler(IMEInventory c) {
super( c, IAEItemStack.class ); super( c, IAEItemStack.class );
CellInventory ci = getCellInv(); ICellInventory ci = getCellInv();
if ( ci != null ) if ( ci != null )
{ {
IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList(); IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();