Skip to content

Commit ab89fe2

Browse files
committed
migrade RS bridge as well
1 parent 22a6ed4 commit ab89fe2

14 files changed

Lines changed: 369 additions & 1030 deletions

File tree

src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AEApi.java

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import de.srendi.advancedperipherals.common.util.LuaConverter;
3636
import de.srendi.advancedperipherals.common.util.Pair;
3737
import de.srendi.advancedperipherals.common.util.StatusConstants;
38-
import de.srendi.advancedperipherals.common.util.inventory.ChemicalFilter;
3938
import de.srendi.advancedperipherals.common.util.inventory.FluidFilter;
4039
import de.srendi.advancedperipherals.common.util.inventory.FluidUtil;
4140
import de.srendi.advancedperipherals.common.util.inventory.GenericFilter;
@@ -48,7 +47,6 @@
4847
import me.ramidzkh.mekae2.ae2.MekanismKey;
4948
import me.ramidzkh.mekae2.ae2.MekanismKeyType;
5049
import me.ramidzkh.mekae2.item.ChemicalStorageCell;
51-
import mekanism.api.chemical.ChemicalStack;
5250
import mekanism.common.tile.TileEntityChemicalTank;
5351
import net.minecraft.core.BlockPos;
5452
import net.minecraft.world.item.ItemStack;
@@ -144,40 +142,6 @@ public static List<Pair<Long, AEFluidKey>> findAEFluidsFromFilter(MEStorage moni
144142
return fluids;
145143
}
146144

