diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-03-21 12:23:14 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-03-21 12:23:14 +0800 |
| commit | 7c4788f86f589d71b319e186fa5d8a468046bcc1 (patch) | |
| tree | b87fd23a6d65a96e381c27fe0470d1f50e77a635 | |
| parent | 2c29cac8a5e0878696c8e6635f4e41ed4845b41c (diff) | |
| download | RoughlyEnoughItems-7c4788f86f589d71b319e186fa5d8a468046bcc1.tar.gz RoughlyEnoughItems-7c4788f86f589d71b319e186fa5d8a468046bcc1.tar.bz2 RoughlyEnoughItems-7c4788f86f589d71b319e186fa5d8a468046bcc1.zip | |
Rely on ScreenRegistry more on calculating the bounds
Signed-off-by: shedaniel <daniel@shedaniel.me>
13 files changed, 103 insertions, 62 deletions
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<T> extends TextRepresentable, Renderer { @Deprecated public static final Settings<Function<EntryStack<?>, List<Component>>> 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<OverlayDecider> { } /** - * 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<OverlayDecider> 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 <T> the type of screen + * @return the main center screen bounds, may be an empty {@link Rectangle} if there are no providers + */ + <T extends Screen> 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 <T> the type of screen + * @return the overlay bounds decided by the {@code location} */ <T extends Screen> Rectangle getOverlayBounds(DisplayPanelLocation location, T screen); @@ -130,5 +147,13 @@ public interface ScreenRegistry extends Reloadable { */ <T extends Screen> void registerClickArea(Class<? extends T> screenClass, ClickArea<T> 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 <T> the type of screen + * @return the collection of category identifiers, may be null if there are no click area handlers. + */ @Nullable <T extends Screen> Set<ResourceLocation> handleClickArea(Class<T> screenClass, ClickArea.ClickAreaContext<T> context); } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index 585d13dc9..5bd37fb6a 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -422,7 +422,8 @@ public class DefaultPlugin implements REIPlugin, BuiltinPlugin { registry.register(GameModeFavoriteEntry.ID, GameModeFavoriteEntry.Type.INSTANCE); registry.getOrCrateSection(new TranslatableComponent(GameModeFavoriteEntry.TRANSLATION_KEY)) .add(Stream.concat( - Arrays.stream(GameType.values()), + Arrays.stream(GameType.values()) + .filter(type -> type != GameType.NOT_SET), Stream.of((GameType) null) ).<FavoriteEntry>map(GameModeFavoriteEntry.Type.INSTANCE::fromArgs).toArray(FavoriteEntry[]::new)); registry.register(WeatherFavoriteEntry.ID, WeatherFavoriteEntry.Type.INSTANCE); @@ -434,12 +435,6 @@ public class DefaultPlugin implements REIPlugin, BuiltinPlugin { } @Override - public void registerSubsets(SubsetsRegistry registry) { -// registry.registerPathEntry("roughlyenoughitems:food", EntryStacks.of(Items.MILK_BUCKET)); -// registry.registerPathEntry("roughlyenoughitems:food/roughlyenoughitems:cookies", EntryStacks.of(Items.COOKIE)); - } - - @Override public int getPriority() { return -100; } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/favorites/GameModeFavoriteEntry.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/favorites/GameModeFavoriteEntry.java index 4450a93b8..dbaec7371 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/favorites/GameModeFavoriteEntry.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/favorites/GameModeFavoriteEntry.java @@ -124,11 +124,24 @@ public class GameModeFavoriteEntry extends FavoriteEntry { } @Override - public @Nullable Tooltip getTooltip(Point mouse) { + @Nullable + public Tooltip getTooltip(Point mouse) { if (gameMode == null) return Tooltip.create(mouse, new TranslatableComponent("text.rei.gamemode_button.tooltip.dropdown")); return Tooltip.create(mouse, new TranslatableComponent("text.rei.gamemode_button.tooltip.entry", gameMode.getDisplayName().getString())); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return hashCode() == o.hashCode(); + } + + @Override + public int hashCode() { + return Objects.hash(getClass(), showcase, gameMode); + } }; } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/favorites/WeatherFavoriteEntry.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/favorites/WeatherFavoriteEntry.java index fcf3077bc..7cb1ac7e6 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/favorites/WeatherFavoriteEntry.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/favorites/WeatherFavoriteEntry.java @@ -143,11 +143,24 @@ public class WeatherFavoriteEntry extends FavoriteEntry { } @Override - public @Nullable Tooltip getTooltip(Point mouse) { + @Nullable + public Tooltip getTooltip(Point mouse) { if (weather == null) return Tooltip.create(mouse, new TranslatableComponent("text.rei.weather_button.tooltip.dropdown")); return Tooltip.create(mouse, new TranslatableComponent("text.rei.weather_button.tooltip.entry", new TranslatableComponent(weather.getTranslateKey()))); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return hashCode() == o.hashCode(); + } + + @Override + public int hashCode() { + return Objects.hash(getClass(), showcase, weather); + } }; } diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java index dfe52a3a2..e817493be 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java @@ -105,6 +105,9 @@ public class RoughlyEnoughItemsInitializer { } public static void checkClothConfig() { + if (!Platform.isModLoaded(Platform.isFabric() ? "cloth-config2" : "cloth-config")) { + RoughlyEnoughItemsState.error("Cloth Config is not installed!", "https://www.curseforge.com/minecraft/mc-mods/cloth-config/files/all"); + } /*try { if (!Platform.isModLoaded("cloth-config2")) { RoughlyEnoughItemsState.error("Cloth Config is not installed!", "https://www.curseforge.com/minecraft/mc-mods/cloth-config/files/all"); diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index bd5f85ef4..8d1a1209a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -53,7 +53,6 @@ import me.shedaniel.rei.api.ingredient.EntryStack; import me.shedaniel.rei.api.ingredient.util.EntryStacks; import me.shedaniel.rei.api.registry.category.CategoryRegistry; import me.shedaniel.rei.api.registry.screen.ClickArea; -import me.shedaniel.rei.api.registry.screen.DisplayBoundsProvider; import me.shedaniel.rei.api.registry.screen.OverlayDecider; import me.shedaniel.rei.api.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.util.CollectionUtils; @@ -429,16 +428,10 @@ public class ContainerScreenOverlay extends REIOverlay { } private Rectangle getSubsetsButtonBounds() { - // TODO rely on the screen registry if (ConfigObject.getInstance().isSubsetsEnabled()) { - if (Minecraft.getInstance().screen instanceof AbstractRecipeViewingScreen) { - AbstractRecipeViewingScreen widget = (AbstractRecipeViewingScreen) Minecraft.getInstance().screen; - return new Rectangle(widget.getBounds().x, 3, widget.getBounds().width, 18); - } - AbstractContainerScreen<?> containerScreen = REIHelper.getInstance().getPreviousContainerScreen(); - if (containerScreen != null) { - return new Rectangle(containerScreen.leftPos, 3, containerScreen.imageWidth, 18); - } + ScreenRegistry registry = ScreenRegistry.getInstance(); + Rectangle screenBounds = registry.getScreenBounds(minecraft.screen); + return new Rectangle(screenBounds.x, 3, screenBounds.width, 18); } return null; } @@ -488,15 +481,8 @@ public class ContainerScreenOverlay extends REIOverlay { case BOTTOM_SIDE: return getBottomSideSearchFieldArea(widthRemoved); default: - case CENTER: { - for (OverlayDecider decider : ScreenRegistry.getInstance().getDeciders(Minecraft.getInstance().screen)) { - if (decider instanceof DisplayBoundsProvider) { - Rectangle containerBounds = ((DisplayBoundsProvider<Screen>) decider).getScreenBounds(Minecraft.getInstance().screen); - return getBottomCenterSearchFieldArea(containerBounds, widthRemoved); - } - } - return new Rectangle(); - } + case CENTER: + return getCenterSearchFieldArea(widthRemoved); } } @@ -508,6 +494,11 @@ public class ContainerScreenOverlay extends REIOverlay { return new Rectangle(bounds.x + 2, window.getGuiScaledHeight() - 22, bounds.width - 6 - widthRemoved, 18); } + private Rectangle getCenterSearchFieldArea(int widthRemoved) { + Rectangle screenBounds = ScreenRegistry.getInstance().getScreenBounds(minecraft.screen); + return getBottomCenterSearchFieldArea(screenBounds, widthRemoved); + } + private Rectangle getBottomCenterSearchFieldArea(Rectangle containerBounds, int widthRemoved) { return new Rectangle(containerBounds.x, window.getGuiScaledHeight() - 22, containerBounds.width - widthRemoved, 18); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java index 8f9cddf1d..c065ff64e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java @@ -93,8 +93,9 @@ public abstract class AbstractEntryStack<A> extends AbstractRenderer implements @Override public <T> T get(Settings<T> settings) { Object o = this.settings == null ? null : this.settings.get(settings.getId()); - if (o == null) + if (o == null) { return settings.getDefaultValue(); + } return (T) o; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/REIHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/REIHelperImpl.java index 0884d70d7..a18b71b3c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/REIHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/REIHelperImpl.java @@ -36,8 +36,6 @@ import me.shedaniel.rei.api.config.ConfigObject; import me.shedaniel.rei.api.gui.config.SearchFieldLocation; import me.shedaniel.rei.api.gui.widgets.TextField; import me.shedaniel.rei.api.gui.widgets.Tooltip; -import me.shedaniel.rei.api.registry.screen.DisplayBoundsProvider; -import me.shedaniel.rei.api.registry.screen.OverlayDecider; import me.shedaniel.rei.api.registry.screen.ScreenRegistry; import me.shedaniel.rei.gui.ContainerScreenOverlay; import me.shedaniel.rei.gui.OverlaySearchField; @@ -174,17 +172,14 @@ public class REIHelperImpl implements REIHelper { @Override public SearchFieldLocation getContextualSearchFieldLocation() { + SearchFieldLocation location = ConfigObject.getInstance().getSearchFieldLocation(); Window window = Minecraft.getInstance().getWindow(); - for (OverlayDecider decider : ScreenRegistry.getInstance().getDeciders(Minecraft.getInstance().screen)) { - if (decider instanceof DisplayBoundsProvider) { - Rectangle containerBounds = ((DisplayBoundsProvider<Screen>) decider).getScreenBounds(Minecraft.getInstance().screen); - if (window.getGuiScaledHeight() - 20 <= containerBounds.getMaxY()) { - return SearchFieldLocation.BOTTOM_SIDE; - } else break; - } + Rectangle screenBounds = ScreenRegistry.getInstance().getScreenBounds(Minecraft.getInstance().screen); + if (location == SearchFieldLocation.CENTER && window.getGuiScaledHeight() - 20 <= screenBounds.getMaxY()) { + return SearchFieldLocation.BOTTOM_SIDE; } - return ConfigObject.getInstance().getSearchFieldLocation(); + return location; } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java index ff7dca9a2..781f78bae 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java @@ -93,25 +93,31 @@ public class ScreenRegistryImpl implements ScreenRegistry { } @Override - public <T extends Screen> Rectangle getOverlayBounds(DisplayPanelLocation location, T screen) { - Window window = Minecraft.getInstance().getWindow(); - int scaledWidth = window.getGuiScaledWidth(); - int scaledHeight = window.getGuiScaledHeight(); + public <T extends Screen> Rectangle getScreenBounds(T screen) { for (OverlayDecider decider : getDeciders(screen)) { if (decider instanceof DisplayBoundsProvider) { - Rectangle containerBounds = ((DisplayBoundsProvider<T>) decider).getScreenBounds(screen); - if (location == DisplayPanelLocation.LEFT) { - if (containerBounds.x < 10) continue; - return new Rectangle(2, 0, containerBounds.x - 2, scaledHeight); - } else { - if (scaledWidth - containerBounds.getMaxX() < 10) continue; - return new Rectangle(containerBounds.getMaxX() + 2, 0, scaledWidth - containerBounds.getMaxX() - 4, scaledHeight); - } + return ((DisplayBoundsProvider<T>) decider).getScreenBounds(screen); } } return new Rectangle(); } + @Override + public <T extends Screen> Rectangle getOverlayBounds(DisplayPanelLocation location, T screen) { + Window window = Minecraft.getInstance().getWindow(); + int scaledWidth = window.getGuiScaledWidth(); + int scaledHeight = window.getGuiScaledHeight(); + Rectangle screenBounds = getScreenBounds(screen); + if (screenBounds.isEmpty()) return new Rectangle(); + if (location == DisplayPanelLocation.LEFT) { + if (screenBounds.x < 10) return new Rectangle(); + return new Rectangle(2, 0, screenBounds.x - 2, scaledHeight); + } else { + if (scaledWidth - screenBounds.getMaxX() < 10) return new Rectangle(); + return new Rectangle(screenBounds.getMaxX() + 2, 0, scaledWidth - screenBounds.getMaxX() - 4, scaledHeight); + } + } + @Nullable @Override public <T extends Screen> EntryStack<?> getFocusedStack(T screen, Point mouse) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/entry/EmptyEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/impl/entry/EmptyEntryDefinition.java index 8a5008cf1..cc6253622 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/entry/EmptyEntryDefinition.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/entry/EmptyEntryDefinition.java @@ -46,6 +46,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Collections; +import java.util.Objects; import java.util.Optional; import java.util.function.Supplier; @@ -107,12 +108,12 @@ public enum EmptyEntryDefinition implements EntryDefinition<Object>, EntrySerial @Override public int hash(EntryStack<Object> entry, Object value, ComparisonContext context) { - return ordinal(); + return empty ? ordinal() : Objects.hashCode(value); } @Override public boolean equals(Object o1, Object o2, ComparisonContext context) { - return true; + return empty || Objects.equals(o1, o2); } @Override |
