Skip to content

Commit 895ceb6

Browse files
committed
Fixed issues with the cached status being null causing missing information when a job is done/canceled. Added a getCraftingJob function with the job id
1 parent 741ffdd commit 895ceb6

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/main/java/de/srendi/advancedperipherals/common/addons/ae2/AECraftJob.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ private void prepareCPUAndStatus(ICraftingService service) {
290290
cpuCluster.craftingLogic.addListener((key) -> {
291291
// The last time the listeners are called from the cpu logic is when the job is finished
292292
// These listeners are not intended by ae2 to be used like this, but it works, and we don't modify the key
293-
this.cachedStatus = cpuCluster.getJobStatus();
293+
if (cpuCluster.getJobStatus() != null) {
294+
this.cachedStatus = cpuCluster.getJobStatus();
295+
}
294296
});
295297
this.targetCpu = cpu;
296298
return;
@@ -301,9 +303,10 @@ private void prepareCPUAndStatus(ICraftingService service) {
301303
}
302304

303305
private CraftingJobStatus getJobStatus() {
304-
if (jobStatus == null || jobStatus.get() == null || cachedStatus != null) {
306+
if (jobStatus == null || jobStatus.get() == null && cachedStatus != null) {
305307
return cachedStatus;
306308
}
309+
cachedStatus = jobStatus.get();
307310
return jobStatus.get();
308311
}
309312
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,22 @@ public MethodResult getCraftingJobs() {
651651
return MethodResult.of(jobs);
652652
}
653653

654+
@Override
655+
@LuaFunction(mainThread = true)
656+
public MethodResult getCraftingJob(int id) {
657+
if (!isAvailable())
658+
return notConnected();
659+
660+
AECraftJob foundJob = null;
661+
662+
for (AECraftJob job : bridge.getJobs()) {
663+
if (job.getId() == id) {
664+
foundJob = job;
665+
}
666+
}
667+
return MethodResult.of(foundJob);
668+
}
669+
654670
@Override
655671
@LuaFunction(mainThread = true)
656672
public MethodResult cancelCraftingJobs(IArguments arguments) {

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import dan200.computercraft.api.peripheral.IComputerAccess;
1212
import dan200.computercraft.core.apis.TableHelper;
1313
import dan200.computercraft.core.computer.ComputerSide;
14+
import de.srendi.advancedperipherals.common.addons.ae2.AECraftJob;
1415
import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner;
1516
import de.srendi.advancedperipherals.common.addons.refinedstorage.RSCraftJob;
1617
import de.srendi.advancedperipherals.common.addons.refinedstorage.RsApi;
@@ -629,6 +630,22 @@ public MethodResult getCraftingJobs() {
629630
return MethodResult.of(RsApi.getCraftingTasks(getNetwork(), bridge));
630631
}
631632

633+
@Override
634+
@LuaFunction(mainThread = true)
635+
public MethodResult getCraftingJob(int id) {
636+
if (!isAvailable())
637+
return notConnected();
638+
639+
RSCraftJob foundJob = null;
640+
641+
for (RSCraftJob job : bridge.getJobs()) {
642+
if (job.getId() == id) {
643+
foundJob = job;
644+
}
645+
}
646+
return MethodResult.of(foundJob);
647+
}
648+
632649
@Override
633650
@LuaFunction(mainThread = true)
634651
public MethodResult cancelCraftingJobs(IArguments arguments) throws LuaException {

src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ public interface IStorageSystemPeripheral {
112112

113113
MethodResult getCraftingJobs();
114114

115+
// A function to get our BasicCraftJob object with the id
116+
MethodResult getCraftingJob(int id);
117+
115118
MethodResult cancelCraftingJobs(IArguments arguments) throws LuaException;
116119

117120
MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException;

0 commit comments

Comments
 (0)