From 7c4788f86f589d71b319e186fa5d8a468046bcc1 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 21 Mar 2021 12:23:14 +0800 Subject: Rely on ScreenRegistry more on calculating the bounds Signed-off-by: shedaniel --- .../main/java/me/shedaniel/rei/api/REIHelper.java | 1 - .../shedaniel/rei/api/ingredient/EntryStack.java | 3 +- .../rei/api/registry/screen/OverlayDecider.java | 4 +-- .../rei/api/registry/screen/ScreenRegistry.java | 33 +++++++++++++++++++--- 4 files changed, 32 insertions(+), 9 deletions(-) (limited to 'api/src/main/java') diff --git a/api/src/main/java/me/shedaniel/rei/api/REIHelper.java b/api/src/main/java/me/shedaniel/rei/api/REIHelper.java index f02ba4024..2911dab04 100644 --- a/api/src/main/java/me/shedaniel/rei/api/REIHelper.java +++ b/api/src/main/java/me/shedaniel/rei/api/REIHelper.java @@ -40,7 +40,6 @@ import java.util.Optional; @Environment(EnvType.CLIENT) public interface REIHelper extends Reloadable { - /** * @return the instance of {@link REIHelper} */ diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryStack.java index b817c33b6..6f4b7294f 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryStack.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryStack.java @@ -172,15 +172,14 @@ public interface EntryStack extends TextRepresentable, Renderer { @Deprecated public static final Settings, List>> TOOLTIP_APPEND_EXTRA = new Settings<>(stack -> Collections.emptyList()); - private static short nextId; private R defaultValue; private short id; @ApiStatus.Internal public Settings(R defaultValue) { this.defaultValue = defaultValue; - this.id = nextId++; SETTINGS.add(this); + this.id = (short) SETTINGS.indexOf(this); } @ApiStatus.Internal diff --git a/api/src/main/java/me/shedaniel/rei/api/registry/screen/OverlayDecider.java b/api/src/main/java/me/shedaniel/rei/api/registry/screen/OverlayDecider.java index f23ed695a..abcc7b35c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/registry/screen/OverlayDecider.java +++ b/api/src/main/java/me/shedaniel/rei/api/registry/screen/OverlayDecider.java @@ -59,11 +59,11 @@ public interface OverlayDecider extends Comparable { } /** - * Checks if mouse is inside the overlay + * Checks if a point is inside the overlay, return false for indicating that REI should not display anything here. * * @param mouseX mouse's x coordinates * @param mouseY mouse's y coordinates - * @return whether mouse is inside the overlay + * @return whether a point is inside the overlay */ default InteractionResult isInZone(double mouseX, double mouseY) { return PASS; diff --git a/api/src/main/java/me/shedaniel/rei/api/registry/screen/ScreenRegistry.java b/api/src/main/java/me/shedaniel/rei/api/registry/screen/ScreenRegistry.java index 4484e5050..d89f95169 100644 --- a/api/src/main/java/me/shedaniel/rei/api/registry/screen/ScreenRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/registry/screen/ScreenRegistry.java @@ -66,19 +66,36 @@ public interface ScreenRegistry extends Reloadable { List getDeciders(); /** - * Registers an overlay decider + * Registers an overlay decider, may be an instance of {@link DisplayBoundsProvider} for providing + * the boundaries of a screen. * * @param decider the decider to register */ void registerDecider(OverlayDecider decider); + /** + * Registers a provider for getting the focused stack by the mouse. + * + * @param provider the provider to register + */ void registerFocusedStack(FocusedStackProvider provider); /** - * Gets the bounds of the overlay. + * Returns the main center screen bounds returned, provided by deciders. + * + * @param screen the screen to check + * @param the type of screen + * @return the main center screen bounds, may be an empty {@link Rectangle} if there are no providers + */ + Rectangle getScreenBounds(T screen); + + /** + * Returns the bounds of the overlay, provided by deciders. * - * @param screen the current screen - * @return the left bounds + * @param location the side of the overlay + * @param screen the screen to check + * @param the type of screen + * @return the overlay bounds decided by the {@code location} */ Rectangle getOverlayBounds(DisplayPanelLocation location, T screen); @@ -130,5 +147,13 @@ public interface ScreenRegistry extends Reloadable { */ void registerClickArea(Class screenClass, ClickArea area); + /** + * Handles the click area, returns an optional collection of category identifiers. + * + * @param screenClass the class of the screen + * @param context the click area context + * @param the type of screen + * @return the collection of category identifiers, may be null if there are no click area handlers. + */ @Nullable Set handleClickArea(Class screenClass, ClickArea.ClickAreaContext context); } -- cgit