Repository: sirendii/advancedperipherals
Issue: ME Bridge inconsistencies

### Describe

_[I don't know why the modpack author of my pack used the 1.19.3 version for a 1.19.2 pack but it works either way.]_
_{If I'm being stupid for any reason, (didnt see something in changelogs, shouldnt do 2 bugs in one post, etc.), please let me know.]_

While trying to write a program to push a live item counter to a Display Link, I encountered one bug and one potentially intended thing that might be a bug.

- getUsedItemStorage() does not account for items held within AE2 Things DISK Drives, it counts as zero.
- Any get[x]ItemStorage() does not account for items stored externally. (might be intended idk?)

### Steps to reproduce

Bug 1:

1. Have an ME system with a drive containing a DISK Drive
2. Attach an ME Bridge and computer
3. Insert items
4. Call getUsedItemStorage()
5. Returns zero.

Bug? 2:

1. Have an ME system with no drives and a storage bus on an inventory
2. Attach an ME bridge and computer
3. Insert items
4. Call any get[x]ItemStorage()
5. Returns zero.

### Multiplayer?

Yes

### Version

1.19.3-0.7.29r (Latest 1.19.3)

### Minecraft, Forge and maybe other related mods versions

Forge 43.2.14, Minecraft 1.19.2, AE2Things 1.1.1

### Screenshots or Videos

_No response_

### Crashlog/log

_No response_

Changed files:
src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java

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 d8a5a109..f87485fb 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
@@ -12,6 +12,7 @@ import appeng.api.storage.IStorageProvider;
 import appeng.api.storage.MEStorage;
 import appeng.blockentity.storage.DriveBlockEntity;
 import appeng.items.storage.BasicStorageCell;
+import appeng.parts.storagebus.StorageBusPart;
 import dan200.computercraft.shared.util.NBTUtil;
 import de.srendi.advancedperipherals.AdvancedPeripherals;
 import de.srendi.advancedperipherals.common.addons.APAddons;
@@ -328,7 +329,6 @@ public class AppEngApi {
 
         Iterator<IGridNode> iterator = node.getGrid().getMachineNodes(DriveBlockEntity.class).iterator();
 
-        if (!iterator.hasNext()) return 0;
         while (iterator.hasNext()) {
             DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class);
             if (entity == null) continue;
@@ -354,6 +354,19 @@ public class AppEngApi {
             }
         }
 
+        iterator = node.getGrid().getMachineNodes(StorageBusPart.class).iterator();
+
+        while (iterator.hasNext()) {
+            StorageBusPart bus = (StorageBusPart) iterator.next().getService(IStorageProvider.class);
+            KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks();
+
+            for (Object2LongMap.Entry<AEKey> aeKey : keyCounter) {
+                if (aeKey.getKey() instanceof AEItemKey itemKey) {
+                    used += aeKey.getLongValue();
+                }
+            }
+        }
+
         return used;
     }
 
@@ -362,7 +375,6 @@ public class AppEngApi {
 
         Iterator<IGridNode> iterator = node.getGrid().getMachineNodes(DriveBlockEntity.class).iterator();
 
-        if (!iterator.hasNext()) return 0;
         while (iterator.hasNext()) {
             DriveBlockEntity entity = (DriveBlockEntity) iterator.next().getService(IStorageProvider.class);
             if (entity == null) continue;
@@ -392,6 +404,19 @@ public class AppEngApi {
             }
         }
 
+        iterator = node.getGrid().getMachineNodes(StorageBusPart.class).iterator();
+
+        while (iterator.hasNext()) {
+            StorageBusPart bus = (StorageBusPart) iterator.next().getService(IStorageProvider.class);
+            KeyCounter keyCounter = bus.getInternalHandler().getAvailableStacks();
+
+            for (Object2LongMap.Entry<AEKey> aeKey : keyCounter) {
+                if (aeKey.getKey() instanceof AEFluidKey fluidKey) {
+                    used += aeKey.getLongValue();
+                }
+            }
+        }
+
         return used;
     }