Skip to content

Commit d7b5051

Browse files
committed
Move any mekanism related functions to dedicated classes to prevent class loading errors in runtime
Updated gradle
1 parent 146e03b commit d7b5051

11 files changed

Lines changed: 214 additions & 146 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99

10+
## [1.21.1-0.7.50b] - 2025-06-10
11+
1012
The new ME and RS Bridge system are more or less final, but expect any last-minute changes before the final release. We will listen for any feedback and try to improve the system as much as we can!
1113
If there are any inconsistencies or bugs, please report them at our github!
1214

build.gradle

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,26 +225,31 @@ dependencies {
225225
// Minimal requirements end
226226

227227
compileOnly("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorage_version}")
228-
runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorage_version}")
228+
runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorage_version}") {
229+
transitive = false
230+
}
229231

232+
// Transitive prevents that this dependency would load other dependencies which are used by refined storage and are faulty marked
230233
compileOnly("com.refinedmods.refinedstorage:refinedstorage-mekanism-integration:${refinedstorage_mekanism_version}")
231-
runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-mekanism-integration:${refinedstorage_mekanism_version}")
234+
runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-mekanism-integration:${refinedstorage_mekanism_version}") {
235+
transitive = false
236+
}
232237

233238
// Needed for the refined storage mek integration
234-
compileOnlyApi("dev.emi:emi-neoforge:${emiVersion}")
239+
//compileOnlyApi("dev.emi:emi-neoforge:${emiVersion}")
235240

236241
// Extended requirements
237242
// We don't use the api since we need a specific class from mekanism
238243
compileOnly "mekanism:Mekanism:${mekanism_version}"
239-
//runtimeOnly "mekanism:Mekanism:${mekanism_version}"
244+
runtimeOnly "mekanism:Mekanism:${mekanism_version}"
240245

241246
// Applied Energistics 2
242247
compileOnly "org.appliedenergistics:appliedenergistics2:${appliedenergistics_version}"
243248
runtimeOnly "org.appliedenergistics:appliedenergistics2:${appliedenergistics_version}"
244249

245250
// Applied Mekanistics
246251
compileOnly "curse.maven:applied-mekanistics-574300:${appliedmekanistics_version}"
247-
//runtimeOnly "curse.maven:applied-mekanistics-574300:${appliedmekanistics_version}"
252+
runtimeOnly "curse.maven:applied-mekanistics-574300:${appliedmekanistics_version}"
248253

