diff options
15 files changed, 273 insertions, 43 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java index 791d2cd39..20165ffc1 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java @@ -111,6 +111,8 @@ public interface ConfigObject { boolean doDebugRenderTimeRequired(); + boolean doMergeDisplayUnderOne(); + ModifierKeyCode getFavoriteKeyCode(); ModifierKeyCode getRecipeKeybind(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategory.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategory.java index 5be94aa76..9202a18ca 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategory.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategory.java @@ -31,12 +31,14 @@ import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.gui.widgets.Widgets; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.api.common.display.DisplayMerger; import me.shedaniel.rei.api.common.util.Identifiable; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -119,6 +121,28 @@ public interface DisplayCategory<T extends Display> extends Identifiable { CategoryIdentifier<? extends T> getCategoryIdentifier(); + @Nullable + default DisplayMerger<T> getDisplayMerger() { + return null; + } + + static <T extends Display> DisplayMerger<T> getContentMerger() { + return new DisplayMerger<T>() { + @Override + public boolean canMerge(T first, T second) { + if (!first.getCategoryIdentifier().equals(second.getCategoryIdentifier())) return false; + if (!first.getInputEntries().equals(second.getInputEntries())) return false; + if (!first.getOutputEntries().equals(second.getOutputEntries())) return false; + return true; + } + + @Override + public int hashOf(T display) { + return display.getCategoryIdentifier().hashCode() * 31 * 31 * 31 + display.getInputEntries().hashCode() * 31 * 31 + display.getOutputEntries().hashCode(); + } + }; + } + @Override default ResourceLocation getIdentifier() { return getCategoryIdentifier().getIdentifier(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java b/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java index 589970db9..9b8a7582c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java @@ -31,12 +31,11 @@ import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.ClientInternals; +import me.shedaniel.rei.impl.display.DisplaySpec; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; public interface ViewSearchBuilder { static ViewSearchBuilder builder() { @@ -66,7 +65,18 @@ public interface ViewSearchBuilder { @Nullable CategoryIdentifier<?> getPreferredOpenedCategory(); - Map<DisplayCategory<?>, List<Display>> buildMap(); + @Deprecated + @ApiStatus.ScheduledForRemoval + default Map<DisplayCategory<?>, List<Display>> buildMap() { + Map<DisplayCategory<?>, List<Display>> map = new HashMap<>(); + for (Map.Entry<DisplayCategory<?>, List<DisplaySpec>> entry : buildMapInternal().entrySet()) { + map.put(entry.getKey(), CollectionUtils.map(entry.getValue(), DisplaySpec::provideInternalDisplay)); + } + return map; + } + + @ApiStatus.Internal + Map<DisplayCategory<?>, List<DisplaySpec>> buildMapInternal(); default boolean open() { return ClientHelper.getInstance().openView(this); diff --git a/api/src/main/java/me/shedaniel/rei/api/common/display/Display.java b/api/src/main/java/me/shedaniel/rei/api/common/display/Display.java index 14db33133..1ee2515e3 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/display/Display.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/display/Display.java @@ -25,8 +25,12 @@ package me.shedaniel.rei.api.common.display; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.impl.display.DisplaySpec; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -37,7 +41,7 @@ import java.util.Optional; * @see me.shedaniel.rei.api.common.display.basic.BasicDisplay * @see me.shedaniel.rei.api.client.registry.display.DisplayRegistry */ -public interface Display { +public interface Display extends DisplaySpec { /** * @return a list of inputs */ @@ -72,4 +76,21 @@ public interface Display { default Optional<ResourceLocation> getDisplayLocation() { return Optional.empty(); } + + @Override + @ApiStatus.NonExtendable + default Display provideInternalDisplay() { + return this; + } + + @Override + @ApiStatus.NonExtendable + default Collection<ResourceLocation> provideInternalDisplayIds() { + Optional<ResourceLocation> location = getDisplayLocation(); + if (location.isPresent()) { + return Collections.singletonList(location.get()); + } else { + return Collections.emptyList(); + } + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/display/DisplayMerger.java b/api/src/main/java/me/shedaniel/rei/api/common/display/DisplayMerger.java new file mode 100644 index 000000000..e13e24cc1 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/common/display/DisplayMerger.java @@ -0,0 +1,30 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.common.display; + +public interface DisplayMerger<T extends Display> { + boolean canMerge(T first, T second); + + int hashOf(T display); +} diff --git a/api/src/main/java/me/shedaniel/rei/impl/display/DisplaySpec.java b/api/src/main/java/me/shedaniel/rei/impl/display/DisplaySpec.java new file mode 100644 index 000000000..399386a32 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/impl/display/DisplaySpec.java @@ -0,0 +1,39 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.display; + +import me.shedaniel.rei.api.common.display.Display; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Collection; + +@ApiStatus.Internal +public interface DisplaySpec { + @ApiStatus.Internal + Display provideInternalDisplay(); + + @ApiStatus.Internal + Collection<ResourceLocation> provideInternalDisplayIds(); +} diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/DefaultCraftingCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/DefaultCraftingCategory.java index 32bec42b1..fdedcff29 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/DefaultCraftingCategory.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/DefaultCraftingCategory.java @@ -32,8 +32,10 @@ import me.shedaniel.rei.api.client.gui.Renderer; import me.shedaniel.rei.api.client.gui.widgets.Slot; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.gui.widgets.Widgets; +import me.shedaniel.rei.api.client.registry.display.DisplayCategory; import me.shedaniel.rei.api.client.registry.display.TransferDisplayCategory; import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.DisplayMerger; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.plugin.common.BuiltinPlugin; @@ -44,13 +46,14 @@ import net.fabricmc.api.Environment; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.world.level.block.Blocks; +import org.jetbrains.annotations.Nullable; import java.util.List; @Environment(EnvType.CLIENT) -public class DefaultCraftingCategory implements TransferDisplayCategory<DefaultCraftingDisplay> { +public class DefaultCraftingCategory implements TransferDisplayCategory<DefaultCraftingDisplay<?>> { @Override - public CategoryIdentifier<? extends DefaultCraftingDisplay> getCategoryIdentifier() { + public CategoryIdentifier<? extends DefaultCraftingDisplay<?>> getCategoryIdentifier() { return BuiltinPlugin.CRAFTING; } @@ -65,7 +68,7 @@ public class DefaultCraftingCategory implements TransferDisplayCategory<DefaultC } @Override - public List<Widget> setupDisplay(DefaultCraftingDisplay display, Rectangle bounds) { + public List<Widget> setupDisplay(DefaultCraftingDisplay<?> display, Rectangle bounds) { Point startPoint = new Point(bounds.getCenterX() - 58, bounds.getCenterY() - 27); List<Widget> widgets = Lists.newArrayList(); widgets.add(Widgets.createRecipeBase(bounds)); @@ -89,9 +92,9 @@ public class DefaultCraftingCategory implements TransferDisplayCategory<DefaultC } @Override - public void renderRedSlots(PoseStack matrices, List<Widget> widgets, Rectangle bounds, DefaultCraftingDisplay display, IntList redSlots) { + public void renderRedSlots(PoseStack matrices, List<Widget> widgets, Rectangle bounds, DefaultCraftingDisplay<?> display, IntList redSlots) { // @Nullable -// Screen previousScreen = REIHelper.getInstance().getPreviousScreen(); +// Screen previousScreen = REIRuntime.getInstance().getPreviousScreen(); // if (!(previousScreen instanceof AbstractContainerScreen)) return; // AbstractContainerMenu containerMenu = ((AbstractContainerScreen<?>) previousScreen).getMenu(); // MenuInfo<AbstractContainerMenu, DefaultCraftingDisplay> info = (MenuInfo<AbstractContainerMenu, DefaultCraftingDisplay>) MenuInfoRegistry.getInstance().get(getCategoryIdentifier(), containerMenu.getClass()); @@ -109,4 +112,10 @@ public class DefaultCraftingCategory implements TransferDisplayCategory<DefaultC // } // matrices.popPose(); } + + @Override + @Nullable + public DisplayMerger<DefaultCraftingDisplay<?>> getDisplayMerger() { + return DisplayCategory.getContentMerger(); + } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java index 0a1e598ca..ee054dcd8 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java @@ -50,6 +50,7 @@ import me.shedaniel.rei.impl.client.gui.screen.CompositeDisplayViewingScreen; import me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen; import me.shedaniel.rei.impl.client.gui.screen.UncertainDisplayViewingScreen; import me.shedaniel.rei.impl.client.view.ViewsImpl; +import me.shedaniel.rei.impl.display.DisplaySpec; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -245,7 +246,7 @@ public class ClientHelperImpl implements ClientHelper { } @ApiStatus.Internal - public void openRecipeViewingScreen(Map<DisplayCategory<?>, List<Display>> map, @Nullable CategoryIdentifier<?> category, List<EntryStack<?>> ingredientNotice, List<EntryStack<?>> resultNotice) { + public void openRecipeViewingScreen(Map<DisplayCategory<?>, List<DisplaySpec>> map, @Nullable CategoryIdentifier<?> category, List<EntryStack<?>> ingredientNotice, List<EntryStack<?>> resultNotice) { LegacyWrapperViewSearchBuilder builder = new LegacyWrapperViewSearchBuilder(map); for (EntryStack<?> stack : ingredientNotice) { builder.addInputNotice(stack); @@ -258,7 +259,7 @@ public class ClientHelperImpl implements ClientHelper { @Override public boolean openView(ViewSearchBuilder builder) { - Map<DisplayCategory<?>, List<Display>> map = builder.buildMap(); + Map<DisplayCategory<?>, List<DisplaySpec>> map = builder.buildMapInternal(); if (map.isEmpty()) return false; Screen screen; if (ConfigObject.getInstance().getRecipeScreenType() == DisplayScreenType.COMPOSITE) { @@ -315,7 +316,7 @@ public class ClientHelperImpl implements ClientHelper { private final List<EntryStack<?>> usagesFor = new ArrayList<>(); @Nullable private CategoryIdentifier<?> preferredOpenedCategory = null; - private final Supplier<Map<DisplayCategory<?>, List<Display>>> map = Suppliers.memoize(() -> ViewsImpl.buildMapFor(this)); + private final Supplier<Map<DisplayCategory<?>, List<DisplaySpec>>> map = Suppliers.memoize(() -> ViewsImpl.buildMapFor(this)); @Override public ViewSearchBuilder addCategory(CategoryIdentifier<?> category) { @@ -369,14 +370,14 @@ public class ClientHelperImpl implements ClientHelper { } @Override - public Map<DisplayCategory<?>, List<Display>> buildMap() { + public Map<DisplayCategory<?>, List<DisplaySpec>> buildMapInternal() { fillPreferredOpenedCategory(); return this.map.get(); } } public static final class LegacyWrapperViewSearchBuilder extends AbstractViewSearchBuilder { - private final Map<DisplayCategory<?>, List<Display>> map; + private final Map<DisplayCategory<?>, List<DisplaySpec>> map; @Nullable private EntryStack<?> inputNotice; @Nullable @@ -384,7 +385,7 @@ public class ClientHelperImpl implements ClientHelper { @Nullable private CategoryIdentifier<?> preferredOpenedCategory = null; - public LegacyWrapperViewSearchBuilder(Map<DisplayCategory<?>, List<Display>> map) { + public LegacyWrapperViewSearchBuilder(Map<DisplayCategory<?>, List<DisplaySpec>> map) { this.map = map; } @@ -446,7 +447,7 @@ public class ClientHelperImpl implements ClientHelper { } @Override - public Map<DisplayCategory<?>, List<Display>> buildMap() { + public Map<DisplayCategory<?>, List<DisplaySpec>> buildMapInternal() { fillPreferredOpenedCategory(); return this.map; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java index fba1fd4c2..3895bc4fc 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java @@ -222,6 +222,11 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { } @Override + public boolean doMergeDisplayUnderOne() { + return advanced.layout.mergeDisplayUnderOne; + } + + @Override public ModifierKeyCode getFavoriteKeyCode() { return basics.keyBindings.favoriteKeybind == null ? ModifierKeyCode.unknown() : basics.keyBindings.favoriteKeybind; } @@ -495,6 +500,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @Comment("Declares the maximum amount of recipes displayed in a page if possible.") @ConfigEntry.BoundedDiscrete(min = 2, max = 99) private int maxRecipesPerPage = 3; @Comment("Declares whether entry rendering time should be debugged.") private boolean debugRenderTimeRequired = false; + @Comment("Merges displays with equal contents under 1 display.") private boolean mergeDisplayUnderOne = true; } public static class Accessibility { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java index c9015efa3..96d290a9a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java @@ -39,6 +39,7 @@ import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.client.ClientHelperImpl; import me.shedaniel.rei.impl.client.gui.widget.EntryWidget; +import me.shedaniel.rei.impl.display.DisplaySpec; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.events.GuiEventListener; @@ -57,7 +58,7 @@ import java.util.List; import java.util.Map; public abstract class AbstractDisplayViewingScreen extends Screen implements DisplayScreen { - protected final Map<DisplayCategory<?>, List<Display>> categoryMap; + protected final Map<DisplayCategory<?>, List<DisplaySpec>> categoryMap; protected final List<DisplayCategory<?>> categories; protected List<EntryStack<?>> ingredientStackToNotice = new ArrayList<>(); protected List<EntryStack<?>> resultStackToNotice = new ArrayList<>(); @@ -65,7 +66,7 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Dis protected int tabsPerPage; protected Rectangle bounds; - protected AbstractDisplayViewingScreen(Map<DisplayCategory<?>, List<Display>> categoryMap, @Nullable CategoryIdentifier<?> category, int tabsPerPage) { + protected AbstractDisplayViewingScreen(Map<DisplayCategory<?>, List<DisplaySpec>> categoryMap, @Nullable CategoryIdentifier<?> category, int tabsPerPage) { super(NarratorChatListener.NO_TITLE); this.categoryMap = categoryMap; this.categories = Lists.newArrayList(categoryMap.keySet()); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java index 115d44f3d..c207a44ab 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java @@ -50,6 +50,7 @@ import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.gui.widget.EntryWidget; import me.shedaniel.rei.impl.client.gui.widget.InternalWidgets; import me.shedaniel.rei.impl.client.gui.widget.TabWidget; +import me.shedaniel.rei.impl.display.DisplaySpec; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.events.GuiEventListener; @@ -95,7 +96,7 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen private long scrollBarAlphaFutureTime = -1; private int tabsPage = -1; - public CompositeDisplayViewingScreen(Map<DisplayCategory<?>, List<Display>> categoryMap, @Nullable CategoryIdentifier<?> category) { + public CompositeDisplayViewingScreen(Map<DisplayCategory<?>, List<DisplaySpec>> categoryMap, @Nullable CategoryIdentifier<?> category) { super(categoryMap, category, 8); } @@ -118,8 +119,8 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen int largestWidth = width - 100; int largestHeight = height - 40; DisplayCategory<Display> category = (DisplayCategory<Display>) categories.get(selectedCategoryIndex); - Display display = categoryMap.get(category).get(selectedRecipeIndex); - int guiWidth = Mth.clamp(category.getDisplayWidth(display) + 30, 0, largestWidth) + 100; + DisplaySpec display = categoryMap.get(category).get(selectedRecipeIndex); + int guiWidth = Mth.clamp(category.getDisplayWidth(display.provideInternalDisplay()) + 30, 0, largestWidth) + 100; int guiHeight = Mth.clamp(category.getDisplayHeight() + 40, 166, largestHeight); this.tabsPerPage = Math.max(5, Mth.floor((guiWidth - 20d) / tabSize)); if (this.tabsPage == -1) { @@ -153,10 +154,10 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen this.scrollListBounds = new Rectangle(bounds.x + 4, bounds.y + 17, 97 + 5, guiHeight - 17 - 7); this.widgets.add(Widgets.createSlotBase(scrollListBounds)); - Rectangle recipeBounds = new Rectangle(bounds.x + 100 + (guiWidth - 100) / 2 - category.getDisplayWidth(display) / 2, bounds.y + bounds.height / 2 - category.getDisplayHeight() / 2, category.getDisplayWidth(display), category.getDisplayHeight()); + Rectangle recipeBounds = new Rectangle(bounds.x + 100 + (guiWidth - 100) / 2 - category.getDisplayWidth(display.provideInternalDisplay()) / 2, bounds.y + bounds.height / 2 - category.getDisplayHeight() / 2, category.getDisplayWidth(display.provideInternalDisplay()), category.getDisplayHeight()); List<Widget> setupDisplay; try { - setupDisplay = category.setupDisplay(display, recipeBounds); + setupDisplay = category.setupDisplay(display.provideInternalDisplay(), recipeBounds); } catch (Throwable throwable) { throwable.printStackTrace(); setupDisplay = new ArrayList<>(); @@ -173,13 +174,13 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen this.widgets.addAll(setupDisplay); Optional<ButtonArea> supplier = CategoryRegistry.getInstance().get(category.getCategoryIdentifier()).getPlusButtonArea(); if (supplier.isPresent() && supplier.get().get(recipeBounds) != null) - this.widgets.add(InternalWidgets.createAutoCraftingButtonWidget(recipeBounds, supplier.get().get(recipeBounds), new TextComponent(supplier.get().getButtonText()), () -> display, setupDisplay, category)); + this.widgets.add(InternalWidgets.createAutoCraftingButtonWidget(recipeBounds, supplier.get().get(recipeBounds), new TextComponent(supplier.get().getButtonText()), display::provideInternalDisplay, display::provideInternalDisplayIds, setupDisplay, category)); int index = 0; - for (Display recipeDisplay : categoryMap.get(category)) { + for (DisplaySpec recipeDisplay : categoryMap.get(category)) { int finalIndex = index; DisplayRenderer displayRenderer; - displayRenderers.add(displayRenderer = category.getDisplayRenderer(recipeDisplay)); + displayRenderers.add(displayRenderer = category.getDisplayRenderer(recipeDisplay.provideInternalDisplay())); buttonList.add(Widgets.createButton(new Rectangle(bounds.x + 5, 0, displayRenderer.getWidth(), displayRenderer.getHeight()), NarratorChatListener.NO_TITLE) .onClick(button -> { selectedRecipeIndex = finalIndex; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java index 5e341d3b9..3478a2cc3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java @@ -56,6 +56,7 @@ import me.shedaniel.rei.impl.client.gui.widget.EntryWidget; import me.shedaniel.rei.impl.client.gui.widget.InternalWidgets; import me.shedaniel.rei.impl.client.gui.widget.TabWidget; import me.shedaniel.rei.impl.client.gui.widget.basewidgets.PanelWidget; +import me.shedaniel.rei.impl.display.DisplaySpec; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.events.GuiEventListener; @@ -89,7 +90,7 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { private Panel workingStationsBaseWidget; private Button recipeBack, recipeNext, categoryBack, categoryNext; - public DefaultDisplayViewingScreen(Map<DisplayCategory<?>, List<Display>> categoriesMap, @Nullable CategoryIdentifier<?> category) { + public DefaultDisplayViewingScreen(Map<DisplayCategory<?>, List<DisplaySpec>> categoriesMap, @Nullable CategoryIdentifier<?> category) { super(categoriesMap, category, 5); this.bounds = new Rectangle(0, 0, 176, 150); } @@ -155,7 +156,7 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { this.preWidgets.clear(); this.widgets.clear(); int largestHeight = Math.max(height - 34 - 30, 100); - int maxWidthDisplay = CollectionUtils.mapAndMax(getCurrentDisplayed(), getCurrentCategory()::getDisplayWidth, Comparator.naturalOrder()).orElse(150); + int maxWidthDisplay = CollectionUtils.<DisplaySpec, Integer>mapAndMax(getCurrentDisplayed(), display -> getCurrentCategory().getDisplayWidth(display.provideInternalDisplay()), Comparator.naturalOrder()).orElse(150); int maxHeight = Math.min(largestHeight, CollectionUtils.<DisplayCategory<?>, Integer>mapAndMax(categories, category -> (category.getDisplayHeight() + 4) * Math.max(1, Math.min(getRecipesPerPage(largestHeight, category) + 1, Math.max(categoryMap.get(category).size(), ConfigObject.getInstance().getMaxRecipePerPage()))) + 36, Comparator.naturalOrder()).orElse(66)); int totalDisplayHeight = (getCurrentCategory().getDisplayHeight() + 4) * Math.max(1, getRecipesPerPage(maxHeight, getCurrentCategory()) + 1) + 36; @@ -250,15 +251,15 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { private void initDisplays() { Optional<ButtonArea> plusButtonArea = CategoryRegistry.getInstance().get(getCurrentCategoryId()).getPlusButtonArea(); int displayHeight = getCurrentCategory().getDisplayHeight(); - List<Display> currentDisplayed = getCurrentDisplayed(); + List<DisplaySpec> currentDisplayed = getCurrentDisplayed(); for (int i = 0; i < currentDisplayed.size(); i++) { - final Display display = currentDisplayed.get(i); - final Supplier<Display> displaySupplier = () -> display; + final DisplaySpec display = currentDisplayed.get(i); + final Supplier<Display> displaySupplier = display::provideInternalDisplay; int displayWidth = getCurrentCategory().getDisplayWidth(displaySupplier.get()); final Rectangle displayBounds = new Rectangle(getBounds().getCenterX() - displayWidth / 2, getBounds().getCenterY() + 16 - displayHeight * (getRecipesPerPage() + 1) / 2 - 2 * (getRecipesPerPage() + 1) + displayHeight * i + 4 * i, displayWidth, displayHeight); List<Widget> setupDisplay; try { - setupDisplay = getCurrentCategory().setupDisplay(display, displayBounds); + setupDisplay = getCurrentCategory().setupDisplay(display.provideInternalDisplay(), displayBounds); } catch (Throwable throwable) { throwable.printStackTrace(); setupDisplay = new ArrayList<>(); @@ -275,7 +276,7 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { this.recipeBounds.put(displayBounds, setupDisplay); this.widgets.addAll(setupDisplay); if (plusButtonArea.isPresent() && plusButtonArea.get().get(displayBounds) != null) { - this.widgets.add(InternalWidgets.createAutoCraftingButtonWidget(displayBounds, plusButtonArea.get().get(displayBounds), new TextComponent(plusButtonArea.get().getButtonText()), displaySupplier, setupDisplay, getCurrentCategory())); + this.widgets.add(InternalWidgets.createAutoCraftingButtonWidget(displayBounds, plusButtonArea.get().get(displayBounds), new TextComponent(plusButtonArea.get().getButtonText()), displaySupplier, display::provideInternalDisplayIds, setupDisplay, getCurrentCategory())); } } } @@ -310,10 +311,10 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { return widgets; } - public List<Display> getCurrentDisplayed() { - List<Display> list = Lists.newArrayList(); + public List<DisplaySpec> getCurrentDisplayed() { + List<DisplaySpec> list = Lists.newArrayList(); int recipesPerPage = getRecipesPerPage(); - List<Display> displays = categoryMap.get(getCurrentCategory()); + List<DisplaySpec> displays = categoryMap.get(getCurrentCategory()); for (int i = 0; i <= recipesPerPage; i++) { if (page * (recipesPerPage + 1) + i < displays.size()) { list.add(displays.get(page * (recipesPerPage + 1) + i)); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java index 1529a9e4b..27e9e79a5 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java @@ -59,6 +59,7 @@ import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; import java.util.ArrayList; +import java.util.Collection; import java.util.Lis |
