diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-07-05 15:31:12 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-07-05 15:31:12 +0800 |
| commit | 17150bedcdf80944a64e165976cf2491d409b1c0 (patch) | |
| tree | f71725bf6c37fd2bc82fbf8bf07a4b98ba2d1584 /src/main/java | |
| parent | af1b3f780d8edb361c00421cdd991f3f2b86849c (diff) | |
| download | RoughlyEnoughItems-17150bedcdf80944a64e165976cf2491d409b1c0.tar.gz RoughlyEnoughItems-17150bedcdf80944a64e165976cf2491d409b1c0.tar.bz2 RoughlyEnoughItems-17150bedcdf80944a64e165976cf2491d409b1c0.zip | |
Fix #370 and changes to how screens are handled
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src/main/java')
20 files changed, 260 insertions, 140 deletions
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java index bf8d57f1d..044b2ae4a 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java @@ -72,8 +72,10 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer { player.addMessage(new TranslatableText("text.rei.no_permission_cheat").formatted(Formatting.RED), false); return; } - if (!player.inventory.getCursorStack().isEmpty()) + if (!player.inventory.getCursorStack().isEmpty()) { player.inventory.setCursorStack(ItemStack.EMPTY); + player.updateCursorStack(); + } }); ServerSidePacketRegistry.INSTANCE.register(CREATE_ITEMS_PACKET, (packetContext, packetByteBuf) -> { ServerPlayerEntity player = (ServerPlayerEntity) packetContext.getPlayer(); @@ -100,8 +102,6 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer { if (!inventory.getCursorStack().isEmpty() && ItemStack.areItemsEqual(inventory.getCursorStack(), stack) && ItemStack.areTagsEqual(inventory.getCursorStack(), stack)) { stack.setCount(MathHelper.clamp(stack.getCount() + inventory.getCursorStack().getCount(), 1, stack.getMaxCount())); } else if (!inventory.getCursorStack().isEmpty()) { - inventory.setCursorStack(ItemStack.EMPTY); - player.updateCursorStack(); return; } inventory.setCursorStack(stack.copy()); diff --git a/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java b/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java index 7ba78120b..7c1f3d2a1 100644 --- a/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java +++ b/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java @@ -25,12 +25,15 @@ package me.shedaniel.rei.api; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.impl.DisplayHelperImpl; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.gui.screen.Screen; import java.util.List; import java.util.function.Supplier; -public interface BaseBoundsHandler extends DisplayHelper.DisplayBoundsHandler<Screen> { +@Environment(EnvType.CLIENT) +public interface BaseBoundsHandler extends OverlayDecider { static BaseBoundsHandler getInstance() { return ((DisplayHelperImpl) DisplayHelper.getInstance()).getBaseBoundsHandler(); diff --git a/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/src/main/java/me/shedaniel/rei/api/ConfigObject.java index ffa8c4a72..a581ce649 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigObject.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -24,10 +24,7 @@ package me.shedaniel.rei.api; import me.shedaniel.clothconfig2.api.ModifierKeyCode; -import me.shedaniel.rei.gui.config.EntryPanelOrdering; -import me.shedaniel.rei.gui.config.RecipeBorderType; -import me.shedaniel.rei.gui.config.RecipeScreenType; -import me.shedaniel.rei.gui.config.SearchFieldLocation; +import me.shedaniel.rei.gui.config.*; import me.shedaniel.rei.impl.ConfigManagerImpl; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -77,7 +74,11 @@ public interface ConfigObject { SearchFieldLocation getSearchFieldLocation(); - boolean isLeftHandSidePanel(); + default boolean isLeftHandSidePanel() { + return getDisplayPanelLocation() == DisplayPanelLocation.LEFT; + } + + DisplayPanelLocation getDisplayPanelLocation(); boolean isCraftableFilterEnabled(); diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index 52936de0e..fbf753a98 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -25,14 +25,19 @@ package me.shedaniel.rei.api; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.gui.config.DisplayPanelLocation; import me.shedaniel.rei.gui.config.SearchFieldLocation; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.util.ActionResult; +import org.jetbrains.annotations.ApiStatus; import java.util.List; import java.util.function.Supplier; import static net.minecraft.util.ActionResult.PASS; +@Environment(EnvType.CLIENT) public interface DisplayHelper { /** @@ -49,8 +54,12 @@ public interface DisplayHelper { * @return the sorted list of responsible bounds handlers * @see DisplayHelper#getResponsibleBoundsHandler(Class) for the unsorted version */ + @Deprecated + @ApiStatus.ScheduledForRemoval List<DisplayBoundsHandler<?>> getSortedBoundsHandlers(Class<?> screenClass); + List<OverlayDecider> getSortedOverlayDeciders(Class<?> screenClass); + /** * Gets all registered overlay deciders * @@ -59,12 +68,14 @@ public interface DisplayHelper { List<OverlayDecider> getAllOverlayDeciders(); /** - * Gets all responsible bounds handlers + * Gets the responsible bounds handlers * * @param screenClass the class for checking responsible bounds handlers * @return the the list of responsible bounds handlers * @see DisplayHelper#getSortedBoundsHandlers(Class) for the sorted version */ + @Deprecated + @ApiStatus.ScheduledForRemoval DisplayBoundsHandler<?> getResponsibleBoundsHandler(Class<?> screenClass); /** @@ -74,6 +85,40 @@ public interface DisplayHelper { */ void registerHandler(OverlayDecider decider); + default <T> void registerProvider(DisplayBoundsProvider<T> provider) { + registerHandler(provider); + } + + /** + * Gets the left bounds of the overlay + * + * @param screen the current screen + * @return the left bounds + */ + <T> Rectangle getOverlayBounds(DisplayPanelLocation location, T screen); + + interface DisplayBoundsProvider<T> extends OverlayDecider { + /** + * @param screen the screen + * @return the boundary of the base container panel. + */ + Rectangle getScreenBounds(T screen); + + /** + * Gets the base supported class for the bounds handler + * + * @return the base class + */ + Class<?> getBaseSupportedClass(); + + @Override + default boolean isHandingScreen(Class<?> screen) { + return getBaseSupportedClass().isAssignableFrom(screen); + } + } + + @Deprecated + @ApiStatus.ScheduledForRemoval interface DisplayBoundsHandler<T> extends OverlayDecider { /** * Gets the base supported class for the bounds handler @@ -114,18 +159,20 @@ public interface DisplayHelper { * @see BaseBoundsHandler#registerExclusionZones(Class, Supplier) for easier api */ default ActionResult canItemSlotWidgetFit(int left, int top, T screen, Rectangle fullBounds) { + ActionResult fit = isInZone(left, top); + if (fit == ActionResult.FAIL) + return ActionResult.FAIL; + ActionResult fit2 = isInZone(left + 18, top + 18); + if (fit2 == ActionResult.FAIL) + return ActionResult.FAIL; + if (fit == ActionResult.SUCCESS && fit2 == ActionResult.SUCCESS) + return ActionResult.SUCCESS; return PASS; } - /** - * Checks if mouse is inside the overlay - * - * @param mouseX mouse's x coordinates - * @param mouseY mouse's y coordinates - * @return whether mouse is inside the overlay - */ + @Override default ActionResult isInZone(double mouseX, double mouseY) { - return PASS; + return OverlayDecider.super.isInZone(mouseX, mouseY); } /** @@ -143,26 +190,24 @@ public interface DisplayHelper { return new Rectangle(rectangle.x + 1, rectangle.y + 2 + offset, rectangle.width - 2, rectangle.height - 5 - offset); } - /** - * Checks if REI should recalculate the overlay bounds - * - * @param isOnRightSide whether the user has set the overlay to the right - * @param rectangle the current overlay bounds - * @return whether REI should recalculate the overlay bounds - */ + @Deprecated + @ApiStatus.ScheduledForRemoval default boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) { return false; } + @Override + default boolean shouldRecalculateArea(DisplayPanelLocation location, Rectangle rectangle) { + return shouldRecalculateArea(location == DisplayPanelLocation.RIGHT, rectangle); + } + /** * Gets the priority of the handler, the higher it is, the earlier it is called. * * @return the priority in float */ @Override - default float getPriority() { - return 0f; - } + float getPriority(); } } diff --git a/src/main/java/me/shedaniel/rei/api/OverlayDecider.java b/src/main/java/me/shedaniel/rei/api/OverlayDecider.java index 9f20f8223..500d9f058 100644 --- a/src/main/java/me/shedaniel/rei/api/OverlayDecider.java +++ b/src/main/java/me/shedaniel/rei/api/OverlayDecider.java @@ -23,8 +23,12 @@ package me.shedaniel.rei.api; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.gui.config.DisplayPanelLocation; import net.minecraft.util.ActionResult; +import static net.minecraft.util.ActionResult.PASS; + public interface OverlayDecider { boolean isHandingScreen(Class<?> screen); @@ -40,4 +44,26 @@ public interface OverlayDecider { default float getPriority() { return 0f; } + + /** + * Checks if REI should recalculate the overlay bounds + * + * @param location the location of the display panel + * @param rectangle the current overlay bounds + * @return whether REI should recalculate the overlay bounds + */ + default boolean shouldRecalculateArea(DisplayPanelLocation location, Rectangle rectangle) { + return false; + } + + /** + * Checks if mouse is inside the overlay + * + * @param mouseX mouse's x coordinates + * @param mouseY mouse's y coordinates + * @return whether mouse is inside the overlay + */ + default ActionResult isInZone(double mouseX, double mouseY) { + return PASS; + } } diff --git a/src/main/java/me/shedaniel/rei/api/REIHelper.java b/src/main/java/me/shedaniel/rei/api/REIHelper.java index a6ff10a8b..2a0dffc64 100644 --- a/src/main/java/me/shedaniel/rei/api/REIHelper.java +++ b/src/main/java/me/shedaniel/rei/api/REIHelper.java @@ -26,12 +26,15 @@ package me.shedaniel.rei.api; import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.gui.widget.TextFieldWidget; import me.shedaniel.rei.impl.ScreenHelper; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.gui.screen.ingame.ContainerScreen; import net.minecraft.item.ItemStack; import org.jetbrains.annotations.Nullable; import java.util.List; +@Environment(EnvType.CLIENT) public interface REIHelper { /** diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index c1ddc3f13..fc6724634 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -25,6 +25,8 @@ package me.shedaniel.rei.api; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.gui.screen.ingame.ContainerScreen; import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeManager; @@ -37,6 +39,7 @@ import java.util.Optional; import java.util.function.Function; import java.util.function.Predicate; +@Environment(EnvType.CLIENT) public interface RecipeHelper { /** diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 6ab41d865..8a3cd5a6f 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -186,16 +186,14 @@ public class ContainerScreenOverlay extends WidgetWithBounds { this.renderWeatherMenu = false; this.weatherButton = null; this.window = MinecraftClient.getInstance().getWindow(); - @SuppressWarnings({"RawTypeCanBeGeneric", "rawtypes"}) - DisplayHelper.DisplayBoundsHandler boundsHandler = DisplayHelper.getInstance().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); - this.bounds = ConfigObject.getInstance().isLeftHandSidePanel() ? boundsHandler.getLeftBounds(MinecraftClient.getInstance().currentScreen) : boundsHandler.getRightBounds(MinecraftClient.getInstance().currentScreen); + this.bounds = DisplayHelper.getInstance().getOverlayBounds(ConfigObject.getInstance().getDisplayPanelLocation(), MinecraftClient.getInstance().currentScreen); widgets.add(ENTRY_LIST_WIDGET); if (ConfigObject.getInstance().isFavoritesEnabled()) { if (favoritesListWidget == null) favoritesListWidget = new FavoritesListWidget(); widgets.add(favoritesListWidget); } - ENTRY_LIST_WIDGET.updateArea(boundsHandler, ScreenHelper.getSearchField() == null ? "" : null); + ENTRY_LIST_WIDGET.updateArea(ScreenHelper.getSearchField() == null ? "" : null); if (ScreenHelper.getSearchField() == null) { ScreenHelper.setSearchField(new OverlaySearchField(0, 0, 0, 0)); } @@ -437,15 +435,13 @@ public class ContainerScreenOverlay extends WidgetWithBounds { return new Rectangle(bounds.x + 2, window.getScaledHeight() - 22, bounds.width - 6 - widthRemoved, 18); if (searchFieldLocation == SearchFieldLocation.TOP_SIDE) return new Rectangle(bounds.x + 2, 4, bounds.width - 6 - widthRemoved, 18); - if (MinecraftClient.getInstance().currentScreen instanceof RecipeViewingScreen) { - RecipeViewingScreen widget = (RecipeViewingScreen) MinecraftClient.getInstance().currentScreen; - return new Rectangle(widget.getBounds().x, window.getScaledHeight() - 22, widget.getBounds().width - widthRemoved, 18); - } - if (MinecraftClient.getInstance().currentScreen instanceof VillagerRecipeViewingScreen) { - VillagerRecipeViewingScreen widget = (VillagerRecipeViewingScreen) MinecraftClient.getInstance().currentScreen; - return new Rectangle(widget.bounds.x, window.getScaledHeight() - 22, widget.bounds.width - widthRemoved, 18); + for (OverlayDecider decider : DisplayHelper.getInstance().getSortedOverlayDeciders(MinecraftClient.getInstance().currentScreen.getClass())) { + if (decider instanceof DisplayHelper.DisplayBoundsProvider) { + Rectangle containerBounds = ((DisplayHelper.DisplayBoundsProvider<Screen>) decider).getScreenBounds(MinecraftClient.getInstance().currentScreen); + return new Rectangle(containerBounds.x, window.getScaledHeight() - 22, containerBounds.width - widthRemoved, 18); + } } - return new Rectangle(REIHelper.getInstance().getPreviousContainerScreen().x, window.getScaledHeight() - 22, REIHelper.getInstance().getPreviousContainerScreen().containerWidth - widthRemoved, 18); + return new Rectangle(); } private Rectangle getCraftableToggleArea() { @@ -482,8 +478,8 @@ public class ContainerScreenOverlay extends WidgetWithBounds { ENTRY_LIST_WIDGET.updateSearch(ScreenHelper.getSearchField().getText(), true); init(); } else { - for (DisplayHelper.DisplayBoundsHandler<?> handler : DisplayHelper.getInstance().getSortedBoundsHandlers(minecraft.currentScreen.getClass())) { - if (handler != null && handler.shouldRecalculateArea(!ConfigObject.getInstance().isLeftHandSidePanel(), bounds)) { + for (OverlayDecider decider : DisplayHelper.getInstance().getSortedOverlayDeciders(minecraft.currentScreen.getClass())) { + if (decider != null && decider.shouldRecalculateArea(ConfigObject.getInstance().getDisplayPanelLocation(), bounds)) { init(); break; } @@ -760,8 +756,8 @@ public class ContainerScreenOverlay extends WidgetWithBounds { } public boolean isNotInExclusionZones(double mouseX, double mouseY) { - for (DisplayHelper.DisplayBoundsHandler<?> handler : DisplayHelper.getInstance().getSortedBoundsHandlers(MinecraftClient.getInstance().currentScreen.getClass())) { - ActionResult in = handler.isInZone(mouseX, mouseY); + for (OverlayDecider decider : DisplayHelper.getInstance().getSortedOverlayDeciders(MinecraftClient.getInstance().currentScreen.getClass())) { + ActionResult in = decider.isInZone(mouseX, mouseY); if (in != ActionResult.PASS) return in == ActionResult.SUCCESS; } diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 52efc96c3..12464c636 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -57,14 +57,16 @@ import net.minecraft.sound.SoundEvents; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; -import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Matrix4f; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.function.Supplier; @ApiStatus.Internal @@ -497,6 +499,9 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { if (choosePageActivated) { return recipeChoosePageWidget.mouseDragged(double_1, double_2, int_1, double_3, double_4); } + for (Element entry : children()) + if (entry.mouseDragged(double_1, double_2, int_1, double_3, double_4)) + return true; return super.mouseDragged(double_1, double_2, int_1, double_3, double_4); } @@ -505,6 +510,9 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { if (choosePageActivated) { return recipeChoosePageWidget.mouseReleased(double_1, double_2, int_1); } + for (Element entry : children()) + if (entry.mouseReleased(double_1, double_2, int_1)) + return true; return super.mouseReleased(double_1, double_2, int_1); } diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index 39bb93746..6d75f7d23 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -258,6 +258,13 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen scrollBarAlpha = 1; return true; } + for (Element entry : children()) + if (entry.mouseClicked(mouseX, mouseY, int_1)) { + setFocused(entry); + if (int_1 == 0) + setDragging(true); + return true; + } return super.mouseClicked(mouseX, mouseY, int_1); } @@ -354,12 +361,23 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen } @Override + public boolean mouseReleased(double double_1, double double_2, int int_1) { + for (Element entry : children()) + if (entry.mouseReleased(double_1, double_2, int_1)) + return true; + return super.mouseReleased(double_1, double_2, int_1); + } + + @Override public boolean mouseDragged(double mouseX, double mouseY, int int_1, double double_3, double double_4) { if (scrolling.mouseDragged(mouseX, mouseY, int_1, double_3, double_4)) { scrollBarAlphaFutureTime = System.currentTimeMillis(); scrollBarAlphaFuture = 1f; return true; } + for (Element entry : children()) + if (entry.mouseDragged(mouseX, mouseY, int_1, double_3, double_4)) + return true; return super.mouseDragged(mouseX, mouseY, int_1, double_3, double_4); } diff --git a/src/main/java/me/shedaniel/rei/gui/config/DisplayPanelLocation.java b/src/main/java/me/shedaniel/rei/gui/config/DisplayPanelLocation.java index a9022ff09..dae518740 100644 --- a/src/main/java/me/shedaniel/rei/gui/config/DisplayPanelLocation.java +++ b/src/main/java/me/shedaniel/rei/gui/config/DisplayPanelLocation.java @@ -24,15 +24,23 @@ package me.shedaniel.rei.gui.config; import me.shedaniel.clothconfig2.gui.entries.SelectionListEntry; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.resource.language.I18n; import org.jetbrains.annotations.NotNull; import java.util.Locale; +@Environment(EnvType.CLIENT) public enum DisplayPanelLocation implements SelectionListEntry.Translatable { LEFT, RIGHT; + public DisplayPanelLocation mirror() { + if (this == LEFT) return RIGHT; + return LEFT; + } + @Override public @NotNull String getKey() { return I18n.translate("config.roughlyenoughitems.accessibility.displayPanelLocation." + name().toLowerCase(Locale.ROOT)); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java index f06a1ac17..b079c0eb1 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java @@ -105,13 +105,17 @@ public class EntryListWidget extends WidgetWithBounds { return MathHelper.ceil(SIZE * ConfigObject.getInstance().getEntrySize()); } - @SuppressWarnings("rawtypes") static boolean notSteppingOnExclusionZones(int left, int top, Rectangle listArea) { MinecraftClient instance = MinecraftClient.getInstance(); - for (DisplayHelper.DisplayBoundsHandler sortedBoundsHandler : DisplayHelper.getInstance().getSortedBoundsHandlers(instance.currentScreen.getClass())) { - ActionResult fit = sortedBoundsHandler.canItemSlotWidgetFit(left, top, instance.currentScreen, listArea); - if (fit != ActionResult.PASS) + for (OverlayDecider decider : DisplayHelper.getInstance().getSortedOverlayDeciders(instance.currentScreen.getClass())) { + ActionResult fit = decider.isInZone(left, top); + if (fit == ActionResult.FAIL) return fit == ActionResult.SUCCESS; + ActionResult fit2 = decider.isInZone(left + 18, top + 18); + if (fit2 == ActionResult.FAIL) + return fit == ActionResult.SUCCESS; + if (fit == ActionResult.SUCCESS && fit2 == ActionResult.SUCCESS) + return true; } return true; } @@ -410,11 +414,11 @@ public class EntryListWidget extends WidgetWithBounds { return false; } - public void updateArea(DisplayHelper.DisplayBoundsHandler<?> boundsHandler, @Nullable String searchTerm) { - this.bounds = boundsHandler.getItemListArea(ScreenHelper.getLastOverlay().getBounds()); + public void updateArea(@Nullable String searchTerm) { + this.bounds = ScreenHelper.getItemListArea(ScreenHelper.getLastOverlay().getBounds()); FavoritesListWidget favoritesListWidget = ContainerScreenOverlay.getFavoritesListWidget(); if (favoritesListWidget != null) - favoritesListWidget.updateFavoritesBounds(boundsHandler, searchTerm); + favoritesListWidget.updateFavoritesBounds(searchTerm); if (searchTerm != null) updateSearch(searchTerm, true); else if (allStacks == null || (favoritesListWidget != null && favoritesListWidget.favorites == null)) diff --git a/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java index bda391df2..d3b66c117 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java @@ -179,9 +179,8 @@ public class FavoritesListWidget extends WidgetWithBounds { return false; } - @SuppressWarnings("rawtypes") - public void updateFavoritesBounds(DisplayHelper.DisplayBoundsHandler boundsHandler, @Nullable String searchTerm) { - this.bounds = boundsHandler.getFavoritesListArea(!ConfigObject.getInstance().isLeftHandSidePanel() ? boundsHandler.getLeftBounds(MinecraftClient.getInstance().currentScreen) : boundsHandler.getRightBounds(MinecraftClient.getInstance().currentScreen)); + public void updateFavoritesBounds(@Nullable String searchTerm) { + this.bounds = ScreenHelper.getFavoritesListArea(DisplayHelper.getInstance().getOverlayBounds(ConfigObject.getInstance().getDisplayPanelLocation().mirror(), MinecraftClient.getInstance().currentScreen)); } public void updateSearch(EntryListWidget listWidget, String searchTerm) { diff --git a/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java b/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java index 679041fa8..eacc92a96 100644 --- a/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java @@ -27,6 +27,9 @@ import com.google.common.collect.Lists; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.BaseBoundsHandler; import me.shedaniel.rei.api.DisplayHelper; +import me.shedaniel.rei.gui.config.DisplayPanelLocation; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.util.ActionResult; @@ -38,6 +41,7 @@ import java.util.List; import java.util.function.Supplier; @ApiStatus.Internal +@Environment(EnvType.CLIENT) public class BaseBoundsHandlerImpl implements BaseBoundsHandler { private static final Comparator<? super Rectangle> RECTANGLE_COMPARER = Comparator.comparingLong(Rectangle::hashCode); @@ -46,18 +50,8 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler { private List<Pair<Pair<Class<?>, Float>, Supplier<List<Rectangle>>>> list = Lists.newArrayList(); @Override - public Class<?> getBaseSupportedClass() { - return Screen.class; - } - - @Override - public Rectangle getLeftBounds(Screen screen) { - return new Rectangle(); - } - - @Override - public Rectangle getRightBounds(Screen screen) { - return new Rectangle(); + public boolean isHandingScreen(Class<?> screen) { + return Screen.class.isAssignableFrom(screen); } @Override @@ -78,30 +72,16 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler { } @Override - public boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) { - long current = currentHashCode(isOnRightSide); + public boolean shouldRecalculateArea(DisplayPanelLocation location, Rectangle rectangle) { + long current = currentHashCode(location); if (lastArea == current) return false; lastArea = current; return true; } - private long currentHashCode(boolean isOnRightSide) { - DisplayHelpe |
