3434import me .ramidzkh .mekae2 .ae2 .MekanismKey ;
3535import me .ramidzkh .mekae2 .ae2 .MekanismKeyType ;
3636import me .ramidzkh .mekae2 .item .ChemicalStorageCell ;
37+ import mekanism .api .chemical .merged .MergedChemicalTank ;
3738import mekanism .common .tile .TileEntityChemicalTank ;
3839import net .minecraft .core .BlockPos ;
3940import net .minecraft .nbt .CompoundTag ;
@@ -479,7 +480,8 @@ public static long getTotalExternalChemicalStorage(IGridNode node) {
479480 continue ;
480481
481482 if (connectedInventoryEntity instanceof TileEntityChemicalTank tank ) {
482- total += tank .getChemicalTank ().getTankFromCurrent (tank .getChemicalTank ().getCurrent ()).getCapacity ();
483+ MergedChemicalTank .Current current = tank .getChemicalTank ().getCurrent () == MergedChemicalTank .Current .EMPTY ? MergedChemicalTank .Current .GAS : tank .getChemicalTank ().getCurrent ();
484+ total += tank .getChemicalTank ().getTankFromCurrent (current ).getCapacity ();
483485 }
484486 }
485487
@@ -496,9 +498,8 @@ public static long getUsedExternalItemStorage(IGridNode node) {
496498 KeyCounter keyCounter = bus .getInternalHandler ().getAvailableStacks ();
497499
498500 for (Object2LongMap .Entry <AEKey > aeKey : keyCounter ) {
499- if (aeKey .getKey () instanceof AEItemKey ) {
501+ if (aeKey .getKey () instanceof AEItemKey )
500502 used += aeKey .getLongValue ();
501- }
502503 }
503504 }
504505
@@ -513,9 +514,8 @@ public static long getUsedExternalFluidStorage(IGridNode node) {
513514 KeyCounter keyCounter = bus .getInternalHandler ().getAvailableStacks ();
514515
515516 for (Object2LongMap .Entry <AEKey > aeKey : keyCounter ) {
516- if (aeKey .getKey () instanceof AEFluidKey ) {
517+ if (aeKey .getKey () instanceof AEFluidKey )
517518 used += aeKey .getLongValue ();
518- }
519519 }
520520 }
521521
@@ -525,14 +525,16 @@ public static long getUsedExternalFluidStorage(IGridNode node) {
525525 public static long getUsedExternalChemicalStorage (IGridNode node ) {
526526 long used = 0 ;
527527
528+ if (!APAddons .appMekLoaded )
529+ return 0 ;
530+
528531 for (IGridNode iGridNode : node .getGrid ().getMachineNodes (StorageBusPart .class )) {
529532 StorageBusPart bus = (StorageBusPart ) iGridNode .getService (IStorageProvider .class );
530533 KeyCounter keyCounter = bus .getInternalHandler ().getAvailableStacks ();
531534
532535 for (Object2LongMap .Entry <AEKey > aeKey : keyCounter ) {
533- if (aeKey .getKey () instanceof MekanismKey ) {
536+ if (aeKey .getKey () instanceof MekanismKey )
534537 used += aeKey .getLongValue ();
535- }
536538 }
537539 }
538540
@@ -571,9 +573,6 @@ public static long getTotalItemStorage(IGridNode node) {
571573 }
572574 }
573575 }
574-
575- total += getTotalExternalItemStorage (node );
576-
577576 return total ;
578577 }
579578
@@ -603,14 +602,15 @@ public static long getTotalFluidStorage(IGridNode node) {
603602 }
604603 }
605604
606- total += getTotalExternalFluidStorage (node );
607-
608605 return total ;
609606 }
610607
611608 public static long getTotalChemicalStorage (IGridNode node ) {
612609 long total = 0 ;
613610
611+ if (!APAddons .appMekLoaded )
612+ return 0 ;
613+
614614 for (IGridNode iGridNode : node .getGrid ().getMachineNodes (DriveBlockEntity .class )) {
615615 DriveBlockEntity entity = (DriveBlockEntity ) iGridNode .getService (IStorageProvider .class );
616616 if (entity == null )
@@ -626,14 +626,12 @@ public static long getTotalChemicalStorage(IGridNode node) {
626626
627627 if (stack .getItem () instanceof ChemicalStorageCell cell ) {
628628 if (cell .getKeyType () instanceof MekanismKeyType ) {
629- total += ( long ) cell .getBytes (null ) * MekanismKeyType . TYPE . getAmountPerByte ( );
629+ total += cell .getBytes (null );
630630 }
631631 }
632632 }
633633 }
634634
635- total += getTotalExternalChemicalStorage (node );
636-
637635 return total ;
638636 }
639637
@@ -683,8 +681,6 @@ public static long getUsedItemStorage(IGridNode node) {
683681 }
684682 }
685683
686- used += getUsedExternalItemStorage (node );
687-
688684 return used ;
689685 }
690686
@@ -722,14 +718,15 @@ public static long getUsedFluidStorage(IGridNode node) {
722718 }
723719 }
724720
725- used += getUsedExternalFluidStorage (node );
726-
727721 return used ;
728722 }
729723
730724 public static long getUsedChemicalStorage (IGridNode node ) {
731725 long used = 0 ;
732726
727+ if (!APAddons .appMekLoaded )
728+ return 0 ;
729+
733730 for (IGridNode iGridNode : node .getGrid ().getMachineNodes (DriveBlockEntity .class )) {
734731 DriveBlockEntity entity = (DriveBlockEntity ) iGridNode .getService (IStorageProvider .class );
735732 if (entity == null )
@@ -748,8 +745,6 @@ public static long getUsedChemicalStorage(IGridNode node) {
748745 }
749746 }
750747
751- used += getUsedExternalChemicalStorage (node );
752-
753748 return used ;
754749 }
755750
0 commit comments