diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-11-05 01:34:31 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-11-05 01:34:31 +0800 |
| commit | 94ff6aac084cfba2ce7eab00da76b7fe2992e657 (patch) | |
| tree | 99905bcb0501ebe1a1a9b2f6a8b5dffe53baf75b /runtime | |
| parent | 23e81b494b73f74c416ec3cf2147e6520608a258 (diff) | |
| parent | 987ee5269a9bc61b9ab4d07ea0986629b1421964 (diff) | |
| download | RoughlyEnoughItems-94ff6aac084cfba2ce7eab00da76b7fe2992e657.tar.gz RoughlyEnoughItems-94ff6aac084cfba2ce7eab00da76b7fe2992e657.tar.bz2 RoughlyEnoughItems-94ff6aac084cfba2ce7eab00da76b7fe2992e657.zip | |
Merge branch '6.x-1.17' into 7.x-1.18
# Conflicts:
# gradle.properties
Diffstat (limited to 'runtime')
18 files changed, 238 insertions, 84 deletions
diff --git a/runtime/build.gradle b/runtime/build.gradle index 76b4276b3..b77410d22 100644 --- a/runtime/build.gradle +++ b/runtime/build.gradle @@ -16,17 +16,13 @@ dependencies { modCompileOnly("net.fabricmc:fabric-loader:${project.fabricloader_version}") modApi("me.shedaniel.cloth:cloth-config:${cloth_config_version}") modApi("dev.architectury:architectury:${architectury_version}") - compileClasspath(project(path: ":api", configuration: "dev")) + compileClasspath(project(path: ":api", configuration: "namedElements")) } remapJar { remapAccessWidener = false } -configurations { - dev -} - remapJar { classifier "raw" } @@ -40,7 +36,6 @@ task fakeJar(type: Jar, dependsOn: remapJar) { } artifacts { - dev(jar) apiElements(fakeJar) runtimeElements(fakeJar) } 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/ScreenOverlayImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java index 04901ba45..bc53fca48 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java @@ -106,6 +106,7 @@ public class ScreenOverlayImpl extends ScreenOverlay { private static FavoritesListWidget favoritesListWidget = null; private final List<Widget> widgets = Lists.newLinkedList(); public boolean shouldReload = false; + public boolean shouldReloadSearch = false; private Rectangle bounds; private Window window; private Button leftButton, rightButton; @@ -207,6 +208,10 @@ public class ScreenOverlayImpl extends ScreenOverlay { shouldReload = true; } + public void queueReloadSearch() { + shouldReloadSearch = true; + } + @Override public DraggingContext<?> getDraggingContext() { return draggingStack; @@ -221,6 +226,7 @@ public class ScreenOverlayImpl extends ScreenOverlay { DraggableStackVisitor.from(() -> ScreenRegistry.getInstance().getDraggableVisitors())); this.shouldReload = false; + this.shouldReloadSearch = false; //Update Variables this.children().clear(); this.closeOverlayMenu(); @@ -469,7 +475,8 @@ public class ScreenOverlayImpl extends ScreenOverlay { } } } - if (ConfigManager.getInstance().isCraftableOnlyEnabled() && CraftableFilter.INSTANCE.wasDirty()) { + if (shouldReloadSearch || (ConfigManager.getInstance().isCraftableOnlyEnabled() && CraftableFilter.INSTANCE.wasDirty())) { + shouldReloadSearch = false; ENTRY_LIST_WIDGET.updateSearch(REIRuntimeImpl.getSearchField().getText(), true); } if (OverlaySearchField.isHighlighting) { 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.List; import java.util.Objects; import java.util.function.Supplier; @@ -68,7 +69,7 @@ import java.util.function.Supplier; public final class InternalWidgets { private InternalWidgets() {} - public static Widget createAutoCraftingButtonWidget(Rectangle displayBounds, Rectangle rectangle, Component text, Supplier<Display> displaySupplier, List<Widget> setupDisplay, DisplayCategory<?> category) { + public static Widget createAutoCraftingButtonWidget(Rectangle displayBounds, Rectangle rectangle, Component text, Supplier<Display> displaySupplier, Supplier<Collection<ResourceLocation>> idsSupplier, List<Widget> setupDisplay, DisplayCategory<?> category) { AbstractContainerScreen<?> containerScreen = REIRuntime.getInstance().getPreviousContainerScreen(); boolean[] visible = {false}; List<Component>[] errorTooltip = new List[]{null}; @@ -177,8 +178,18 @@ public final class InternalWidgets { str.add(errorTooltip[0].get(0).copy().withStyle(ChatFormatting.RED)); } } - if ((Minecraft.getInstance().options.advancedItemTooltips || Screen.hasShiftDown()) && displaySupplier.get().getDisplayLocation().isPresent()) { - str.add(new TranslatableComponent("text.rei.recipe_id", "", new TextComponent(displaySupplier.get().getDisplayLocation().get().toString()).withStyle(ChatFormatting.GRAY)).withStyle(ChatFormatting.GRAY)); + if (Minecraft.getInstance().options.advancedItemTooltips || Screen.hasShiftDown()) { + Collection<ResourceLocation> locations = idsSupplier.get(); + if (!locations.isEmpty()) { + str.add(new TextComponent(" ")); + for (ResourceLocation location : locations) { + String t = I18n.get("text.rei.recipe_id", "", new TextComponent(location.toString()).withStyle(ChatFormatting.GRAY)); + if (t.startsWith("\n")) { + t = t.substring("\n".length()); + } + str.add(new TextComponent(t).withStyle(ChatFormatting.GRAY)); + } + } } return str.toArray(new Component[0]); }); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java index 0710d0a17..a76cce52f 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java @@ -36,6 +36,7 @@ import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.client.view.Views; 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.entry.EntryIngredient; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.plugins.PluginManager; @@ -47,8 +48,10 @@ import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryIngredients; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.client.gui.craftable.CraftableFilter; +import me.shedaniel.rei.impl.display.DisplaySpec; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.AbstractContainerMenu; import org.jetbrains.annotations.ApiStatus; @@ -58,7 +61,7 @@ import java.util.stream.Collectors; @ApiStatus.Internal public class ViewsImpl implements Views { - public static Map<DisplayCategory<?>, List<Display>> buildMapFor(ViewSearchBuilder builder) { + public static Map<DisplayCategory<?>, List<DisplaySpec>> buildMapFor(ViewSearchBuilder builder) { if (PluginManager.areAnyReloading()) { RoughlyEnoughItemsCore.LOGGER.info("Cancelled Views buildMap since plugins have not finished reloading."); return Maps.newLinkedHashMap(); @@ -155,6 +158,76 @@ public class ViewsImpl implements Views { generateLiveDisplays(displayRegistry, generator, builder, displayConsumer); } + Map<DisplayCategory<?>, List<DisplaySpec>> resultSpeced = (Map<DisplayCategory<?>, List<DisplaySpec>>) (Map) new LinkedHashMap<>(result); + // optimize displays + if (ConfigObject.getInstance().doMergeDisplayUnderOne()) { + for (Map.Entry<DisplayCategory<?>, List<Display>> entry : result.entrySet()) { + DisplayMerger<Display> merger = (DisplayMerger<Display>) entry.getKey().getDisplayMerger(); + + if (merger != null) { + class Wrapped implements DisplaySpec { + private Display display; + private List<ResourceLocation> ids = null; + + public Wrapped(Display display) { + this.display = display; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Wrapped)) return false; + Wrapped wrapped = (Wrapped) o; + return merger.canMerge(display, wrapped.display); + } + + @Override + public int hashCode() { + return merger.hashOf(display); + } + + @Override + public Display provideInternalDisplay() { + return display; + } + + @Override + public Collection<ResourceLocation> provideInternalDisplayIds() { + if (ids == null) { + ids = new ArrayList<>(); + Optional<ResourceLocation> location = display.getDisplayLocation(); + if (location.isPresent()) { + ids.add(location.get()); + } + } + return ids; + } + + public void add(Display display) { + Optional<ResourceLocation> location = display.getDisplayLocation(); + if (location.isPresent()) { + provideInternalDisplayIds().add(location.get()); + } + } + } + Map<Wrapped, Wrapped> wrappedSet = new LinkedHashMap<>(); + List<Wrapped> wrappeds = new ArrayList<>(); + + for (Display display : entry.getValue()) { + Wrapped wrapped = new Wrapped(display); + if (wrappedSet.containsKey(wrapped)) { + wrappedSet.get(wrapped).add(display); + } else { + wrappedSet.put(wrapped, wrapped); + wrappeds.add(wrapped); + } + } + + resultSpeced.put(entry.getKey(), (List<DisplaySpec>) (List) wrappeds); + } + } + } + String message = String.format("Built Recipe View in %s for %d categories, %d recipes for, %d usages for and %d live recipe generators.", stopwatch.stop(), categories.size(), recipesFor.size(), usagesFor.size(), generatorsCount); if (ConfigObject.getInstance().doDebugSearchTimeRequired()) { @@ -162,7 +235,7 @@ public class ViewsImpl implements Views { } else { RoughlyEnoughItemsCore.LOGGER.trace(message); } - return result; + return resultSpeced; } private static <T extends Display> void generateLiveDisplays(DisplayRegistry displayRegistry, DynamicDisplayGenerator<T> generator, ViewSearchBuilder builder, Consumer<T> displayConsumer) { @@ -207,44 +280,46 @@ public class ViewsImpl implements Views { AbstractContainerMenu menu = Minecraft.getInstance().player.containerMenu; Set<EntryStack<?>> craftables = new HashSet<>(); for (Map.Entry<CategoryIdentifier<?>, List<Display>> entry : DisplayRegistry.getInstance().getAll().entrySet()) { - MenuInfo<AbstractContainerMenu, Display> info = menu != null ? - (MenuInfo<AbstractContainerMenu, Display>) MenuInfoRegistry.getInstance().get(entry.getKey(), menu.getClass()) - : null; - - |
