@@ -223,11 +223,11 @@ public static List<Object> listPatterns(IGrid grid, Level level) {
223223 public static List <Object > listDrives (IGrid grid ) {
224224 List <Object > drives = new ArrayList <>();
225225
226- for (IGridNode node : grid .getMachineNodes (DriveBlockEntity .class )) {
226+ for (IGridNode node : grid .getMachineNodes (DriveBlockEntity .class )) {
227227 DriveBlockEntity drive = (DriveBlockEntity ) node .getService (IStorageProvider .class );
228228
229229 // A normal drive has a cellCount of 10
230- if (drive == null || drive .getCellCount () != 10 )
230+ if (drive == null || drive .getCellCount () != 10 )
231231 continue ;
232232
233233 drives .add (getObjectFromDrive (drive ));
@@ -237,9 +237,9 @@ public static List<Object> listDrives(IGrid grid) {
237237 }
238238
239239 private static Class <? extends PatternContainer > tryCastMachineToContainer (Class <?> machineClass ) {
240- if (PatternContainer .class .isAssignableFrom (machineClass )) {
240+ if (PatternContainer .class .isAssignableFrom (machineClass ))
241241 return machineClass .asSubclass (PatternContainer .class );
242- }
242+
243243 return null ;
244244 }
245245
@@ -262,16 +262,25 @@ public static Map<Object, Object> getObjectFromDrive(DriveBlockEntity drive) {
262262
263263 map .put ("powered" , drive .isPowered ());
264264
265- if (drive .getCellCount () != 10 )
265+ long totalBytes = 0 ;
266+ long usedBytes = 0 ;
267+
268+ if (drive .getCellCount () != 10 )
266269 return map ;
267270
268271 List <Object > driveCells = new ArrayList <>();
269272 for (ItemStack item : drive .getInternalInventory ()) {
270273 if (item .getItem () instanceof BasicStorageCell cell ) {
274+ BasicCellInventory cellInventory = BasicCellHandler .INSTANCE .getCellInventory (item , null );
275+ totalBytes += cellInventory .getTotalBytes ();
276+ usedBytes += cellInventory .getUsedBytes ();
277+
271278 driveCells .add (getObjectFromCell (cell , item ));
272279 }
273280 }
274281
282+ map .put ("usedBytes" , usedBytes );
283+ map .put ("totalBytes" , totalBytes );
275284 map .put ("cells" , driveCells );
276285 map .put ("priority" , drive .getPriority ());
277286 map .put ("menuIcon" , LuaConverter .itemToObject (drive .getMainMenuIcon ().getItem ()));
@@ -283,24 +292,13 @@ public static Map<Object, Object> getObjectFromDrive(DriveBlockEntity drive) {
283292
284293 public static Map <Object , Object > getObjectFromCell (BasicStorageCell cell , ItemStack cellItem ) {
285294 Map <Object , Object > map = new HashMap <>();
295+ BasicCellInventory cellInventory = BasicCellHandler .INSTANCE .getCellInventory (cellItem , null );
286296
287297 map .put ("item" , LuaConverter .itemToObject (cellItem .getItem ()));
288298 map .put ("type" , cell .getKeyType ().toString ());
289299 map .put ("bytes" , cell .getBytes (cellItem ));
290- long numItemsInCell = cellItem .getTag ().getLong ("ic" );
291-
292- if (cellItem .getTag ().contains ("amts" )) {
293- int bytesPerType = cell .getBytesPerType (null );
294-
295- int numOfType = cellItem .getTag ().getLongArray ("amts" ).length ;
296-
297- map .put ("bytesPerType" , bytesPerType );
298- map .put ("usedBytes" , ((int ) Math .ceil (((double ) numItemsInCell ) / 8 )) + ((long ) bytesPerType * numOfType ));
299-
300- } else {
301- map .put ("usedBytes" , numItemsInCell );
302- }
303-
300+ map .put ("bytesPerType" , cell .getBytesPerType (cellItem ));
301+ map .put ("usedBytes" , cellInventory .getUsedBytes ());
304302 map .put ("totalTypes" , cell .getTotalTypes (cellItem ));
305303 map .put ("fuzzyMode" , cell .getFuzzyMode (cellItem ));
306304
@@ -720,15 +718,10 @@ public static long getUsedItemStorage(IGridNode node) {
720718 continue ;
721719
722720 if (stack .getItem () instanceof BasicStorageCell cell ) {
723- int bytesPerType = cell .getBytesPerType (null );
724-
725721 if (cell .getKeyType ().getClass ().isAssignableFrom (AEKeyType .items ().getClass ())) {
726- if (stack .getTag () == null )
727- continue ;
728- int numOfType = stack .getTag ().getLongArray ("amts" ).length ;
729- long numItemsInCell = stack .getTag ().getLong ("ic" );
722+ BasicCellInventory cellInventory = BasicCellHandler .INSTANCE .getCellInventory (stack , null );
730723
731- used += (( int ) Math . ceil ((( double ) numItemsInCell ) / 8 )) + (( long ) bytesPerType * numOfType );
724+ used += cellInventory . getUsedBytes ( );
732725 }
733726 } else if (APAddons .aeThingsLoaded && stack .getItem () instanceof DISKDrive disk ) {
734727 if (disk .getKeyType ().toString ().equals ("ae2:i" )) {
@@ -764,15 +757,10 @@ public static long getUsedFluidStorage(IGridNode node) {
764757 ItemStack stack = inventory .getStackInSlot (i );
765758
766759 if (stack .getItem () instanceof BasicStorageCell cell ) {
767- int bytesPerType = cell .getBytesPerType (null );
768-
769760 if (cell .getKeyType ().getClass ().isAssignableFrom (AEKeyType .fluids ().getClass ())) {
770- if (stack .getTag () == null )
771- continue ;
772- int numOfType = stack .getTag ().getLongArray ("amts" ).length ;
773- long numBucketsInCell = stack .getTag ().getLong ("ic" ) / 1000 ;
761+ BasicCellInventory cellInventory = BasicCellHandler .INSTANCE .getCellInventory (stack , null );
774762
775- used += (( int ) Math . ceil ((( double ) numBucketsInCell ) / 8 )) + (( long ) bytesPerType * numOfType );
763+ used += cellInventory . getUsedBytes ( );
776764 }
777765 } else if (APAddons .aeAdditionsLoaded && stack .getItem () instanceof SuperStorageCell superStorageCell ) {
778766 if (stack .getTag () == null )
0 commit comments