Skip to content

Commit

Permalink
fix requests being submitted on different grids
Browse files Browse the repository at this point in the history
  • Loading branch information
rlnt committed Sep 3, 2024
1 parent 01555b2 commit 37d2d55
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ExportState implements StatusState {
public StatusState handle(RequesterBlockEntity host, int index) {
var storageManager = host.getStorageManager().get(index);
if (storageManager.getKey() == null) {
return StatusState.IDLE;
return IDLE;
}

var inserted = StorageHelper.poweredInsert(
Expand All @@ -29,9 +29,9 @@ public StatusState handle(RequesterBlockEntity host, int index) {
return this;
}
if (inserted > 0) {
return StatusState.REQUEST;
return REQUEST;
}
return StatusState.IDLE;
return IDLE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class IdleState implements StatusState {
@Override
public StatusState handle(RequesterBlockEntity host, int index) {
if (host.getStorageManager().get(index).getBufferAmount() > 0) {
return StatusState.EXPORT;
return EXPORT;
}

var request = host.getRequests().get(index);
if (request.isRequesting() && request.getAmount() > host.getStorageManager().get(index).getKnownAmount()) {
return StatusState.REQUEST;
return REQUEST;
}

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public record LinkState(ICraftingLink link) implements StatusState {
@Override
public StatusState handle(RequesterBlockEntity host, int slot) {
if (link.isDone()) {
return StatusState.EXPORT;
return EXPORT;
}

if (link.isCanceled()) {
return StatusState.IDLE;
return IDLE;
}

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ public StatusState handle(RequesterBlockEntity host, int slot) {
return planSim;
}

var idleSim = StatusState.IDLE.handle(host, slot);
if (idleSim == StatusState.IDLE || idleSim == StatusState.EXPORT) {
var idleSim = IDLE.handle(host, slot);
if (idleSim == IDLE || idleSim == EXPORT) {
// idle simulation returning idle means a request is no
// longer required because we have enough items
// idle state returning export should not be possible
// idle state returning export should not be possible,
// but just in case, we will return to idle to handle it
return StatusState.IDLE;
return IDLE;
}

// idle sim returned that we can request
var requestSim = StatusState.REQUEST.handle(host, slot);
if (requestSim == StatusState.IDLE) {
return StatusState.IDLE;
var requestSim = REQUEST.handle(host, slot);
if (requestSim == IDLE) {
return IDLE;
}

// request sim returned that we can start planning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class PlanState implements StatusState {
@Override
public StatusState handle(RequesterBlockEntity host, int index) {
if (!future.isDone()) return this;
if (future.isCancelled()) return StatusState.IDLE;
if (future.isCancelled()) return IDLE;

try {
var plan = future.get();
Expand All @@ -31,15 +31,15 @@ public StatusState handle(RequesterBlockEntity host, int index) {
if (!submitResult.successful() || submitResult.link() == null) {
if (submitResult.errorCode() == CraftingSubmitErrorCode.INCOMPLETE_PLAN &&
!plan.missingItems().isEmpty()) {
return StatusState.MISSING;
return new MissingState();
}
return StatusState.IDLE;
return IDLE;
}

host.getStorageManager().get(index).setTotalAmount(plan.finalOutput().amount());
return new LinkState(Objects.requireNonNull(submitResult.link()));
} catch (InterruptedException | ExecutionException e) {
return StatusState.IDLE;
return IDLE;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class RequestState implements StatusState {
@Override
public StatusState handle(RequesterBlockEntity owner, int index) {
var amountToCraft = owner.getStorageManager().computeAmountToCraft(index);
if (amountToCraft <= 0) return StatusState.IDLE;
if (amountToCraft <= 0) return IDLE;
var key = owner.getRequests().getKey(index);

var future = owner.getMainNodeGrid()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
public interface StatusState {

StatusState IDLE = new IdleState();
StatusState MISSING = new MissingState();
StatusState REQUEST = new RequestState();
StatusState EXPORT = new ExportState();

Expand Down

0 comments on commit 37d2d55

Please sign in to comment.