@@ -220,6 +220,22 @@ public static List<Object> listPatterns(IGrid grid, Level level) {
220220 return getPatterns (grid , level ).stream ().map (AppEngApi ::getObjectFromPattern ).collect (Collectors .toList ());
221221 }
222222
223+ public static List <Object > listDrives (IGrid grid ) {
224+ List <Object > drives = new ArrayList <>();
225+
226+ for (IGridNode node : grid .getMachineNodes (DriveBlockEntity .class )) {
227+ DriveBlockEntity drive = (DriveBlockEntity ) node .getService (IStorageProvider .class );
228+
229+ // A normal drive has a cellCount of 10
230+ if (drive == null || drive .getCellCount () != 10 )
231+ continue ;
232+
233+ drives .add (getObjectFromDrive (drive ));
234+ }
235+
236+ return drives ;
237+ }
238+
223239 private static Class <? extends PatternContainer > tryCastMachineToContainer (Class <?> machineClass ) {
224240 if (PatternContainer .class .isAssignableFrom (machineClass )) {
225241 return machineClass .asSubclass (PatternContainer .class );
@@ -241,6 +257,56 @@ public static <T extends AEKey> Map<String, Object> getObjectFromStack(Pair<Long
241257 return Collections .emptyMap ();
242258 }
243259
260+ public static Map <Object , Object > getObjectFromDrive (DriveBlockEntity drive ) {
261+ Map <Object , Object > map = new HashMap <>();
262+
263+ map .put ("powered" , drive .isPowered ());
264+
265+ if (drive .getCellCount () != 10 )
266+ return map ;
267+
268+ List <Object > driveCells = new ArrayList <>();
269+ for (ItemStack item : drive .getInternalInventory ()) {
270+ if (item .getItem () instanceof BasicStorageCell cell ) {
271+ driveCells .add (getObjectFromCell (cell , item ));
272+ }
273+ }
274+
275+ map .put ("cells" , driveCells );
276+ map .put ("priority" , drive .getPriority ());
277+ map .put ("menuIcon" , LuaConverter .itemToObject (drive .getMainMenuIcon ().getItem ()));
278+ map .put ("position" , LuaConverter .posToObject (drive .getBlockPos ()));
279+ map .put ("name" , drive .getCustomInventoryName ().getString ());
280+
281+ return map ;
282+ }
283+
284+ public static Map <Object , Object > getObjectFromCell (BasicStorageCell cell , ItemStack cellItem ) {
285+ Map <Object , Object > map = new HashMap <>();
286+
287+ map .put ("item" , LuaConverter .itemToObject (cellItem .getItem ()));
288+ map .put ("type" , cell .getKeyType ().toString ());
289+ 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+
304+ map .put ("totalTypes" , cell .getTotalTypes (cellItem ));
305+ map .put ("fuzzyMode" , cell .getFuzzyMode (cellItem ));
306+
307+ return map ;
308+ }
309+
244310 private static Map <String , Object > getObjectFromItemStack (Pair <Long , AEItemKey > stack , @ Nullable ICraftingService craftingService ) {
245311 Map <String , Object > map = new HashMap <>();
246312 String displayName = stack .getRight ().getDisplayName ().getString ();
@@ -832,26 +898,6 @@ public static List<Object> listCells(IGridNode node) {
832898 return items ;
833899 }
834900
835- private static Map <String , Object > getObjectFromCell (BasicStorageCell cell , ItemStack stack ) {
836- Map <String , Object > map = new HashMap <>();
837-
838- map .put ("item" , ItemUtil .getRegistryKey (stack .getItem ()).toString ());
839-
840- String cellType = "" ;
841-
842- if (cell .getKeyType ().getClass ().isAssignableFrom (AEKeyType .items ().getClass ())) {
843- cellType = "item" ;
844- } else if (cell .getKeyType ().getClass ().isAssignableFrom (AEKeyType .fluids ().getClass ())) {
845- cellType = "fluid" ;
846- }
847-
848- map .put ("cellType" , cellType );
849- map .put ("bytesPerType" , cell .getBytesPerType (null ));
850- map .put ("totalBytes" , cell .getBytes (null ));
851-
852- return map ;
853- }
854-
855901 private static Map <String , Object > getObjectFromDisk (DISKDrive drive , ItemStack stack ) {
856902 Map <String , Object > map = new HashMap <>();
857903
0 commit comments