3939import org .jetbrains .annotations .Nullable ;
4040
4141import java .util .ArrayList ;
42+ import java .util .Collections ;
4243import java .util .List ;
4344import java .util .Locale ;
4445import java .util .Map ;
@@ -216,7 +217,7 @@ public MethodResult getChemical(IArguments arguments) throws LuaException {
216217
217218 @ Override
218219 @ LuaFunction (mainThread = true )
219- public final MethodResult listItems () {
220+ public final MethodResult listItems (IArguments arguments ) {
220221 if (!isAvailable ())
221222 return notConnected ();
222223
@@ -225,21 +226,21 @@ public final MethodResult listItems() {
225226
226227 @ Override
227228 @ LuaFunction (mainThread = true )
228- public final MethodResult listFluids () {
229+ public final MethodResult listFluids (IArguments arguments ) {
229230 if (!isAvailable ())
230231 return notConnected ();
231232
232233 return MethodResult .of (AppEngApi .listFluids (AppEngApi .getMonitor (node ), getCraftingService ()));
233234 }
234235
235236 @ Override
236- public MethodResult listChemicals () {
237+ public MethodResult listChemicals (IArguments arguments ) {
237238 return null ;
238239 }
239240
240241 @ Override
241242 @ LuaFunction (mainThread = true )
242- public final MethodResult listCraftableItems () {
243+ public final MethodResult listCraftableItems (IArguments arguments ) {
243244 if (!isAvailable ())
244245 return notConnected ();
245246
@@ -248,15 +249,15 @@ public final MethodResult listCraftableItems() {
248249
249250 @ Override
250251 @ LuaFunction (mainThread = true )
251- public final MethodResult listCraftableFluids () {
252+ public final MethodResult listCraftableFluids (IArguments arguments ) {
252253 if (!isAvailable ())
253254 return notConnected ();
254255
255256 return MethodResult .of (AppEngApi .listCraftableFluids (AppEngApi .getMonitor (node ), getCraftingService ()));
256257 }
257258
258259 @ Override
259- public MethodResult listCraftableChemicals () {
260+ public MethodResult listCraftableChemicals (IArguments arguments ) {
260261 return null ;
261262 }
262263
@@ -316,19 +317,14 @@ public final MethodResult exportItem(IComputerAccess computer, @NotNull IArgumen
316317
317318 @ Override
318319 @ LuaFunction (mainThread = true )
319- public MethodResult getFilteredPatterns (IArguments arguments ) throws LuaException {
320+ public MethodResult getPatterns (IArguments arguments ) throws LuaException {
320321 if (!isAvailable ())
321322 return notConnected ();
322323
323324 // Expected input is a table with either an input table, an output table or both to filter for both
324- Map <?, ?> filterTable ;
325- try {
326- Optional <Map <?, ?>> optionalTable = arguments .optTable (0 );
327- if (optionalTable .isEmpty ())
328- return MethodResult .of (null , "EMPTY_INPUT" );
329- filterTable = optionalTable .get ();
330- } catch (LuaException e ) {
331- return MethodResult .of (null , "NO_TABLE" );
325+ Map <?, ?> filterTable = arguments .optTable (0 , Collections .emptyMap ());
326+ if (filterTable .isEmpty ()) {
327+ return MethodResult .of (AppEngApi .getPatterns (node .getGrid (), getLevel ()));
332328 }
333329
334330 boolean hasInputFilter = filterTable .containsKey ("input" );
@@ -361,15 +357,6 @@ public MethodResult getFilteredPatterns(IArguments arguments) throws LuaExceptio
361357 return MethodResult .of (AppEngApi .parsePattern (pattern .getLeft ()));
362358 }
363359
364- @ Override
365- @ LuaFunction (mainThread = true )
366- public MethodResult getPatterns () {
367- if (!isAvailable ())
368- return notConnected ();
369-
370- return MethodResult .of (AppEngApi .listPatterns (node .getGrid (), getLevel ()));
371- }
372-
373360 @ Override
374361 @ LuaFunction (mainThread = true )
375362 public final MethodResult getStoredEnergy () {
@@ -634,7 +621,7 @@ public MethodResult craftChemical(IComputerAccess computer, IArguments arguments
634621
635622 @ Override
636623 @ LuaFunction (mainThread = true )
637- public MethodResult getCraftingJobs () {
624+ public MethodResult getCraftingTasks () {
638625 if (!isAvailable ())
639626 return notConnected ();
640627
@@ -653,7 +640,7 @@ public MethodResult getCraftingJobs() {
653640
654641 @ Override
655642 @ LuaFunction (mainThread = true )
656- public MethodResult getCraftingJob (int id ) {
643+ public MethodResult getCraftingTask (int id ) {
657644 if (!isAvailable ())
658645 return notConnected ();
659646
@@ -669,7 +656,7 @@ public MethodResult getCraftingJob(int id) {
669656
670657 @ Override
671658 @ LuaFunction (mainThread = true )
672- public MethodResult cancelCraftingJobs (IArguments arguments ) {
659+ public MethodResult cancelCraftingTasks (IArguments arguments ) {
673660 if (!isAvailable ())
674661 return notConnected ();
675662
@@ -685,7 +672,7 @@ public MethodResult cancelCraftingJobs(IArguments arguments) {
685672 return MethodResult .of (null , "NO_TABLE" );
686673 }
687674
688- Pair <? extends GenericFilter , String > filter = GenericFilter .parseGeneric (filterTable );
675+ Pair <? extends GenericFilter <?> , String > filter = GenericFilter .parseGeneric (filterTable );
689676 if (filter .getRight () != null )
690677 return MethodResult .of (null , filter .getRight ());
691678
@@ -703,72 +690,19 @@ public MethodResult cancelCraftingJobs(IArguments arguments) {
703690
704691 @ Override
705692 @ LuaFunction (mainThread = true )
706- public final MethodResult isItemCraftable (IArguments arguments ) throws LuaException {
693+ public final MethodResult isCraftable (IArguments arguments ) throws LuaException {
707694 if (!isAvailable ())
708695 return notConnected ();
709696
710- Pair <ItemFilter , String > filter = ItemFilter .parse (arguments .getTable (0 ));
711- if (filter .rightPresent ())
712- return MethodResult .of (false , filter .getRight ());
713-
714- ItemFilter parsedFilter = filter .getLeft ();
715- if (parsedFilter .isEmpty ())
716- return MethodResult .of (false , "EMPTY_FILTER" );
717-
718- AEItemKey item = AEItemKey .of (parsedFilter .toItemStack ());
719-
720- return MethodResult .of (getCraftingService ().isCraftable (item ));
721- }
722-
723- @ Override
724- @ LuaFunction (mainThread = true )
725- public final MethodResult isFluidCrafting (IArguments arguments ) throws LuaException {
726- if (!isAvailable ())
727- return notConnected ();
728-
729- MEStorage monitor = AppEngApi .getMonitor (node );
730- ICraftingService grid = node .getGrid ().getService (ICraftingService .class );
731-
732- Pair <FluidFilter , String > filter = FluidFilter .parse (arguments .getTable (0 ));
733- if (filter .rightPresent ())
734- return MethodResult .of (false , filter .getRight ());
735-
736- FluidFilter parsedFilter = filter .getLeft ();
737- if (parsedFilter .isEmpty ())
738- return MethodResult .of (false , "EMPTY_FILTER" );
739- String cpuName = arguments .optString (1 , "" );
740- ICraftingCPU craftingCPU = AppEngApi .getCraftingCPU (node , cpuName );
741-
742- return MethodResult .of (AppEngApi .isFluidCrafting (monitor , grid , parsedFilter , craftingCPU ));
743- }
744-
745- @ Override
746- public MethodResult isChemicalCraftable (IArguments arguments ) throws LuaException {
747- return null ;
748- }
749-
750- @ Override
751- public MethodResult isChemicalCrafting (IArguments arguments ) throws LuaException {
752- return null ;
753- }
754-
755- @ Override
756- @ LuaFunction (mainThread = true )
757- public final MethodResult isFluidCraftable (IArguments arguments ) throws LuaException {
758- if (!isAvailable ())
759- return notConnected ();
760-
761- Pair <FluidFilter , String > filter = FluidFilter .parse (arguments .getTable (0 ));
762- if (filter .rightPresent ())
763- return MethodResult .of (false , filter .getRight ());
697+ Pair <? extends GenericFilter <?>, String > filter = GenericFilter .parseGeneric (arguments .getTable (0 ));
698+ if (filter .getRight () != null )
699+ return MethodResult .of (null , filter .getRight ());
764700
765- FluidFilter parsedFilter = filter .getLeft ();
701+ GenericFilter <?> parsedFilter = filter .getLeft ();
766702 if (parsedFilter .isEmpty ())
767703 return MethodResult .of (false , "EMPTY_FILTER" );
768704
769- AEFluidKey fluid = AEFluidKey .of (parsedFilter .toFluidStack ());
770-
771- return MethodResult .of (getCraftingService ().isCraftable (fluid ));
705+ return MethodResult .of (AppEngApi .findPatternFromFilters (node .getGrid (), getLevel (), null , parsedFilter ).getLeft () != null );
772706 }
773707
774708 @ Override
@@ -795,7 +729,7 @@ public MethodResult importChemical(IComputerAccess computer, IArguments argument
795729 }
796730
797731 @ Override
798- public MethodResult exportchemical (IComputerAccess computer , IArguments arguments ) throws LuaException {
732+ public MethodResult exportChemical (IComputerAccess computer , IArguments arguments ) throws LuaException {
799733 return null ;
800734 }
801735
@@ -819,24 +753,25 @@ public final MethodResult importFluid(IComputerAccess computer, IArguments argum
819753
820754 @ Override
821755 @ LuaFunction (mainThread = true )
822- public final MethodResult isItemCrafting (IArguments arguments ) throws LuaException {
756+ public final MethodResult isCrafting (IArguments arguments ) throws LuaException {
823757 if (!isAvailable ())
824758 return notConnected ();
825759
826760 MEStorage monitor = AppEngApi .getMonitor (node );
827761 ICraftingService grid = node .getGrid ().getService (ICraftingService .class );
828762
829- Pair <ItemFilter , String > filter = ItemFilter . parse (arguments .getTable (0 ));
830- if (filter .rightPresent () )
831- return MethodResult .of (false , filter .getRight ());
763+ Pair <? extends GenericFilter <?> , String > filter = GenericFilter . parseGeneric (arguments .getTable (0 ));
764+ if (filter .getRight () != null )
765+ return MethodResult .of (null , filter .getRight ());
832766
833- ItemFilter parsedFilter = filter .getLeft ();
767+ GenericFilter <?> parsedFilter = filter .getLeft ();
834768 if (parsedFilter .isEmpty ())
835769 return MethodResult .of (false , "EMPTY_FILTER" );
770+
836771 String cpuName = arguments .optString (1 , "" );
837772 ICraftingCPU craftingCPU = AppEngApi .getCraftingCPU (node , cpuName );
838773
839- return MethodResult .of (AppEngApi .isItemCrafting (monitor , grid , parsedFilter , craftingCPU ));
774+ return MethodResult .of (AppEngApi .isCrafting (monitor , grid , parsedFilter , craftingCPU ));
840775 }
841776
842777 @ LuaFunction (mainThread = true )
0 commit comments