147-
@NotNull
148-
public static Pair<Long, MekanismKey> findAEChemicalFromStack(MEStorage monitor, @Nullable ICraftingService crafting, ChemicalStack stack) {
149-
return findAEChemicalFromFilter(monitor, crafting, ChemicalFilter.fromStack(stack));
150-
}
151-
152-
@NotNull
153-
public static Pair<Long, MekanismKey> findAEChemicalFromFilter(MEStorage monitor, @Nullable ICraftingService crafting, ChemicalFilter filter) {
154-
for (Object2LongMap.Entry<AEKey> temp : monitor.getAvailableStacks()) {
155-
if (temp.getKey() instanceof MekanismKey key && filter.test(key.getStack()))
156-
return Pair.of(temp.getLongValue(), key);
157-
}
158-
159-
if (crafting == null)
160-
return Pair.of(0L, null);
161-
162-
for (var temp : crafting.getCraftables(param -> true)) {
163-
if (temp instanceof MekanismKey key && filter.test(key.getStack()))
164-
return Pair.of(0L, key);
165-
}
166-
167-
return Pair.of(0L, null);
168-
}
169-
170-
@NotNull
171-
public static List<Pair<Long, MekanismKey>> findAEChemicalsFromFilter(MEStorage monitor, ChemicalFilter filter) {
172-
List<Pair<Long, MekanismKey>> chemicals = new ArrayList<>();
173-
for (Object2LongMap.Entry<AEKey> temp : monitor.getAvailableStacks()) {
174-
if (temp.getKey() instanceof MekanismKey key && filter.test(key.getStack())) {
175-
chemicals.add(Pair.of(temp.getLongValue(), key));
176-
}
177-
}
178-
return chemicals;
179-
}
180-
181145
/**
182146
* Finds a pattern from filters.
183147
*
@@ -266,16 +230,6 @@ public static List<Object> listFluids(MEStorage monitor, ICraftingService servic
266230
return items;
267231
}
268232

269-
public static List<Object> listChemicals(MEStorage monitor, ICraftingService service, ChemicalFilter filter) {
270-
List<Object> items = new ArrayList<>();
271-
for (Object2LongMap.Entry<AEKey> aeKey : monitor.getAvailableStacks()) {
272-
if (APAddon.APP_MEKANISTICS.isLoaded() && aeKey.getKey() instanceof MekanismKey mekanismKey && filter.test(mekanismKey.getStack())) {
273-
items.add(parseAeStack(Pair.of(aeKey.getLongValue(), mekanismKey), service));
274-
}
275-
}
276-
return items;
277-
}
278-
279233
public static List<Object> listCraftableFluids(MEStorage monitor, ICraftingService service, FluidFilter filter) {
280234
List<Object> items = new ArrayList<>();
281235
KeyCounter keyCounter = monitor.getAvailableStacks();
@@ -288,18 +242,6 @@ public static List<Object> listCraftableFluids(MEStorage monitor, ICraftingServi
288242
return items;
289243
}
290244

291-
public static List<Object> listCraftableChemicals(MEStorage monitor, ICraftingService service, ChemicalFilter filter) {
292-
List<Object> items = new ArrayList<>();
293-
KeyCounter keyCounter = monitor.getAvailableStacks();
294-
Set<AEKey> craftables = service.getCraftables(AEKeyFilter.none());
295-
for (AEKey aeKey : craftables) {
296-
if (aeKey instanceof MekanismKey mekanismKey && filter.test(mekanismKey.getStack())) {
297-
items.add(parseAeStack(Pair.of(keyCounter.get(aeKey), aeKey), service));
298-
}
299-
}
300-
return items;
301-
}
302-
303245
public static List<Pair<EncodedPatternItem<?>, IPatternDetails>> getPatterns(IGrid grid, Level level) {
304246
List<Pair<EncodedPatternItem<?>, IPatternDetails>> patterns = new ArrayList<>();
305247

@@ -358,7 +300,7 @@ public static <T extends AEKey> Map<String, Object> parseAeStack(Pair<Long, T> s
358300
if (stack.right() instanceof AEFluidKey fluidKey)
359301
return parseFluidStack(Pair.of(stack.left(), fluidKey), service);
360302
if (APAddon.APP_MEKANISTICS.isLoaded() && (stack.right() instanceof MekanismKey gasKey))
361-
return parseChemStack(Pair.of(stack.left(), gasKey), service);
303+
return AEMekanismApi.parseChemStack(Pair.of(stack.left(), gasKey), service);
362304

363305
AdvancedPeripherals.debug(org.apache.logging.log4j.Level.WARN, "Could not create table from unknown stack {} - Report this to the maintainer of ap", stack.right().getClass());
364306
return null;
@@ -458,12 +400,6 @@ private static Map<String, Object> parseFluidStack(Pair<Long, AEFluidKey> stack,
458400
return properties;
459401
}
460402

461-
private static Map<String, Object> parseChemStack(Pair<Long, MekanismKey> stack, @Nullable ICraftingService craftingService) {
462-
Map<String, Object> properties = LuaConverter.chemicalStackToLua(stack.right().withAmount(stack.left()));
463-
properties.put("isCraftable", craftingService != null && craftingService.isCraftable(stack.right()));
464-
return properties;
465-
}
466-
467403
public static Map<String, Object> parsePattern(Pair<EncodedPatternItem<?>, IPatternDetails> pattern) {
468404
Map<String, Object> properties = new HashMap<>();
469405
IPatternDetails patternDetails = pattern.right();
Lines changed: 61 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,79 @@
11
package de.srendi.advancedperipherals.common.addons.appliedenergistics;
22

3+
import appeng.api.networking.crafting.ICraftingService;
4+
import appeng.api.stacks.AEKey;
5+
import appeng.api.stacks.KeyCounter;
6+
import appeng.api.storage.AEKeyFilter;
37
import appeng.api.storage.MEStorage;
4-
import dan200.computercraft.api.lua.IArguments;
5-
import dan200.computercraft.api.lua.LuaException;
6-
import dan200.computercraft.api.lua.MethodResult;
7-
import dan200.computercraft.api.lua.ObjectLuaTable;
8-
import dan200.computercraft.api.peripheral.IComputerAccess;
9-
import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MEBridgePeripheral;
10-
import de.srendi.advancedperipherals.common.blocks.blockentities.MEBridgeEntity;
8+
import de.srendi.advancedperipherals.common.addons.APAddon;
9+
import de.srendi.advancedperipherals.common.util.LuaConverter;
1110
import de.srendi.advancedperipherals.common.util.Pair;
12-
import de.srendi.advancedperipherals.common.util.StatusConstants;
1311
import de.srendi.advancedperipherals.common.util.inventory.ChemicalFilter;
14-
import de.srendi.advancedperipherals.common.util.inventory.ChemicalUtil;
15-
import mekanism.api.chemical.IChemicalHandler;
12+
import it.unimi.dsi.fastutil.objects.Object2LongMap;
13+
import me.ramidzkh.mekae2.ae2.MekanismKey;
1614
import org.jetbrains.annotations.NotNull;
17-
18-
/**
19-
* Offloading mekanism related ME Bridge functions to prevent class loading errors at runtime
20-
*/
21-
public class AEMekanismApi {
22-
23-
/**
24-
* imports a fluid to the system from a valid tank
25-
*
26-
* @param arguments the arguments given by the computer
27-
* @param computer the computer connected to the peripheral - used for peripheral attached inventories
28-
* @param peripheral the ME Bridge peripheral
29-
* @return the imported amount or null with a string if something went wrong
30-
*/
31-
public static MethodResult importToME(@NotNull IArguments arguments, IComputerAccess computer, MEBridgePeripheral peripheral) throws LuaException {
32-
MEBridgeEntity bridge = peripheral.getBridge();
33-
MEStorage monitor = AEApi.getMonitor(bridge.getActionableNode());
34-
Pair<ChemicalFilter, String> filter = ChemicalFilter.parse(new ObjectLuaTable(arguments.getTable(0)));
35-
36-
if (filter.rightPresent())
37-
return MethodResult.of(0, filter.right());
38-
39-
String side = arguments.getString(1);
40-
IChemicalHandler targetTank = ChemicalUtil.getHandlerFromDirection(side, peripheral.getPeripheralOwner());
41-
42-
if (targetTank == null) {
43-
targetTank = ChemicalUtil.getHandlerFromName(computer, side);
15+
import org.jetbrains.annotations.Nullable;
16+
17+
import java.util.ArrayList;
18+
import java.util.List;
19+
import java.util.Map;
20+
import java.util.Set;
21+
22+
public final class AEMekanismApi {
23+
@NotNull
24+
public static Pair<Long, MekanismKey> findAEChemicalFromFilter(MEStorage monitor, @Nullable ICraftingService crafting, ChemicalFilter filter) {
25+
for (Object2LongMap.Entry<AEKey> temp : monitor.getAvailableStacks()) {
26+
if (temp.getKey() instanceof MekanismKey key && filter.test(key.getStack()))
27+
return Pair.of(temp.getLongValue(), key);
4428
}
4529

46-
if (targetTank == null)
47-
return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name());
30+
if (crafting == null)
31+
return Pair.of(0L, null);
4832

49-
MEChemicalHandler chemicalHandler = new MEChemicalHandler(monitor, bridge);
33+
for (var temp : crafting.getCraftables(param -> true)) {
34+
if (temp instanceof MekanismKey key && filter.test(key.getStack()))
35+
return Pair.of(0L, key);
36+
}
5037

51-
return MethodResult.of(ChemicalUtil.moveChemical(targetTank, chemicalHandler, filter.left()));
38+
return Pair.of(0L, null);
5239
}
5340

54-
/**
55-
* imports a fluid to the system from a valid tank
56-
*
57-
* @param arguments the arguments given by the computer
58-
* @param computer the computer connected to the peripheral - used for peripheral attached inventories
59-
* @param peripheral the ME Bridge peripheral
60-
* @return the exportable amount or null with a string if something went wrong
61-
*/
62-
public static MethodResult exportToTank(@NotNull IArguments arguments, IComputerAccess computer, MEBridgePeripheral peripheral) throws LuaException {
63-
MEBridgeEntity bridge = peripheral.getBridge();
64-
MEStorage monitor = AEApi.getMonitor(bridge.getActionableNode());
65-
Pair<ChemicalFilter, String> filter = ChemicalFilter.parse(new ObjectLuaTable(arguments.getTable(0)));
66-
67-
if (filter.rightPresent())
68-
return MethodResult.of(0, filter.right());
69-
70-
String side = arguments.getString(1);
71-
IChemicalHandler targetTank = ChemicalUtil.getHandlerFromDirection(side, peripheral.getPeripheralOwner());
72-
73-
if (targetTank == null) {
74-
targetTank = ChemicalUtil.getHandlerFromName(computer, side);
41+
@NotNull
42+
public static List<Pair<Long, MekanismKey>> findAEChemicalsFromFilter(MEStorage monitor, ChemicalFilter filter) {
43+
List<Pair<Long, MekanismKey>> chemicals = new ArrayList<>();
44+
for (Object2LongMap.Entry<AEKey> temp : monitor.getAvailableStacks()) {
45+
if (temp.getKey() instanceof MekanismKey key && filter.test(key.getStack())) {
46+
chemicals.add(Pair.of(temp.getLongValue(), key));
47+
}
7548
}
49+
return chemicals;
50+
}
7651

77-
if (targetTank == null)
78-
return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name());
79-
80-
MEChemicalHandler chemicalHandler = new MEChemicalHandler(monitor, bridge);
52+
public static List<Object> listChemicals(MEStorage monitor, ICraftingService service, ChemicalFilter filter) {
53+
List<Object> items = new ArrayList<>();
54+
for (Object2LongMap.Entry<AEKey> aeKey : monitor.getAvailableStacks()) {
55+
if (APAddon.APP_MEKANISTICS.isLoaded() && aeKey.getKey() instanceof MekanismKey mekanismKey && filter.test(mekanismKey.getStack())) {
56+
items.add(AEApi.parseAeStack(Pair.of(aeKey.getLongValue(), mekanismKey), service));
57+
}
58+
}
59+
return items;
60+
}
8161

82-
return MethodResult.of(ChemicalUtil.moveChemical(chemicalHandler, targetTank, filter.left()));
62+
public static List<Object> listCraftableChemicals(MEStorage monitor, ICraftingService service, ChemicalFilter filter) {
63+
List<Object> items = new ArrayList<>();
64+
KeyCounter keyCounter = monitor.getAvailableStacks();
65+
Set<AEKey> craftables = service.getCraftables(AEKeyFilter.none());
66+
for (AEKey aeKey : craftables) {
67+
if (aeKey instanceof MekanismKey mekanismKey && filter.test(mekanismKey.getStack())) {
68+
items.add(AEApi.parseAeStack(Pair.of(keyCounter.get(aeKey), aeKey), service));
69+
}
70+
}
71+
return items;
8372
}
8473

74+
public static Map<String, Object> parseChemStack(Pair<Long, MekanismKey> stack, @Nullable ICraftingService craftingService) {
75+
Map<String, Object> properties = LuaConverter.chemicalStackToLua(stack.right().withAmount(stack.left()));
76+
properties.put("isCraftable", craftingService != null && craftingService.isCraftable(stack.right()));
77+
return properties;
78+
}
8579
}

src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEChemicalHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ChemicalStack insertChemical(ChemicalStack resource, @NotNull Action acti
4747

4848
@Override
4949
public long extractChemicals(ChemicalFilter filter, StorageProcessor.Large<ChemicalStack> processor, Action action) {
50-
List<Pair<Long, MekanismKey>> chemicalKeys = AEApi.findAEChemicalsFromFilter(storageMonitor, filter);
50+
List<Pair<Long, MekanismKey>> chemicalKeys = AEMekanismApi.findAEChemicalsFromFilter(storageMonitor, filter);
5151
if (chemicalKeys.isEmpty()) {
5252
return 0;
5353
}

src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/AbstractStorageSystemPeripheral.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,14 @@
3939
* This ensures that these both bridges use the same methods. This makes it easier to support both in the same script
4040
* In case there is a new mod which adds new ways to store and craft items, this ensures that the new peripheral
4141
* has the same functions as the other ones
42+
*
43+
* @param <O> peripheral owner type
4244
*/
4345
public abstract class AbstractStorageSystemPeripheral<O extends IPeripheralOwner> extends BasePeripheral<O> {
44-
protected AbstractStorageSystemPeripheral(String type, @NotNull O owner) {
45-
super(type, owner);
46-
}
47-
4846
static final MethodResult NOT_CONNECTED_RESULT = MethodResult.of(null, StatusConstants.NOT_CONNECTED.toString());
4947

50-
public abstract boolean isAvailable();
51-
52-
@LuaFunction(mainThread = true)
53-
public final boolean isConnected() {
54-
return this.isAvailable();
55-
}
56-
57-
public abstract boolean isOnlineImpl();
58-
59-
@LuaFunction(mainThread = true)
60-
public final boolean isOnline() {
61-
if (!this.isAvailable()) {
62-
return false;
63-
}
64-
return this.isOnlineImpl();
48+
protected AbstractStorageSystemPeripheral(String type, @NotNull O owner) {
49+
super(type, owner);
6550
}
6651

6752
@Nullable
@@ -85,6 +70,23 @@ public MethodResult checkChemicalOperation() {
8570
@NotNull
8671
public abstract Object /*IChemicalHandler*/ getStorageSystemChemicalHandler();
8772

73+
public abstract boolean isAvailable();
74+
75+
@LuaFunction(mainThread = true)
76+
public final boolean isConnected() {
77+
return this.isAvailable();
78+
}
79+
80+
public abstract boolean isOnlineImpl();
81+
82+
@LuaFunction(mainThread = true)
83+
public final boolean isOnline() {
84+
if (!this.isAvailable()) {
85+
return false;
86+
}
87+
return this.isOnlineImpl();
88+
}
89+
8890
public abstract MethodResult getItemImpl(ItemFilter filter) throws LuaException;
8991

9092
@LuaFunction(mainThread = true)

0 commit comments

Comments
 (0)