aboutsummaryrefslogtreecommitdiff
path: root/api/src/main/java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-08-28 20:48:46 +0900
committershedaniel <daniel@shedaniel.me>2022-08-28 21:14:21 +0900
commitfb91ed996b01f986492de4007cb86be5e68ad192 (patch)
treeb1176be6374ac6d56094c9bcf2b48226b31e68ec /api/src/main/java
parent94e323f75c17e297c33fba1d3afb5c47ae66a8ad (diff)
downloadRoughlyEnoughItems-fb91ed996b01f986492de4007cb86be5e68ad192.tar.gz
RoughlyEnoughItems-fb91ed996b01f986492de4007cb86be5e68ad192.tar.bz2
RoughlyEnoughItems-fb91ed996b01f986492de4007cb86be5e68ad192.zip
More internal changes
Diffstat (limited to 'api/src/main/java')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TextField.java3
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java19
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ScreenRegistry.java23
-rw-r--r--api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java7
-rw-r--r--api/src/main/java/me/shedaniel/rei/impl/client/provider/OverlayProvider.java9
5 files changed, 57 insertions, 4 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TextField.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TextField.java
index 1757e77b5..4b062c6bd 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TextField.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TextField.java
@@ -23,6 +23,7 @@
package me.shedaniel.rei.api.client.gui.widgets;
+import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.vertex.PoseStack;
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
import me.shedaniel.clothconfig2.api.TickableWidget;
@@ -78,6 +79,8 @@ public interface TextField extends TickableWidget {
void setFocused(boolean focused);
+ void setFocusedFromKey(boolean focused, InputConstants.Key key);
+
void setResponder(Consumer<String> responder);
void setFocusedResponder(BooleanConsumer responder);
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java b/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java
index 5d8ed2b80..9954a57a9 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java
@@ -24,6 +24,8 @@
package me.shedaniel.rei.api.client.overlay;
import com.mojang.blaze3d.vertex.PoseStack;
+import me.shedaniel.math.Rectangle;
+import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.gui.drag.DraggingContext;
import me.shedaniel.rei.api.client.gui.widgets.TextField;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
@@ -38,6 +40,10 @@ import java.util.Optional;
@Environment(EnvType.CLIENT)
public abstract class ScreenOverlay extends WidgetWithBounds {
+ public static Optional<ScreenOverlay> getInstance() {
+ return REIRuntime.getInstance().getOverlay();
+ }
+
/**
* Queues reload of the overlay.
*/
@@ -79,6 +85,19 @@ public abstract class ScreenOverlay extends WidgetWithBounds {
public abstract boolean isNotInExclusionZones(double mouseX, double mouseY);
/**
+ * Returns whether a specified bounds is within the bounds of the overlay.
+ *
+ * @param bounds the bounds to test
+ * @return whether the bounds is within the bounds of the overlay
+ */
+ public boolean isNotInExclusionZones(Rectangle bounds) {
+ return isNotInExclusionZones(bounds.x, bounds.y) &&
+ isNotInExclusionZones(bounds.getMaxX(), bounds.y) &&
+ isNotInExclusionZones(bounds.x, bounds.getMaxY()) &&
+ isNotInExclusionZones(bounds.getMaxX(), bounds.getMaxY());
+ }
+
+ /**
* Returns the entry list of the overlay.
*
* @return the entry list of the overlay
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ScreenRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ScreenRegistry.java
index d43b96be6..45d32737d 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ScreenRegistry.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ScreenRegistry.java
@@ -25,6 +25,7 @@ package me.shedaniel.rei.api.client.registry.screen;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
+import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.gui.config.DisplayPanelLocation;
import me.shedaniel.rei.api.client.gui.drag.DraggableStackProvider;
import me.shedaniel.rei.api.client.gui.drag.DraggableStackProviderWidget;
@@ -49,14 +50,12 @@ import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvents;
+import net.minecraft.world.InteractionResult;
import net.minecraft.world.inventory.AbstractContainerMenu;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -289,4 +288,20 @@ public interface ScreenRegistry extends Reloadable<REIClientPlugin> {
return false;
}
+
+ default boolean shouldDisplay(Screen screen) {
+ if (REIRuntime.getInstance().getOverlay().isEmpty()) return false;
+ if (screen == null) return false;
+ if (screen != Minecraft.getInstance().screen) return false;
+ try {
+ for (OverlayDecider decider : getDeciders(screen)) {
+ InteractionResult result = decider.shouldScreenBeOverlaid(screen);
+ if (result != InteractionResult.PASS) {
+ return result != InteractionResult.FAIL && REIRuntime.getInstance().getPreviousScreen() != null;
+ }
+ }
+ } catch (ConcurrentModificationException ignored) {
+ }
+ return false;
+ }
}
diff --git a/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java b/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java
index eeb03e5fb..22c64a606 100644
--- a/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java
+++ b/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java
@@ -23,6 +23,7 @@
package me.shedaniel.rei.impl.client;
+import com.google.common.base.Suppliers;
import com.mojang.serialization.DataResult;
import me.shedaniel.math.Point;
import me.shedaniel.rei.api.client.ClientHelper;
@@ -30,6 +31,7 @@ import me.shedaniel.rei.api.client.favorites.FavoriteEntry;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
import me.shedaniel.rei.api.client.gui.widgets.TooltipContext;
import me.shedaniel.rei.api.client.gui.widgets.TooltipQueue;
+import me.shedaniel.rei.api.client.overlay.ScreenOverlay;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.client.registry.entry.PreFilteredEntryList;
import me.shedaniel.rei.api.client.registry.screen.ClickArea;
@@ -66,6 +68,7 @@ public final class ClientInternals {
private static final AutoCraftingEvaluator AUTO_CRAFTING_EVALUATOR = resolveService(AutoCraftingEvaluator.class);
private static final TooltipQueue TOOLTIP_QUEUE = resolveService(TooltipQueue.class);
private static final TooltipRenderer TOOLTIP_RENDERER = resolveService(TooltipRenderer.class);
+ private static final OverlayProvider SCREEN_OVERLAY_PROVIDER = resolveService(OverlayProvider.class);
private static Function<CompoundTag, DataResult<FavoriteEntry>> favoriteEntryFromJson = (object) -> throwNotSetup();
private static Function<Boolean, ClickArea.Result> clickAreaHandlerResult = (result) -> throwNotSetup();
private static BiFunction<@Nullable Point, Collection<Tooltip.Entry>, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup();
@@ -142,6 +145,10 @@ public final class ClientInternals {
return TOOLTIP_RENDERER;
}
+ public static ScreenOverlay getNewOverlay() {
+ return SCREEN_OVERLAY_PROVIDER.provide();
+ }
+
public static TooltipContext createTooltipContext(Point point, @Nullable TooltipFlag flag, boolean isSearch) {
return tooltipContextProvider.apply(point, flag, isSearch);
}
diff --git a/api/src/main/java/me/shedaniel/rei/impl/client/provider/OverlayProvider.java b/api/src/main/java/me/shedaniel/rei/impl/client/provider/OverlayProvider.java
new file mode 100644
index 000000000..c3688626a
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/impl/client/provider/OverlayProvider.java
@@ -0,0 +1,9 @@
+package me.shedaniel.rei.impl.client.provider;
+
+import me.shedaniel.rei.api.client.overlay.ScreenOverlay;
+import org.jetbrains.annotations.ApiStatus;
+
+@ApiStatus.Internal
+public interface OverlayProvider {
+ ScreenOverlay provide();
+}