-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crafting jobs appearing on other grids #30
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.almostreliable.merequester.requester.status; | ||
|
||
import appeng.api.networking.crafting.CalculationStrategy; | ||
import appeng.api.networking.crafting.CraftingSubmitErrorCode; | ||
import appeng.api.networking.crafting.ICraftingPlan; | ||
import appeng.api.networking.ticking.TickRateModulation; | ||
|
@@ -11,12 +12,33 @@ | |
|
||
public final class PlanState implements StatusState { | ||
|
||
private final boolean wasMissing; | ||
private final Future<? extends ICraftingPlan> future; | ||
|
||
PlanState(Future<? extends ICraftingPlan> future) { | ||
PlanState(boolean wasMissing, Future<? extends ICraftingPlan> future) { | ||
this.wasMissing = wasMissing; | ||
this.future = future; | ||
} | ||
|
||
static PlanState BuildPlan(RequesterBlockEntity host, int slot, boolean wasMissing) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is completely different code style from the rest of the project. Methods should always be lowercase even if they are static. You also should not place the opening bracket in the next line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, C# bleeding through and I apparently hate myself because I setup vscode for Java right as java22 broke a bunch of extensions. I should have double checked formatting though, that's on me. |
||
{ | ||
// Once BuildPlan is invoked, we're crafting no matter what, rather than returning a null PlanState | ||
var amountToCraft = Math.max(1, host.getStorageManager().computeAmountToCraft(slot)); | ||
var key = host.getRequests().getKey(slot); | ||
|
||
var future = host.getMainNodeGrid() | ||
.getCraftingService() | ||
.beginCraftingCalculation( | ||
host.getLevel(), | ||
host::getActionSource, | ||
key, | ||
amountToCraft, | ||
CalculationStrategy.CRAFT_LESS | ||
); | ||
|
||
return new PlanState(wasMissing, future); | ||
} | ||
|
||
@Override | ||
public StatusState handle(RequesterBlockEntity host, int index) { | ||
if (!future.isDone()) return this; | ||
|
@@ -45,7 +67,7 @@ public StatusState handle(RequesterBlockEntity host, int index) { | |
|
||
@Override | ||
public RequestStatus type() { | ||
return RequestStatus.PLAN; | ||
return wasMissing ? RequestStatus.MISSING : RequestStatus.PLAN; | ||
} | ||
|
||
@Override | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I agree that this change would result in less code, it's not very efficient to schedule new operations to the next tick especially when exporting is involved. This makes the requester noticeably slower.
It's incorrect that the client will never see the "missing ingredient" state with the current behavior. You can just remove the necessary ingredients for a recipe that is configured in the requester and it will show you the missing state in the GUI. This is specified here: https://github.com/AlmostReliable/merequester/blob/1.19-forge/src/main/java/com/almostreliable/merequester/requester/status/PlanState.java#L33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the same setup to reproduce the issues caused by the singleton MissingState I was experiencing an issue where constantly missing an ingredient would result in the client feedback only showing Idle. I believe the reason for this is because right after transitioning from PlanState to MissingState, handle is then invoked again and we were immediately returning to PlanState. As I was writing this comment, I investigated more and now realize that this is actually a 2nd artifact of MissingState being a singleton and addressing that root issue would eliminate this behavior as well.