1818import de .srendi .advancedperipherals .common .addons .APAddon ;
1919import de .srendi .advancedperipherals .common .addons .appliedenergistics .AEApi ;
2020import de .srendi .advancedperipherals .common .addons .appliedenergistics .AECraftJob ;
21- import de .srendi .advancedperipherals .common .addons .appliedenergistics .MEChemicalHandler ;
21+ import de .srendi .advancedperipherals .common .addons .appliedenergistics .AEMekanismApi ;
2222import de .srendi .advancedperipherals .common .addons .appliedenergistics .MEFluidHandler ;
2323import de .srendi .advancedperipherals .common .addons .appliedenergistics .MEItemHandler ;
2424import de .srendi .advancedperipherals .common .addons .computercraft .owner .BlockEntityPeripheralOwner ;
2727import de .srendi .advancedperipherals .common .util .Pair ;
2828import de .srendi .advancedperipherals .common .util .StatusConstants ;
2929import de .srendi .advancedperipherals .common .util .inventory .ChemicalFilter ;
30- import de .srendi .advancedperipherals .common .util .inventory .ChemicalUtil ;
3130import de .srendi .advancedperipherals .common .util .inventory .FluidFilter ;
3231import de .srendi .advancedperipherals .common .util .inventory .FluidUtil ;
3332import de .srendi .advancedperipherals .common .util .inventory .GenericFilter ;
3635import de .srendi .advancedperipherals .common .util .inventory .ItemFilter ;
3736import de .srendi .advancedperipherals .lib .peripherals .BasePeripheral ;
3837import me .ramidzkh .mekae2 .ae2 .MekanismKey ;
39- import mekanism .api .chemical .IChemicalHandler ;
4038import net .neoforged .neoforge .fluids .capability .IFluidHandler ;
4139import net .neoforged .neoforge .items .IItemHandler ;
4240import org .jetbrains .annotations .NotNull ;
@@ -73,6 +71,10 @@ private ICraftingService getCraftingService() {
7371 return node .getGrid ().getCraftingService ();
7472 }
7573
74+ public MEBridgeEntity getBridge () {
75+ return bridge ;
76+ }
77+
7678 /**
7779 * exports an item out of the system to a valid inventory
7880 *
@@ -109,23 +111,6 @@ protected MethodResult exportToTank(@NotNull IArguments arguments, IFluidHandler
109111 return MethodResult .of (FluidUtil .moveFluid (fluidHandler , targetTank , filter .getLeft ()), null );
110112 }
111113
112- /**
113- * exports a fluid out of the system to a valid tank
114- *
115- * @param arguments the arguments given by the computer
116- * @param targetTank the give tank
117- * @return the exportable amount or null with a string if something went wrong
118- */
119- protected MethodResult exportToTank (@ NotNull IArguments arguments , IChemicalHandler targetTank ) throws LuaException {
120- MEStorage monitor = AEApi .getMonitor (node );
121- MEChemicalHandler chemicalHandler = new MEChemicalHandler (monitor , bridge );
122- Pair <ChemicalFilter , String > filter = ChemicalFilter .parse (arguments .getTable (0 ));
123-
124- if (filter .rightPresent ())
125- return MethodResult .of (0 , filter .getRight ());
126-
127- return MethodResult .of (ChemicalUtil .moveChemical (chemicalHandler , targetTank , filter .getLeft ()));
128- }
129114
130115 /**
131116 * imports an item to the system from a valid inventory
@@ -163,24 +148,6 @@ protected MethodResult importToME(@NotNull IArguments arguments, IFluidHandler t
163148 return MethodResult .of (FluidUtil .moveFluid (targetTank , fluidHandler , filter .getLeft ()), null );
164149 }
165150
166- /**
167- * imports a fluid to the system from a valid tank
168- *
169- * @param arguments the arguments given by the computer
170- * @param targetTank the give tank
171- * @return the imported amount or null with a string if something went wrong
172- */
173- protected MethodResult importToME (@ NotNull IArguments arguments , IChemicalHandler targetTank ) throws LuaException {
174- MEStorage monitor = AEApi .getMonitor (node );
175- MEChemicalHandler chemicalHandler = new MEChemicalHandler (monitor , bridge );
176- Pair <ChemicalFilter , String > filter = ChemicalFilter .parse (arguments .getTable (0 ));
177-
178- if (filter .rightPresent ())
179- return MethodResult .of (0 , filter .getRight ());
180-
181- return MethodResult .of (ChemicalUtil .moveChemical (targetTank , chemicalHandler , filter .getLeft ()));
182- }
183-
184151 private MethodResult notConnected (@ Nullable Object defaultValue ) {
185152 return MethodResult .of (defaultValue , StatusConstants .NOT_CONNECTED .toString ());
186153 }
@@ -450,19 +417,9 @@ public MethodResult importChemical(IComputerAccess computer, IArguments argument
450417 return notConnected (0 );
451418
452419 if (!APAddon .APP_MEKANISTICS .isLoaded ())
453- return MethodResult .of (0 );
454-
455- String side = arguments .getString (1 );
456- IChemicalHandler chemicalHandler = ChemicalUtil .getHandlerFromDirection (side , owner );
457-
458- if (chemicalHandler == null ) {
459- chemicalHandler = ChemicalUtil .getHandlerFromName (computer , side );
460- }
461-
462- if (chemicalHandler == null )
463- return MethodResult .of (0 , StatusConstants .INVENTORY_NOT_FOUND .name ());
420+ return MethodResult .of (null , StatusConstants .ADDON_NOT_LOADED .withInfo (APAddon .APP_MEKANISTICS .name ()));
464421
465- return importToME (arguments , chemicalHandler );
422+ return AEMekanismApi . importToME (arguments , computer , this );
466423 }
467424
468425 @ Override
@@ -471,20 +428,10 @@ public MethodResult exportChemical(IComputerAccess computer, IArguments argument
471428 if (!isAvailable ())
472429 return notConnected (0 );
473430
474- if (APAddon .APP_MEKANISTICS .isLoaded ())
475- return MethodResult .of (0 );
476-
477- String side = arguments .getString (1 );
478- IChemicalHandler chemicalHandler = ChemicalUtil .getHandlerFromDirection (side , owner );
479-
480- if (chemicalHandler == null ) {
481- chemicalHandler = ChemicalUtil .getHandlerFromName (computer , side );
482- }
483-
484- if (chemicalHandler == null )
485- return MethodResult .of (0 , StatusConstants .INVENTORY_NOT_FOUND .name ());
431+ if (!APAddon .APP_MEKANISTICS .isLoaded ())
432+ return MethodResult .of (null , StatusConstants .ADDON_NOT_LOADED .withInfo (APAddon .APP_MEKANISTICS .name ()));
486433
487- return exportToTank (arguments , chemicalHandler );
434+ return AEMekanismApi . exportToTank (arguments , computer , this );
488435 }
489436
490437 @ Override
0 commit comments