diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index 0fedd7315..b52e6023a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -10,9 +10,10 @@ import appeng.api.storage.AEKeyFilter; import appeng.api.storage.IStorageProvider; import appeng.api.storage.MEStorage; +import appeng.api.storage.cells.IBasicCellItem; import appeng.blockentity.storage.DriveBlockEntity; -import appeng.items.storage.BasicStorageCell; import appeng.parts.storagebus.StorageBusPart; +import com.the9grounds.aeadditions.item.storage.StorageCell; import com.the9grounds.aeadditions.item.storage.SuperStorageCell; import dan200.computercraft.shared.util.NBTUtil; import de.srendi.advancedperipherals.AdvancedPeripherals; @@ -310,11 +311,11 @@ public static boolean isFluidCrafting(MEStorage monitor, ICraftingService grid, public static long getTotalItemStorage(IGridNode node) { long total = 0; - Iterator iterator = node.getGrid().getMachineNodes(DriveBlockEntity.class).iterator(); + // note: do not query DriveBlockEntity.class specifically here, because it will avoid subclasses, e.g. the ME Extended Drive from ExtendedAE + Iterator iterator = node.getGrid().getNodes().iterator(); while (iterator.hasNext()) { - DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); - if (entity == null) + if (!(iterator.next().getService(IStorageProvider.class) instanceof DriveBlockEntity entity)) continue; InternalInventory inventory = entity.getInternalInventory(); @@ -325,7 +326,7 @@ public static long getTotalItemStorage(IGridNode node) { if (stack.isEmpty()) continue; - if (stack.getItem() instanceof BasicStorageCell cell) { + if (stack.getItem() instanceof IBasicCellItem cell) { if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.items().getClass())) { total += cell.getBytes(null); } @@ -335,6 +336,10 @@ public static long getTotalItemStorage(IGridNode node) { } } else if (APAddons.aeAdditionsLoaded && (stack.getItem() instanceof SuperStorageCell superStorageCell)) { total += superStorageCell.getKiloBytes() * 1024L; + } else if (APAddons.aeAdditionsLoaded && (stack.getItem() instanceof StorageCell storageCell)) { + if (storageCell.getKeyType() != AEKeyType.items()) + continue; + total += storageCell.getKiloBytes() * 1024L; } } } @@ -362,11 +367,10 @@ public static long getTotalItemStorage(IGridNode node) { public static long getTotalFluidStorage(IGridNode node) { long total = 0; - Iterator iterator = node.getGrid().getMachineNodes(DriveBlockEntity.class).iterator(); + Iterator iterator = node.getGrid().getNodes().iterator(); while (iterator.hasNext()) { - DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); - if (entity == null) + if (!(iterator.next().getService(IStorageProvider.class) instanceof DriveBlockEntity entity)) continue; InternalInventory inventory = entity.getInternalInventory(); @@ -377,12 +381,16 @@ public static long getTotalFluidStorage(IGridNode node) { if (stack.isEmpty()) continue; - if (stack.getItem() instanceof BasicStorageCell cell) { + if (stack.getItem() instanceof IBasicCellItem cell) { if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.fluids().getClass())) { total += cell.getBytes(null); } } else if (APAddons.aeAdditionsLoaded && stack.getItem() instanceof SuperStorageCell superStorageCell) { total += superStorageCell.getKiloBytes() * 1024L; + } else if (APAddons.aeAdditionsLoaded && (stack.getItem() instanceof StorageCell storageCell)) { + if (storageCell.getKeyType() != AEKeyType.fluids()) + continue; + total += storageCell.getKiloBytes() * 1024L; } } } @@ -410,11 +418,10 @@ public static long getTotalFluidStorage(IGridNode node) { public static long getUsedItemStorage(IGridNode node) { long used = 0; - Iterator iterator = node.getGrid().getMachineNodes(DriveBlockEntity.class).iterator(); + Iterator iterator = node.getGrid().getNodes().iterator(); while (iterator.hasNext()) { - DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); - if (entity == null) + if (!(iterator.next().getService(IStorageProvider.class) instanceof DriveBlockEntity entity)) continue; InternalInventory inventory = entity.getInternalInventory(); @@ -425,7 +432,7 @@ public static long getUsedItemStorage(IGridNode node) { if (stack.isEmpty()) continue; - if (stack.getItem() instanceof BasicStorageCell cell) { + if (stack.getItem() instanceof IBasicCellItem cell) { int bytesPerType = cell.getBytesPerType(null); if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.items().getClass())) { @@ -448,6 +455,14 @@ public static long getUsedItemStorage(IGridNode node) { continue; long numItemsInCell = stack.getTag().getLong("ic"); + used += numItemsInCell; + } else if (APAddons.aeAdditionsLoaded && stack.getItem() instanceof StorageCell storageCell) { + if (storageCell.getKeyType() != AEKeyType.items()) + continue; + if (stack.getTag() == null) + continue; + long numItemsInCell = stack.getTag().getLong("ic"); + used += numItemsInCell; } } @@ -472,11 +487,10 @@ public static long getUsedItemStorage(IGridNode node) { public static long getUsedFluidStorage(IGridNode node) { long used = 0; - Iterator iterator = node.getGrid().getMachineNodes(DriveBlockEntity.class).iterator(); + Iterator iterator = node.getGrid().getNodes().iterator(); while (iterator.hasNext()) { - DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class); - if (entity == null) + if (!(iterator.next().getService(IStorageProvider.class) instanceof DriveBlockEntity entity)) continue; InternalInventory inventory = entity.getInternalInventory(); @@ -484,7 +498,7 @@ public static long getUsedFluidStorage(IGridNode node) { for (int i = 0; i < inventory.size(); i++) { ItemStack stack = inventory.getStackInSlot(i); - if (stack.getItem() instanceof BasicStorageCell cell) { + if (stack.getItem() instanceof IBasicCellItem cell) { int bytesPerType = cell.getBytesPerType(null); if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.fluids().getClass())) { @@ -495,7 +509,15 @@ public static long getUsedFluidStorage(IGridNode node) { used += ((int) Math.ceil(((double) numBucketsInCell) / 8)) + ((long) bytesPerType * numOfType); } - } else if (APAddons.aeAdditionsLoaded && stack.getItem() instanceof SuperStorageCell superStorageCell) { + } else if (APAddons.aeAdditionsLoaded && stack.getItem() instanceof SuperStorageCell) { + if (stack.getTag() == null) + continue; + long numItemsInCell = stack.getTag().getLong("ic"); + + used += numItemsInCell; + } else if (APAddons.aeAdditionsLoaded && stack.getItem() instanceof StorageCell storageCell) { + if (storageCell.getKeyType() != AEKeyType.fluids()) + continue; if (stack.getTag() == null) continue; long numItemsInCell = stack.getTag().getLong("ic"); @@ -548,7 +570,7 @@ public static List listCells(IGridNode node) { if (stack.isEmpty()) continue; - if (stack.getItem() instanceof BasicStorageCell cell) { + if (stack.getItem() instanceof IBasicCellItem cell) { items.add(getObjectFromCell(cell, stack)); } else if (APAddons.aeThingsLoaded && stack.getItem() instanceof DISKDrive disk) { items.add(getObjectFromDisk(disk, stack)); @@ -561,7 +583,7 @@ public static List listCells(IGridNode node) { return items; } - private static Map getObjectFromCell(BasicStorageCell cell, ItemStack stack) { + private static Map getObjectFromCell(IBasicCellItem cell, ItemStack stack) { Map map = new HashMap<>(); map.put("item", ItemUtil.getRegistryKey(stack.getItem()).toString());