249254
// AE2 Things
250255
compileOnly "curse.maven:ae2things-609977:${ae2things_version}-sources"

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package de.srendi.advancedperipherals.common.addons.appliedenergistics;
2+
3+
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.peripheral.IComputerAccess;
8+
import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MEBridgePeripheral;
9+
import de.srendi.advancedperipherals.common.blocks.blockentities.MEBridgeEntity;
10+
import de.srendi.advancedperipherals.common.util.Pair;
11+
import de.srendi.advancedperipherals.common.util.StatusConstants;
12+
import de.srendi.advancedperipherals.common.util.inventory.ChemicalFilter;
13+
import de.srendi.advancedperipherals.common.util.inventory.ChemicalUtil;
14+
import mekanism.api.chemical.IChemicalHandler;
15+
import org.jetbrains.annotations.NotNull;
16+
17+
/**
18+
* Offloading mekanism related ME Bridge functions to prevent class loading errors at runtime
19+
*/
20+
public class AEMekanismApi {
21+
22+
/**
23+
* imports a fluid to the system from a valid tank
24+
*
25+
* @param arguments the arguments given by the computer
26+
* @param computer the computer connected to the peripheral - used for peripheral attached inventories
27+
* @param peripheral the ME Bridge peripheral
28+
* @return the imported amount or null with a string if something went wrong
29+
*/
30+
public static MethodResult importToME(@NotNull IArguments arguments, IComputerAccess computer, MEBridgePeripheral peripheral) throws LuaException {
31+
MEBridgeEntity bridge = peripheral.getBridge();
32+
MEStorage monitor = AEApi.getMonitor(bridge.getActionableNode());
33+
Pair<ChemicalFilter, String> filter = ChemicalFilter.parse(arguments.getTable(0));
34+
35+
if (filter.rightPresent())
36+
return MethodResult.of(0, filter.getRight());
37+
38+
String side = arguments.getString(1);
39+
IChemicalHandler targetTank = ChemicalUtil.getHandlerFromDirection(side, peripheral.getPeripheralOwner());
40+
41+
if (targetTank == null) {
42+
targetTank = ChemicalUtil.getHandlerFromName(computer, side);
43+
}
44+
45+
if (targetTank == null)
46+
return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name());
47+
48+
MEChemicalHandler chemicalHandler = new MEChemicalHandler(monitor, bridge);
49+
50+
return MethodResult.of(ChemicalUtil.moveChemical(targetTank, chemicalHandler, filter.getLeft()));
51+
}
52+
53+
/**
54+
* imports a fluid to the system from a valid tank
55+
*
56+
* @param arguments the arguments given by the computer
57+
* @param computer the computer connected to the peripheral - used for peripheral attached inventories
58+
* @param peripheral the ME Bridge peripheral
59+
* @return the exportable amount or null with a string if something went wrong
60+
*/
61+
public static MethodResult exportToTank(@NotNull IArguments arguments, IComputerAccess computer, MEBridgePeripheral peripheral) throws LuaException {
62+
MEBridgeEntity bridge = peripheral.getBridge();
63+
MEStorage monitor = AEApi.getMonitor(bridge.getActionableNode());
64+
Pair<ChemicalFilter, String> filter = ChemicalFilter.parse(arguments.getTable(0));
65+
66+
if (filter.rightPresent())
67+
return MethodResult.of(0, filter.getRight());
68+
69+
String side = arguments.getString(1);
70+
IChemicalHandler targetTank = ChemicalUtil.getHandlerFromDirection(side, peripheral.getPeripheralOwner());
71+
72+
if (targetTank == null) {
73+
targetTank = ChemicalUtil.getHandlerFromName(computer, side);
74+
}
75+
76+
if (targetTank == null)
77+
return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name());
78+
79+
MEChemicalHandler chemicalHandler = new MEChemicalHandler(monitor, bridge);
80+
81+
return MethodResult.of(ChemicalUtil.moveChemical(chemicalHandler, targetTank, filter.getLeft()));
82+
}
83+
84+
}

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

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import de.srendi.advancedperipherals.common.addons.APAddon;
1919
import de.srendi.advancedperipherals.common.addons.appliedenergistics.AEApi;
2020
import 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;
2222
import de.srendi.advancedperipherals.common.addons.appliedenergistics.MEFluidHandler;
2323
import de.srendi.advancedperipherals.common.addons.appliedenergistics.MEItemHandler;
2424
import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner;
@@ -27,7 +27,6 @@
2727
import de.srendi.advancedperipherals.common.util.Pair;
2828
import de.srendi.advancedperipherals.common.util.StatusConstants;
2929
import de.srendi.advancedperipherals.common.util.inventory.ChemicalFilter;
30-
import de.srendi.advancedperipherals.common.util.inventory.ChemicalUtil;
3130
import de.srendi.advancedperipherals.common.util.inventory.FluidFilter;
3231
import de.srendi.advancedperipherals.common.util.inventory.FluidUtil;
3332
import de.srendi.advancedperipherals.common.util.inventory.GenericFilter;
@@ -36,7 +35,6 @@
3635
import de.srendi.advancedperipherals.common.util.inventory.ItemFilter;
3736
import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral;
3837
import me.ramidzkh.mekae2.ae2.MekanismKey;
39-
import mekanism.api.chemical.IChemicalHandler;
4038
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
4139
import net.neoforged.neoforge.items.IItemHandler;
4240
import 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

Comments
 (0)