From cf6b0986fcb76f5fc21278d81d4264ce8b245f41 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Fri, 21 Feb 2014 14:36:40 -0600 Subject: [PATCH] Fortify ItemLists. --- api | 2 +- client/me/ItemRepo.java | 8 ++--- .../ContainerCellWorkbench.java | 3 +- .../ContainerMEMonitorable.java | 4 +-- core/api/ApiStorage.java | 10 ++++-- helpers/DualityInterface.java | 4 +-- items/tools/powered/ToolMassCannon.java | 3 +- me/cache/GridStorageCache.java | 11 +++---- me/storage/CellInventory.java | 12 +++---- me/storage/CellInventoryHandler.java | 6 ++-- me/storage/CreativeCellInventory.java | 4 +-- me/storage/DriveWatcher.java | 2 +- me/storage/MEInventoryHandler.java | 15 +++++---- me/storage/MEMonitorIInventory.java | 3 +- me/storage/MEMonitorPassthu.java | 10 +++--- me/storage/MEPassthru.java | 4 ++- me/storage/SecurityInventory.java | 2 +- parts/automation/PartFormationPlane.java | 6 ++-- parts/misc/PartStorageBus.java | 5 ++- tile/storage/TileChest.java | 2 +- tile/storage/TileIOPort.java | 4 +-- util/Platform.java | 8 ++--- util/item/ItemList.java | 31 ++++++++++++++++--- 23 files changed, 93 insertions(+), 66 deletions(-) diff --git a/api b/api index 7834e09f..2fed92ea 160000 --- a/api +++ b/api @@ -1 +1 @@ -Subproject commit 7834e09f349699868a1074879a7a3902e3fd2bf4 +Subproject commit 2fed92eaa8c7dd3434e6c0c20552c6fd2605959c diff --git a/client/me/ItemRepo.java b/client/me/ItemRepo.java index ea76b446..a462e8eb 100644 --- a/client/me/ItemRepo.java +++ b/client/me/ItemRepo.java @@ -5,6 +5,7 @@ import java.util.Collections; import java.util.regex.Pattern; import net.minecraft.item.ItemStack; +import appeng.api.AEApi; import appeng.api.config.Settings; import appeng.api.config.SortOrder; import appeng.api.config.YesNo; @@ -15,14 +16,13 @@ import appeng.client.gui.widgets.ISortSource; import appeng.core.AEConfig; import appeng.util.ItemSorters; import appeng.util.Platform; -import appeng.util.item.ItemList; public class ItemRepo { - final private IItemList list = new ItemList(); - final private ArrayList view = new ArrayList(); - final private ArrayList dsp = new ArrayList(); + final private IItemList list = AEApi.instance().storage().createItemList(); + final private ArrayList view = new ArrayList(); + final private ArrayList dsp = new ArrayList(); final private IScrollSource src; final private ISortSource sortSrc; diff --git a/container/implementations/ContainerCellWorkbench.java b/container/implementations/ContainerCellWorkbench.java index d33f1bf1..e9aec2d4 100644 --- a/container/implementations/ContainerCellWorkbench.java +++ b/container/implementations/ContainerCellWorkbench.java @@ -22,7 +22,6 @@ import appeng.container.slot.SlotRestrictedInput.PlaceableItemType; import appeng.tile.inventory.AppEngNullInventory; import appeng.tile.misc.TileCellWorkbench; import appeng.util.Platform; -import appeng.util.item.ItemList; import appeng.util.iterators.NullIterator; public class ContainerCellWorkbench extends ContainerUpgradeable @@ -268,7 +267,7 @@ public class ContainerCellWorkbench extends ContainerUpgradeable Iterator i = new NullIterator(); if ( cellInv != null ) { - IItemList list = cellInv.getAvailableItems( new ItemList() ); + IItemList list = cellInv.getAvailableItems( AEApi.instance().storage().createItemList() ); i = list.iterator(); } diff --git a/container/implementations/ContainerMEMonitorable.java b/container/implementations/ContainerMEMonitorable.java index bc0b1f4d..13a341ca 100644 --- a/container/implementations/ContainerMEMonitorable.java +++ b/container/implementations/ContainerMEMonitorable.java @@ -9,6 +9,7 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; import appeng.api.config.Settings; import appeng.api.config.SortDir; import appeng.api.config.SortOrder; @@ -36,13 +37,12 @@ import appeng.core.sync.packets.PacketValueConfig; import appeng.util.ConfigManager; import appeng.util.IConfigManagerHost; import appeng.util.Platform; -import appeng.util.item.ItemList; public class ContainerMEMonitorable extends AEBaseContainer implements IConfigManagerHost, IConfigureableObject, IMEMonitorHandlerReceiver { final IMEMonitor monitor; - final IItemList items = new ItemList(); + final IItemList items = AEApi.instance().storage().createItemList(); IConfigManager serverCM; IConfigManager clientCM; diff --git a/core/api/ApiStorage.java b/core/api/ApiStorage.java index 3e1125d9..b9f6f646 100644 --- a/core/api/ApiStorage.java +++ b/core/api/ApiStorage.java @@ -34,9 +34,15 @@ public class ApiStorage implements IStorageHelper } @Override - public IItemList createItemList() + public IItemList createItemList() { - return new ItemList(); + return new ItemList( IAEItemStack.class); + } + + @Override + public IItemList createFluidList() + { + return new ItemList( IAEFluidStack.class); } @Override diff --git a/helpers/DualityInterface.java b/helpers/DualityInterface.java index c1fe084b..81c6a029 100644 --- a/helpers/DualityInterface.java +++ b/helpers/DualityInterface.java @@ -285,8 +285,8 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt return patterns; } - MEMonitorPassthu items = new MEMonitorPassthu( new NullInventory() ); - MEMonitorPassthu fluids = new MEMonitorPassthu( new NullInventory() ); + MEMonitorPassthu items = new MEMonitorPassthu( new NullInventory(), IAEItemStack.class ); + MEMonitorPassthu fluids = new MEMonitorPassthu( new NullInventory(), IAEFluidStack.class ); public void gridChanged() { diff --git a/items/tools/powered/ToolMassCannon.java b/items/tools/powered/ToolMassCannon.java index ffeab325..b7e009a8 100644 --- a/items/tools/powered/ToolMassCannon.java +++ b/items/tools/powered/ToolMassCannon.java @@ -41,7 +41,6 @@ import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.me.storage.CellInventory; import appeng.me.storage.CellInventoryHandler; import appeng.util.Platform; -import appeng.util.item.ItemList; public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell { @@ -84,7 +83,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell IMEInventory inv = AEApi.instance().registries().cell().getCellInventory( item, StorageChannel.ITEMS ); if ( inv != null ) { - IItemList itemList = inv.getAvailableItems( new ItemList() ); + IItemList itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() ); IAEStack aeammo = itemList.getFirstItem(); if ( aeammo instanceof IAEItemStack ) { diff --git a/me/cache/GridStorageCache.java b/me/cache/GridStorageCache.java index 06c0f08e..435042f3 100644 --- a/me/cache/GridStorageCache.java +++ b/me/cache/GridStorageCache.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import appeng.api.AEApi; import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; import appeng.api.networking.IGridNode; @@ -26,8 +27,6 @@ import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; import appeng.me.storage.ItemWatcher; import appeng.me.storage.NetworkInventoryHandler; -import appeng.util.item.ItemList; - import com.google.common.collect.HashMultimap; import com.google.common.collect.SetMultimap; @@ -68,12 +67,12 @@ public class GridStorageCache implements IStorageGrid for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.ITEMS )) { - postChanges( StorageChannel.ITEMS, 1, h.getAvailableItems( new ItemList() ), new MachineSource( cc ) ); + postChanges( StorageChannel.ITEMS, 1, h.getAvailableItems( AEApi.instance().storage().createItemList() ), new MachineSource( cc ) ); } for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.FLUIDS )) { - postChanges( StorageChannel.FLUIDS, 1, h.getAvailableItems( new ItemList() ), new MachineSource( cc ) ); + postChanges( StorageChannel.FLUIDS, 1, h.getAvailableItems( AEApi.instance().storage().createFluidList() ), new MachineSource( cc ) ); } } } @@ -87,12 +86,12 @@ public class GridStorageCache implements IStorageGrid for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.ITEMS )) { - postChanges( StorageChannel.ITEMS, -1, h.getAvailableItems( new ItemList() ), new MachineSource( cc ) ); + postChanges( StorageChannel.ITEMS, -1, h.getAvailableItems( AEApi.instance().storage().createItemList() ), new MachineSource( cc ) ); } for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.FLUIDS )) { - postChanges( StorageChannel.FLUIDS, -1, h.getAvailableItems( new ItemList() ), new MachineSource( cc ) ); + postChanges( StorageChannel.FLUIDS, -1, h.getAvailableItems( AEApi.instance().storage().createFluidList() ), new MachineSource( cc ) ); } } } diff --git a/me/storage/CellInventory.java b/me/storage/CellInventory.java index 10d57259..155c066e 100644 --- a/me/storage/CellInventory.java +++ b/me/storage/CellInventory.java @@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.oredict.OreDictionary; +import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; import appeng.api.exceptions.AppEngException; @@ -21,7 +22,6 @@ import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.util.Platform; import appeng.util.item.AEItemStack; -import appeng.util.item.ItemList; public class CellInventory implements IMEInventory { @@ -42,7 +42,7 @@ public class CellInventory implements IMEInventory protected int MAX_ITEM_TYPES = 63; protected short storedItems = 0; protected int storedItemCount = 0; - protected ItemList cellItems; + protected IItemList cellItems; protected ItemStack i; protected IStorageCell CellType; @@ -54,7 +54,7 @@ public class CellInventory implements IMEInventory protected void loadCellItems() { if ( cellItems == null ) - cellItems = new ItemList(); + cellItems = AEApi.instance().storage().createItemList(); cellItems.resetStatus(); // clears totals and stuff. @@ -181,11 +181,11 @@ public class CellInventory implements IMEInventory cellItems = null; } - ItemList getCellItems() + IItemList getCellItems() { if ( cellItems == null ) { - cellItems = new ItemList(); + cellItems = AEApi.instance().storage().createItemList(); loadCellItems(); } @@ -333,7 +333,7 @@ public class CellInventory implements IMEInventory private boolean isEmpty(IMEInventory meinv) { - return meinv.getAvailableItems( new ItemList() ).isEmpty(); + return meinv.getAvailableItems( AEApi.instance().storage().createItemList() ).isEmpty(); } @Override diff --git a/me/storage/CellInventoryHandler.java b/me/storage/CellInventoryHandler.java index 01314691..5eb3e4d9 100644 --- a/me/storage/CellInventoryHandler.java +++ b/me/storage/CellInventoryHandler.java @@ -3,6 +3,7 @@ package appeng.me.storage; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import appeng.api.AEApi; import appeng.api.config.FuzzyMode; import appeng.api.config.IncludeExclude; import appeng.api.config.Upgrades; @@ -12,7 +13,6 @@ import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.util.Platform; import appeng.util.item.AEItemStack; -import appeng.util.item.ItemList; import appeng.util.prioitylist.FuzzyPriorityList; import appeng.util.prioitylist.PrecisePriorityList; @@ -35,12 +35,12 @@ public class CellInventoryHandler extends MEInventoryHandler } CellInventoryHandler(IMEInventory c) { - super( c ); + super( c, IAEItemStack.class ); CellInventory ci = getCellInv(); if ( ci != null ) { - IItemList priorityList = new ItemList(); + IItemList priorityList = AEApi.instance().storage().createItemList(); IInventory upgrades = ci.getUpgradesInventory(); IInventory config = ci.getConfigInventory(); diff --git a/me/storage/CreativeCellInventory.java b/me/storage/CreativeCellInventory.java index 678dcccb..6ad6b6f1 100644 --- a/me/storage/CreativeCellInventory.java +++ b/me/storage/CreativeCellInventory.java @@ -1,6 +1,7 @@ package appeng.me.storage; import net.minecraft.item.ItemStack; +import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; import appeng.api.exceptions.AppEngException; @@ -11,12 +12,11 @@ import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.items.contents.CellConfig; import appeng.util.item.AEItemStack; -import appeng.util.item.ItemList; public class CreativeCellInventory implements IMEInventoryHandler { - ItemList itemListCache = new ItemList(); + IItemList itemListCache = AEApi.instance().storage().createItemList(); public static IMEInventoryHandler getCell(ItemStack o) { diff --git a/me/storage/DriveWatcher.java b/me/storage/DriveWatcher.java index 38437e29..85f5681d 100644 --- a/me/storage/DriveWatcher.java +++ b/me/storage/DriveWatcher.java @@ -17,7 +17,7 @@ public class DriveWatcher> extends MEInventoryHandler final IChestOrDrive cord; public DriveWatcher(IMEInventory i, ItemStack is, ICellHandler han, IChestOrDrive cod) { - super( i ); + super( i, i.getChannel().type ); this.is = is; handler = han; cord = cod; diff --git a/me/storage/MEInventoryHandler.java b/me/storage/MEInventoryHandler.java index 3943bbfb..5a239e84 100644 --- a/me/storage/MEInventoryHandler.java +++ b/me/storage/MEInventoryHandler.java @@ -15,20 +15,23 @@ import appeng.util.prioitylist.IPartitionList; public class MEInventoryHandler> implements IMEInventoryHandler { - + + Class clz; final protected IMEMonitor monitor; final protected IMEInventoryHandler internal; public int myPriority = 0; public IncludeExclude myWhitelist = IncludeExclude.WHITELIST; public AccessRestriction myAccess = AccessRestriction.READ_WRITE; - public IPartitionList myPartitionList = new DefaultPriorityList(); + public IPartitionList myPartitionList = new DefaultPriorityList(); - public MEInventoryHandler(IMEInventory i) { + public MEInventoryHandler(IMEInventory i,Class cla) { + clz = cla; + if ( i instanceof IMEInventoryHandler ) internal = (IMEInventoryHandler) i; else - internal = new MEPassthru( i ); + internal = new MEPassthru( i,clz ); monitor = internal instanceof IMEMonitor ? (IMEMonitor) internal : null; } @@ -52,7 +55,7 @@ public class MEInventoryHandler> implements IMEInventoryHa } @Override - public IItemList getAvailableItems(IItemList out) + public IItemList getAvailableItems(IItemList out) { if ( !getAccess().hasPermission( AccessRestriction.READ ) ) return out; @@ -105,7 +108,7 @@ public class MEInventoryHandler> implements IMEInventoryHa return internal.getSlot(); } - public IMEInventory getInternal() + public IMEInventory getInternal() { return internal; } diff --git a/me/storage/MEMonitorIInventory.java b/me/storage/MEMonitorIInventory.java index aa1593f9..87a6027f 100644 --- a/me/storage/MEMonitorIInventory.java +++ b/me/storage/MEMonitorIInventory.java @@ -23,7 +23,6 @@ import appeng.util.InventoryAdaptor; import appeng.util.Platform; import appeng.util.inv.ItemSlot; import appeng.util.item.AEItemStack; -import appeng.util.item.ItemList; public class MEMonitorIInventory implements IMEInventory, IMEMonitor { @@ -53,7 +52,7 @@ public class MEMonitorIInventory implements IMEInventory, IMEMonit final InventoryAdaptor adaptor; final TreeMap memory; - final IItemList list = new ItemList(); + final IItemList list = AEApi.instance().storage().createItemList(); final HashMap, Object> listeners = new HashMap(); public BaseActionSource mySource; diff --git a/me/storage/MEMonitorPassthu.java b/me/storage/MEMonitorPassthu.java index a2e66e05..6c7302cb 100644 --- a/me/storage/MEMonitorPassthu.java +++ b/me/storage/MEMonitorPassthu.java @@ -21,8 +21,8 @@ public class MEMonitorPassthu> extends MEPassthru imple public BaseActionSource changeSource; - public MEMonitorPassthu(IMEInventory i) { - super( i ); + public MEMonitorPassthu(IMEInventory i, Class cla) { + super( i,cla ); if ( i instanceof IMEMonitor ) monitor = (IMEMonitor) i; } @@ -34,13 +34,13 @@ public class MEMonitorPassthu> extends MEPassthru imple monitor.removeListener( this ); monitor = null; - IItemList before = getInternal() == null ? new ItemList() : getInternal().getAvailableItems( new ItemList() ); + IItemList before = getInternal() == null ? new ItemList(clz) : getInternal().getAvailableItems( new ItemList(clz) ); super.setInternal( i ); if ( i instanceof IMEMonitor ) monitor = (IMEMonitor) i; - IItemList after = getInternal() == null ? new ItemList() : getInternal().getAvailableItems( new ItemList() ); + IItemList after = getInternal() == null ? new ItemList(clz) : getInternal().getAvailableItems( new ItemList(clz) ); if ( monitor != null ) monitor.addListener( this, monitor ); @@ -64,7 +64,7 @@ public class MEMonitorPassthu> extends MEPassthru imple public IItemList getStorageList() { if ( monitor == null ) - return getInternal().getAvailableItems( new ItemList() ); + return getInternal().getAvailableItems( new ItemList(clz) ); return monitor.getStorageList(); } diff --git a/me/storage/MEPassthru.java b/me/storage/MEPassthru.java index 9c49fd97..3bfbb7c7 100644 --- a/me/storage/MEPassthru.java +++ b/me/storage/MEPassthru.java @@ -12,6 +12,7 @@ import appeng.api.storage.data.IItemList; public class MEPassthru> implements IMEInventoryHandler { + Class clz; private IMEInventory internal; protected IMEInventory getInternal() @@ -19,8 +20,9 @@ public class MEPassthru> implements IMEInventoryHandler return internal; } - public MEPassthru(IMEInventory i) { + public MEPassthru(IMEInventory i,Class cla) { setInternal( i ); + clz = cla; } public void setInternal(IMEInventory i) diff --git a/me/storage/SecurityInventory.java b/me/storage/SecurityInventory.java index f3d907ea..bd4a1776 100644 --- a/me/storage/SecurityInventory.java +++ b/me/storage/SecurityInventory.java @@ -19,7 +19,7 @@ public class SecurityInventory implements IMEInventoryHandler { final TileSecurity securityTile; - final public IItemList storedItems = new ItemList(); + final public IItemList storedItems = new ItemList(IAEItemStack.class); public SecurityInventory(TileSecurity ts) { securityTile = ts; diff --git a/parts/automation/PartFormationPlane.java b/parts/automation/PartFormationPlane.java index c6466fef..37aa5b18 100644 --- a/parts/automation/PartFormationPlane.java +++ b/parts/automation/PartFormationPlane.java @@ -17,6 +17,7 @@ import net.minecraft.world.WorldServer; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; @@ -47,7 +48,6 @@ import appeng.me.storage.MEInventoryHandler; import appeng.tile.inventory.AppEngInternalAEInventory; import appeng.tile.inventory.InvOperation; import appeng.util.Platform; -import appeng.util.item.ItemList; import appeng.util.prioitylist.FuzzyPriorityList; import appeng.util.prioitylist.PrecisePriorityList; import cpw.mods.fml.relauncher.Side; @@ -59,7 +59,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine int priority = 0; boolean wasActive = false; boolean blocked = false; - MEInventoryHandler myHandler = new MEInventoryHandler( this ); + MEInventoryHandler myHandler = new MEInventoryHandler( this, IAEItemStack.class ); AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 ); public PartFormationPlane(ItemStack is) { @@ -271,7 +271,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine myHandler.myWhitelist = getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST; myHandler.myPriority = priority; - IItemList priorityList = new ItemList(); + IItemList priorityList = AEApi.instance().storage().createItemList(); int slotsToUse = 18 + getInstalledUpgrades( Upgrades.CAPACITY ) * 9; for (int x = 0; x < Config.getSizeInventory() && x < slotsToUse; x++) diff --git a/parts/misc/PartStorageBus.java b/parts/misc/PartStorageBus.java index 52ad0e78..2a40051e 100644 --- a/parts/misc/PartStorageBus.java +++ b/parts/misc/PartStorageBus.java @@ -49,7 +49,6 @@ import appeng.parts.automation.PartUpgradeable; import appeng.tile.inventory.AppEngInternalAEInventory; import appeng.tile.inventory.InvOperation; import appeng.util.Platform; -import appeng.util.item.ItemList; import appeng.util.prioitylist.FuzzyPriorityList; import appeng.util.prioitylist.PrecisePriorityList; import buildcraft.api.transport.IPipeConnection; @@ -216,13 +215,13 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC if ( inv != null ) { - handler = new MEInventoryHandler( inv ); + handler = new MEInventoryHandler( inv, IAEItemStack.class ); handler.myAccess = (AccessRestriction) this.getConfigManager().getSetting( Settings.ACCESS ); handler.myWhitelist = getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST; handler.myPriority = priority; - IItemList priorityList = new ItemList(); + IItemList priorityList = AEApi.instance().storage().createItemList(); int slotsToUse = 18 + getInstalledUpgrades( Upgrades.CAPACITY ) * 9; for (int x = 0; x < Config.getSizeInventory() && x < slotsToUse; x++) diff --git a/tile/storage/TileChest.java b/tile/storage/TileChest.java index fcfa1e00..f9757f95 100644 --- a/tile/storage/TileChest.java +++ b/tile/storage/TileChest.java @@ -336,7 +336,7 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan if ( h == null ) return null; - MEInventoryHandler ih = new MEInventoryHandler( h ); + MEInventoryHandler ih = new MEInventoryHandler( h, h.getChannel().type ); ih.myPriority = priority; MEMonitorHandler g = new ChestMonitorHandler( ih ); diff --git a/tile/storage/TileIOPort.java b/tile/storage/TileIOPort.java index bcfe6c4b..933e6cfd 100644 --- a/tile/storage/TileIOPort.java +++ b/tile/storage/TileIOPort.java @@ -301,7 +301,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC if ( src instanceof IMEMonitor ) myList = ((IMEMonitor) src).getStorageList(); else - myList = src.getAvailableItems( new ItemList() ); + myList = src.getAvailableItems( new ItemList( src.getChannel().type ) ); if ( fm == FullnessMode.EMPTY ) return myList.isEmpty(); @@ -340,7 +340,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC if ( src instanceof IMEMonitor ) myList = ((IMEMonitor) src).getStorageList(); else - myList = src.getAvailableItems( new ItemList() ); + myList = src.getAvailableItems( new ItemList( src.getChannel().type ) ); boolean didStuff; diff --git a/util/Platform.java b/util/Platform.java index 971b865c..6d4ed2db 100644 --- a/util/Platform.java +++ b/util/Platform.java @@ -1306,7 +1306,7 @@ public class Platform if ( myItems != null ) { - for (IAEItemStack is : myItems.getAvailableItems( new ItemList() )) + for (IAEItemStack is : myItems.getAvailableItems( AEApi.instance().storage().createItemList() )) { is.setStackSize( -is.getStackSize() ); gs.postAlterationOfStoredItems( StorageChannel.ITEMS, is, src ); @@ -1317,7 +1317,7 @@ public class Platform if ( myFluids != null ) { - for (IAEFluidStack is : myFluids.getAvailableItems( new ItemList() )) + for (IAEFluidStack is : myFluids.getAvailableItems( AEApi.instance().storage().createFluidList() )) { is.setStackSize( -is.getStackSize() ); gs.postAlterationOfStoredItems( StorageChannel.ITEMS, is, src ); @@ -1331,7 +1331,7 @@ public class Platform if ( myItems != null ) { - for (IAEItemStack is : myItems.getAvailableItems( new ItemList() )) + for (IAEItemStack is : myItems.getAvailableItems( new ItemList(IAEItemStack.class) )) { gs.postAlterationOfStoredItems( StorageChannel.ITEMS, is, src ); } @@ -1341,7 +1341,7 @@ public class Platform if ( myFluids != null ) { - for (IAEFluidStack is : myFluids.getAvailableItems( new ItemList() )) + for (IAEFluidStack is : myFluids.getAvailableItems( new ItemList(IAEFluidStack.class) )) { gs.postAlterationOfStoredItems( StorageChannel.ITEMS, is, src ); } diff --git a/util/item/ItemList.java b/util/item/ItemList.java index 85aa145e..dadcdb7a 100644 --- a/util/item/ItemList.java +++ b/util/item/ItemList.java @@ -1,5 +1,6 @@ package appeng.util.item; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; @@ -18,15 +19,32 @@ public final class ItemList implements IItemList records = new TreeMap(); + private final Class clz; + // private int currentPriority = Integer.MIN_VALUE; int iteration = Integer.MIN_VALUE; public Throwable stacktrace; + + public ItemList( Class cla) { + clz = cla; + } + private boolean checkStackType( StackType st ) + { + if ( st == null) + return true; + + if ( !clz.isInstance(st) ) + throw new RuntimeException("WRONG TYPE - got "+st.getClass().getName()+" expected "+clz.getName() ); + + return false; + } + @Override synchronized public void add(StackType option) { - if ( option == null ) + if ( checkStackType( option ) ) return; StackType st = records.get( option ); @@ -47,7 +65,7 @@ public final class ItemList implements IItemList implements IItemList implements IItemList implements IItemList implements IItemList findFuzzy(StackType filter, FuzzyMode fuzzy) { + if ( checkStackType( filter ) ) + return new ArrayList(); + if ( filter instanceof IAEFluidStack ) return filter.equals( this ) ? (List) Arrays.asList( new IAEFluidStack[] { (IAEFluidStack) filter } ) : (List) Arrays .asList( new IAEFluidStack[] {} );