Skip to content

Commit

Permalink
Merge pull request #491 from michele-grifa/1.19.2
Browse files Browse the repository at this point in the history
Added support to Storage Bus in calculation of used storage space.
  • Loading branch information
SirEndii authored Jul 19, 2023
2 parents 15186b7 + 49ebb4d commit a4c3373
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand Down Expand Up @@ -328,7 +329,6 @@ public static long getUsedItemStorage(IGridNode node) {

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;
Expand All @@ -354,6 +354,19 @@ public static long getUsedItemStorage(IGridNode node) {
}
}

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;
}

Expand All @@ -362,7 +375,6 @@ public static long getUsedFluidStorage(IGridNode node) {

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;
Expand Down Expand Up @@ -392,6 +404,19 @@ public static long getUsedFluidStorage(IGridNode node) {
}
}

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;
}

Expand Down

0 comments on commit a4c3373

Please sign in to comment.