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 --- .../rei/RoughlyEnoughItemsInitializer.java | 3 +++ .../shedaniel/rei/gui/ContainerScreenOverlay.java | 29 ++++++++------------- .../me/shedaniel/rei/impl/AbstractEntryStack.java | 3 ++- .../java/me/shedaniel/rei/impl/REIHelperImpl.java | 15 ++++------- .../me/shedaniel/rei/impl/ScreenRegistryImpl.java | 30 +++++++++++++--------- .../rei/impl/entry/EmptyEntryDefinition.java | 5 ++-- 6 files changed, 41 insertions(+), 44 deletions(-) (limited to 'runtime/src') 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) 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 extends AbstractRenderer implements @Override public T get(Settings 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) 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 Rectangle getOverlayBounds(DisplayPanelLocation location, T screen) { - Window window = Minecraft.getInstance().getWindow(); - int scaledWidth = window.getGuiScaledWidth(); - int scaledHeight = window.getGuiScaledHeight(); + public Rectangle getScreenBounds(T screen) { for (OverlayDecider decider : getDeciders(screen)) { if (decider instanceof DisplayBoundsProvider) { - Rectangle containerBounds = ((DisplayBoundsProvider) 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) decider).getScreenBounds(screen); } } return new Rectangle(); } + @Override + public 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 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, EntrySerial @Override public int hash(EntryStack 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 -- cgit