aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-07-13 22:11:38 +0800
committershedaniel <daniel@shedaniel.me>2020-07-13 22:11:38 +0800
commitc531e830ba3a5c13ec05f086e81b6776cd075539 (patch)
tree4dec7aa3a1a3aa423c80d20094d72a0aeed7bf80 /src
parentad005ad366c8238f8592e8595000742fe4d73a2e (diff)
parent0df9f46a8b74ec6517eeb574633d436c066027f3 (diff)
downloadRoughlyEnoughItems-c531e830ba3a5c13ec05f086e81b6776cd075539.tar.gz
RoughlyEnoughItems-c531e830ba3a5c13ec05f086e81b6776cd075539.tar.bz2
RoughlyEnoughItems-c531e830ba3a5c13ec05f086e81b6776cd075539.zip
Merge branch 'pull/379' into 4.x
Diffstat (limited to 'src')
-rw-r--r--src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java35
-rw-r--r--src/main/java/me/shedaniel/rei/impl/InternalWidgets.java9
2 files changed, 35 insertions, 9 deletions
diff --git a/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java b/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java
index 85eb02553..aff7a5e2b 100644
--- a/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java
+++ b/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java
@@ -47,7 +47,11 @@ public interface AutoTransferHandler {
static Result createSuccessful() {
return new ResultImpl();
}
-
+
+ static Result createSuccessfulReturningToScreen() {
+ return new ResultImpl(true, true, true);
+ }
+
static Result createNotApplicable() {
return new ResultImpl(false);
}
@@ -71,6 +75,12 @@ public interface AutoTransferHandler {
int getColor();
boolean isSuccessful();
+
+ /**
+ * Applicable if {@link #isSuccessful()} is true. Will return
+ * to the previous screen rather than staying open.
+ */
+ boolean isReturningToScreen();
boolean isApplicable();
@@ -111,21 +121,25 @@ public interface AutoTransferHandler {
@ApiStatus.Internal
final class ResultImpl implements Result {
- private boolean successful, applicable;
+ private boolean successful, applicable, returningToScreen;
private String errorKey;
private IntList integers = new IntArrayList();
private int color;
private ResultImpl() {
- this.successful = true;
- this.applicable = true;
+ this(true, true, false);
}
public ResultImpl(boolean applicable) {
- this.successful = false;
+ this(false, applicable, false);
+ }
+
+ public ResultImpl(boolean successful, boolean applicable, boolean returningToScreen) {
+ this.successful = successful;
this.applicable = applicable;
+ this.returningToScreen = returningToScreen;
}
-
+
public ResultImpl(String errorKey, IntList integers, int color) {
this.successful = false;
this.applicable = true;
@@ -144,12 +158,17 @@ public interface AutoTransferHandler {
public boolean isSuccessful() {
return successful;
}
-
+
@Override
public boolean isApplicable() {
return applicable;
}
-
+
+ @Override
+ public boolean isReturningToScreen() {
+ return returningToScreen;
+ }
+
@Override
public String getErrorKey() {
return errorKey;
diff --git a/src/main/java/me/shedaniel/rei/impl/InternalWidgets.java b/src/main/java/me/shedaniel/rei/impl/InternalWidgets.java
index e6b04a84d..497d67727 100644
--- a/src/main/java/me/shedaniel/rei/impl/InternalWidgets.java
+++ b/src/main/java/me/shedaniel/rei/impl/InternalWidgets.java
@@ -35,6 +35,8 @@ import me.shedaniel.rei.gui.widget.LateRenderable;
import me.shedaniel.rei.gui.widget.Widget;
import me.shedaniel.rei.gui.widget.WidgetWithBounds;
import me.shedaniel.rei.utils.CollectionUtils;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.ingame.ContainerScreen;
@@ -51,6 +53,7 @@ import java.util.Objects;
import java.util.function.Supplier;
@ApiStatus.Internal
+@Environment(EnvType.CLIENT)
public final class InternalWidgets {
private InternalWidgets() {}
@@ -65,8 +68,12 @@ public final class InternalWidgets {
for (AutoTransferHandler autoTransferHandler : RecipeHelper.getInstance().getSortedAutoCraftingHandler())
try {
AutoTransferHandler.Result result = autoTransferHandler.handle(context);
- if (result.isSuccessful())
+ if (result.isSuccessful()) {
+ if (result.isReturningToScreen()) {
+ break; // Same as failing, but doesn't ask other handlers
+ }
return;
+ }
} catch (Exception e) {
e.printStackTrace();
}