From 1b33b3e72c1b2bdb5b733bb5afe6b478367c77e5 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 2 Nov 2021 11:09:14 +0800 Subject: Fix searching craft but does search the modid because other mods add that --- fabric/src/main/resources/roughlyenoughitems.accessWidener | 1 - .../shedaniel/rei/impl/common/entry/AbstractEntryStack.java | 13 ++++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fabric/src/main/resources/roughlyenoughitems.accessWidener b/fabric/src/main/resources/roughlyenoughitems.accessWidener index e9d33d153..3be86e69f 100644 --- a/fabric/src/main/resources/roughlyenoughitems.accessWidener +++ b/fabric/src/main/resources/roughlyenoughitems.accessWidener @@ -26,7 +26,6 @@ accessible field net/minecraft/world/item/crafting/UpgradeRecipe accessible field net/minecraft/world/item/crafting/UpgradeRecipe base Lnet/minecraft/world/item/crafting/Ingredient; accessible field net/minecraft/world/item/CreativeModeTab langId Ljava/lang/String; accessible method net/minecraft/client/gui/GuiComponent innerBlit (Lcom/mojang/math/Matrix4f;IIIIIFFFF)V -accessible method net/minecraft/client/gui/screens/Screen addButton (Lnet/minecraft/client/gui/components/AbstractWidget;)Lnet/minecraft/client/gui/components/AbstractWidget; accessible method net/minecraft/client/gui/screens/Screen addWidget (Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener; accessible method net/minecraft/client/gui/screens/Screen init ()V accessible method net/minecraft/client/gui/screens/Screen insertText (Ljava/lang/String;Z)V diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java index 04f364c75..3e304f41e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java @@ -36,6 +36,7 @@ import me.shedaniel.rei.api.client.gui.Renderer; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.EntryStacks; +import me.shedaniel.rei.api.common.util.FormattingUtils; import me.shedaniel.rei.impl.client.util.CrashReportUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -52,6 +53,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.Iterator; @ApiStatus.Internal public abstract class AbstractEntryStack implements EntryStack, Renderer { @@ -184,11 +186,20 @@ public abstract class AbstractEntryStack implements EntryStack, Renderer { tooltip.getValue().addAllTexts(get(Settings.TOOLTIP_APPEND_EXTRA).apply(this)); tooltip.setValue(get(Settings.TOOLTIP_PROCESSOR).apply(this, tooltip.getValue())); if (tooltip.getValue() == null) return null; + ResourceLocation location = getIdentifier(); if (appendModName) { - ResourceLocation location = getIdentifier(); if (location != null) { ClientHelper.getInstance().appendModIdToTooltips(tooltip.getValue(), location.getNamespace()); } + } else { + final String modName = ClientHelper.getInstance().getModFromModId(location.getNamespace()); + Iterator iterator = tooltip.getValue().entries().iterator(); + while (iterator.hasNext()) { + Tooltip.Entry s = iterator.next(); + if (s.isText() && FormattingUtils.stripFormatting(s.getAsText().getString()).equalsIgnoreCase(modName)) { + iterator.remove(); + } + } } return tooltip.getValue(); } catch (Throwable throwable) { -- cgit From b817b2ad84966370a4adf48a192827d8de100b46 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 2 Nov 2021 12:04:25 +0800 Subject: Add option to merge displays --- .../rei/api/client/config/ConfigObject.java | 2 + .../client/registry/display/DisplayCategory.java | 24 +++++++ .../rei/api/client/view/ViewSearchBuilder.java | 20 ++++-- .../shedaniel/rei/api/common/display/Display.java | 23 ++++++- .../rei/api/common/display/DisplayMerger.java | 30 +++++++++ .../me/shedaniel/rei/impl/display/DisplaySpec.java | 39 +++++++++++ .../crafting/DefaultCraftingCategory.java | 19 ++++-- .../rei/impl/client/ClientHelperImpl.java | 15 +++-- .../rei/impl/client/config/ConfigObjectImpl.java | 6 ++ .../gui/screen/AbstractDisplayViewingScreen.java | 5 +- .../gui/screen/CompositeDisplayViewingScreen.java | 17 ++--- .../gui/screen/DefaultDisplayViewingScreen.java | 21 +++--- .../impl/client/gui/widget/InternalWidgets.java | 17 ++++- .../shedaniel/rei/impl/client/view/ViewsImpl.java | 77 +++++++++++++++++++++- .../assets/roughlyenoughitems/lang/en_us.json | 1 + 15 files changed, 273 insertions(+), 43 deletions(-) create mode 100644 api/src/main/java/me/shedaniel/rei/api/common/display/DisplayMerger.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/display/DisplaySpec.java 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 extends Identifiable { CategoryIdentifier getCategoryIdentifier(); + @Nullable + default DisplayMerger getDisplayMerger() { + return null; + } + + static DisplayMerger getContentMerger() { + return new DisplayMerger() { + @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, List> buildMap(); + @Deprecated + @ApiStatus.ScheduledForRemoval + default Map, List> buildMap() { + Map, List> map = new HashMap<>(); + for (Map.Entry, List> entry : buildMapInternal().entrySet()) { + map.put(entry.getKey(), CollectionUtils.map(entry.getValue(), DisplaySpec::provideInternalDisplay)); + } + return map; + } + + @ApiStatus.Internal + Map, List> 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 getDisplayLocation() { return Optional.empty(); } + + @Override + @ApiStatus.NonExtendable + default Display provideInternalDisplay() { + return this; + } + + @Override + @ApiStatus.NonExtendable + default Collection provideInternalDisplayIds() { + Optional 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 { + 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 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 { +public class DefaultCraftingCategory implements TransferDisplayCategory> { @Override - public CategoryIdentifier getCategoryIdentifier() { + public CategoryIdentifier> getCategoryIdentifier() { return BuiltinPlugin.CRAFTING; } @@ -65,7 +68,7 @@ public class DefaultCraftingCategory implements TransferDisplayCategory setupDisplay(DefaultCraftingDisplay display, Rectangle bounds) { + public List setupDisplay(DefaultCraftingDisplay display, Rectangle bounds) { Point startPoint = new Point(bounds.getCenterX() - 58, bounds.getCenterY() - 27); List widgets = Lists.newArrayList(); widgets.add(Widgets.createRecipeBase(bounds)); @@ -89,9 +92,9 @@ public class DefaultCraftingCategory implements TransferDisplayCategory widgets, Rectangle bounds, DefaultCraftingDisplay display, IntList redSlots) { + public void renderRedSlots(PoseStack matrices, List 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 info = (MenuInfo) MenuInfoRegistry.getInstance().get(getCategoryIdentifier(), containerMenu.getClass()); @@ -109,4 +112,10 @@ public class DefaultCraftingCategory implements TransferDisplayCategory> 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, List> map, @Nullable CategoryIdentifier category, List> ingredientNotice, List> resultNotice) { + public void openRecipeViewingScreen(Map, List> map, @Nullable CategoryIdentifier category, List> ingredientNotice, List> 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, List> map = builder.buildMap(); + Map, List> 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> usagesFor = new ArrayList<>(); @Nullable private CategoryIdentifier preferredOpenedCategory = null; - private final Supplier, List>> map = Suppliers.memoize(() -> ViewsImpl.buildMapFor(this)); + private final Supplier, List>> map = Suppliers.memoize(() -> ViewsImpl.buildMapFor(this)); @Override public ViewSearchBuilder addCategory(CategoryIdentifier category) { @@ -369,14 +370,14 @@ public class ClientHelperImpl implements ClientHelper { } @Override - public Map, List> buildMap() { + public Map, List> buildMapInternal() { fillPreferredOpenedCategory(); return this.map.get(); } } public static final class LegacyWrapperViewSearchBuilder extends AbstractViewSearchBuilder { - private final Map, List> map; + private final Map, List> map; @Nullable private EntryStack inputNotice; @Nullable @@ -384,7 +385,7 @@ public class ClientHelperImpl implements ClientHelper { @Nullable private CategoryIdentifier preferredOpenedCategory = null; - public LegacyWrapperViewSearchBuilder(Map, List> map) { + public LegacyWrapperViewSearchBuilder(Map, List> map) { this.map = map; } @@ -446,7 +447,7 @@ public class ClientHelperImpl implements ClientHelper { } @Override - public Map, List> buildMap() { + public Map, List> 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 @@ -221,6 +221,11 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { return advanced.layout.debugRenderTimeRequired; } + @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, List> categoryMap; + protected final Map, List> categoryMap; protected final List> categories; protected List> ingredientStackToNotice = new ArrayList<>(); protected List> resultStackToNotice = new ArrayList<>(); @@ -65,7 +66,7 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Dis protected int tabsPerPage; protected Rectangle bounds; - protected AbstractDisplayViewingScreen(Map, List> categoryMap, @Nullable CategoryIdentifier category, int tabsPerPage) { + protected AbstractDisplayViewingScreen(Map, List> 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, List> categoryMap, @Nullable CategoryIdentifier category) { + public CompositeDisplayViewingScreen(Map, List> 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 category = (DisplayCategory) 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 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 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, List> categoriesMap, @Nullable CategoryIdentifier category) { + public DefaultDisplayViewingScreen(Map, List> 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.mapAndMax(getCurrentDisplayed(), display -> getCurrentCategory().getDisplayWidth(display.provideInternalDisplay()), Comparator.naturalOrder()).orElse(150); int maxHeight = Math.min(largestHeight, CollectionUtils., 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 plusButtonArea = CategoryRegistry.getInstance().get(getCurrentCategoryId()).getPlusButtonArea(); int displayHeight = getCurrentCategory().getDisplayHeight(); - List currentDisplayed = getCurrentDisplayed(); + List currentDisplayed = getCurrentDisplayed(); for (int i = 0; i < currentDisplayed.size(); i++) { - final Display display = currentDisplayed.get(i); - final Supplier displaySupplier = () -> display; + final DisplaySpec display = currentDisplayed.get(i); + final Supplier 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 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 getCurrentDisplayed() { - List list = Lists.newArrayList(); + public List getCurrentDisplayed() { + List list = Lists.newArrayList(); int recipesPerPage = getRecipesPerPage(); - List displays = categoryMap.get(getCurrentCategory()); + List 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 displaySupplier, List setupDisplay, DisplayCategory category) { + public static Widget createAutoCraftingButtonWidget(Rectangle displayBounds, Rectangle rectangle, Component text, Supplier displaySupplier, Supplier> idsSupplier, List setupDisplay, DisplayCategory category) { AbstractContainerScreen containerScreen = REIRuntime.getInstance().getPreviousContainerScreen(); boolean[] visible = {false}; List[] 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 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..d5e73916d 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, List> buildMapFor(ViewSearchBuilder builder) { + public static Map, List> 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, List> resultSpeced = (Map, List>) (Map) new LinkedHashMap<>(result); + // optimize displays + if (ConfigObject.getInstance().doMergeDisplayUnderOne()) { + for (Map.Entry, List> entry : result.entrySet()) { + DisplayMerger merger = (DisplayMerger) entry.getKey().getDisplayMerger(); + + if (merger != null) { + class Wrapped implements DisplaySpec { + private Display display; + private List 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 provideInternalDisplayIds() { + if (ids == null) { + ids = new ArrayList<>(); + Optional location = display.getDisplayLocation(); + if (location.isPresent()) { + ids.add(location.get()); + } + } + return ids; + } + + public void add(Display display) { + Optional location = display.getDisplayLocation(); + if (location.isPresent()) { + provideInternalDisplayIds().add(location.get()); + } + } + } + Map wrappedSet = new LinkedHashMap<>(); + List 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) (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 void generateLiveDisplays(DisplayRegistry displayRegistry, DynamicDisplayGenerator generator, ViewSearchBuilder builder, Consumer displayConsumer) { diff --git a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json index c944215f0..d84b2e67d 100755 --- a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json +++ b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json @@ -167,6 +167,7 @@ "config.roughlyenoughitems.layout.configButtonLocation": "Config Button Position:", "config.roughlyenoughitems.layout.configButtonLocation.upper": "Upper", "config.roughlyenoughitems.layout.configButtonLocation.lower": "Lower", + "config.roughlyenoughitems.layout.mergeDisplayUnderOne": "Merge Displays with Equal Contents:", "config.roughlyenoughitems.filteredEntries.selectAll": "Select All", "config.roughlyenoughitems.filteredEntries.selectNone": "Unselect All", "config.roughlyenoughitems.filteredEntries.hide": "Hide Selected", -- cgit From cd43bc7766a7eb7e73aa82af06fb64f9701bb13b Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 2 Nov 2021 12:04:59 +0800 Subject: Update localizations --- .../main/resources/assets/roughlyenoughitems/lang/he_il.json | 10 ++++++++++ .../main/resources/assets/roughlyenoughitems/lang/zh_cn.json | 2 ++ .../main/resources/assets/roughlyenoughitems/lang/zh_tw.json | 2 ++ 3 files changed, 14 insertions(+) diff --git a/runtime/src/main/resources/assets/roughlyenoughitems/lang/he_il.json b/runtime/src/main/resources/assets/roughlyenoughitems/lang/he_il.json index 498e92a83..7a0ad52c7 100644 --- a/runtime/src/main/resources/assets/roughlyenoughitems/lang/he_il.json +++ b/runtime/src/main/resources/assets/roughlyenoughitems/lang/he_il.json @@ -96,6 +96,7 @@ "tooltip.rei.drag_to_add_favorites": "תגרור את זה למעה כדי להוסיף את זה לרשימת הפריטים השמורים!", "msg.rei.copied_recipe_id": "העתיק זהות מתכון", "msg.rei.recipe_id_details": "זהות מתכון: %s", + "msg.rei.exported_recipe": "מתכון מיוצא", "subsets.rei.roughlyenoughitems.item_groups": "כרטיסייות מצב יצירתי", "config.roughlyenoughitems.title": "קונפיגורציה REI", "config.roughlyenoughitems.basics": "בסיסים", @@ -113,17 +114,22 @@ "config.roughlyenoughitems.keyBindings.copyRecipeIdentifierKeybind": "העתק זהות מתכון:", "config.roughlyenoughitems.keyBindings.previousScreenKeybind": "מסך קודם:", "config.roughlyenoughitems.cheatingStyle": "סטייל של רמאות:", + "config.roughlyenoughitems.cheatingStyle.grab": "תפוס", "config.roughlyenoughitems.cheatingStyle.give": "תן", "config.roughlyenoughitems.motion": "הגדרות אנימציה / תזוזה", + "config.roughlyenoughitems.motion.configScreenAnimation": "מסך קונפיגורציה מונפש:", "config.roughlyenoughitems.motion.creditsScreenAnimation": "מסך קרדיטים מונפש:", "config.roughlyenoughitems.motion.favoritesAnimation": "רשימת פריטים שמורים מונפשת:", "config.roughlyenoughitems.recipeScreenType": "סוג מסך מתכון:", "config.roughlyenoughitems.recipeScreenType.config": "סוג מסך מתכון: %s", "config.roughlyenoughitems.recipeScreenType.unset": "לא נקבע", "config.roughlyenoughitems.recipeScreenType.original": "ברירת מחדל", + "config.roughlyenoughitems.layout": "פריסה", + "config.roughlyenoughitems.tooltips": "תאורים", "config.roughlyenoughitems.accessibility": "נגישות", "config.roughlyenoughitems.search": "חיפוש", "config.roughlyenoughitems.commands": "פקודות", + "config.roughlyenoughitems.filtering": "סינון", "config.roughlyenoughitems.miscellaneous": "שונות", "config.roughlyenoughitems.miscellaneous.clickableRecipeArrows": "חצי מתכונים לחיצים", "config.roughlyenoughitems.miscellaneous.renderEntryEnchantmentGlint": "הראה זהירת כישוף:", @@ -141,7 +147,9 @@ "config.roughlyenoughitems.recipeBorder.none": "כלום", "config.roughlyenoughitems.accessibility.displayPanelLocation.left": "צד שמאל", "config.roughlyenoughitems.accessibility.displayPanelLocation.right": "צד ימין", + "config.roughlyenoughitems.search.tooltipSearch": "חיפוש לפי תאורים (#):", "config.roughlyenoughitems.search.tagSearch": "חיפוש לפי תווית ($):", + "config.roughlyenoughitems.search.identifierSearch": "חיפוש לפי מזהה (*):", "config.roughlyenoughitems.search.modSearch": "חיפוש לפי מוד (@):", "config.roughlyenoughitems.search_mode.always": "תמיד פעיל", "config.roughlyenoughitems.search_mode.prefix": "כאשר משתמשים בקידומת", @@ -149,7 +157,9 @@ "config.roughlyenoughitems.layout.searchFieldLocation.bottom_side": "למטה בשמאל / ימין", "config.roughlyenoughitems.layout.searchFieldLocation.top_side": "למעלה בשמאל / ימין", "config.roughlyenoughitems.layout.searchFieldLocation.center": "באמצע", + "config.roughlyenoughitems.accessibility.compositeScrollBarPermanent": "דהיית סרגל הגלילה:", "config.roughlyenoughitems.accessibility.compositeScrollBarPermanent.boolean.true": "לעולם לא", + "config.roughlyenoughitems.accessibility.compositeScrollBarPermanent.boolean.false": "כאשר אינו פעיל", "config.roughlyenoughitems.disableRecipeBook": "ספר מתכונים של וונילה:", "config.roughlyenoughitems.disableRecipeBook.boolean.true": "§cלא", "config.roughlyenoughitems.disableRecipeBook.boolean.false": "§cכן", diff --git a/runtime/src/main/resources/assets/roughlyenoughitems/lang/zh_cn.json b/runtime/src/main/resources/assets/roughlyenoughitems/lang/zh_cn.json index 0256f54c9..88e977e97 100644 --- a/runtime/src/main/resources/assets/roughlyenoughitems/lang/zh_cn.json +++ b/runtime/src/main/resources/assets/roughlyenoughitems/lang/zh_cn.json @@ -47,6 +47,8 @@ "text.rei.cheat_items": "已将 {item_count} 个 [{item_name}§f] 给予 {player_name}", "text.rei.failed_cheat_items": "§c物品给予失败", "text.rei.too_long_nbt": "§c物品 NBT 太长,不能应用于多人游戏.", + "text.rei.tag_match": "标签: %s", + "text.rei.performance": "性能分析", "ordering.rei.ascending": "顺序", "ordering.rei.descending": "倒序", "ordering.rei.registry": "物品ID循序", diff --git a/runtime/src/main/resources/assets/roughlyenoughitems/lang/zh_tw.json b/runtime/src/main/resources/assets/roughlyenoughitems/lang/zh_tw.json index 38bcd4a00..c99289bbb 100644 --- a/runtime/src/main/resources/assets/roughlyenoughitems/lang/zh_tw.json +++ b/runtime/src/main/resources/assets/roughlyenoughitems/lang/zh_tw.json @@ -47,6 +47,8 @@ "text.rei.cheat_items": "已將 {item_count} 個 [{item_name}§f] 給予 {player_name}", "text.rei.failed_cheat_items": "§c給予物品失敗", "text.rei.too_long_nbt": "§c物品 NBT 過長,不能應用於多人遊戲。", + "text.rei.tag_match": "標籤: %s", + "text.rei.performance": "效能分析", "ordering.rei.ascending": "從 A 到 Z", "ordering.rei.descending": "從 Z 到 A", "ordering.rei.registry": "註冊名", -- cgit From 1fe450ebee9eaf803f98895969f2abf2202730e5 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 2 Nov 2021 12:05:18 +0800 Subject: Add 1.17.1 to CF versions --- fabric/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fabric/build.gradle b/fabric/build.gradle index f91ffc538..41387c5bd 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -110,6 +110,8 @@ curseforge { changelogType = "html" changelog = rootProject.releaseChangelog addGameVersion "1.17" + addGameVersion "1.17-Snapshot" + addGameVersion "1.17.1" addGameVersion "Fabric" relations { requiredDependency "architectury-fabric" -- cgit From b9ab61fe8a1c10f5adb61814ad9328b29727a37a Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 2 Nov 2021 16:06:10 +0800 Subject: Refactor MenuInfoProvider to give more concrete info --- api/build.gradle | 5 -- .../rei/api/common/transfer/info/MenuInfo.java | 4 ++ .../api/common/transfer/info/MenuInfoProvider.java | 40 ++++++++++++ .../api/common/transfer/info/MenuInfoRegistry.java | 16 ++++- .../transfer/info/MenuSerializationContext.java | 5 +- .../info/MenuSerializationProviderContext.java | 43 +++++++++++++ build.gradle | 2 +- default-plugin/build.gradle | 7 +-- fabric/build.gradle | 2 +- forge/build.gradle | 8 +-- runtime/build.gradle | 7 +-- .../shedaniel/rei/impl/client/view/ViewsImpl.java | 72 +++++++++++----------- .../rei/impl/common/transfer/InputSlotCrafter.java | 16 +++-- .../impl/common/transfer/MenuInfoRegistryImpl.java | 28 ++++++++- .../autocrafting/DefaultCategoryHandler.java | 2 +- 15 files changed, 189 insertions(+), 68 deletions(-) create mode 100644 api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationProviderContext.java diff --git a/api/build.gradle b/api/build.gradle index a38d48176..7939ee6a5 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -14,10 +14,6 @@ remapJar { remapAccessWidener = false } -configurations { - dev -} - remapJar { classifier "raw" } @@ -31,7 +27,6 @@ task fakeJar(type: Jar, dependsOn: remapJar) { } artifacts { - dev(jar) apiElements(fakeJar) runtimeElements(fakeJar) } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java index 313ab23de..b5ed1de67 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java @@ -34,6 +34,8 @@ import me.shedaniel.rei.api.common.transfer.info.clean.InputCleanHandler; import me.shedaniel.rei.api.common.transfer.info.simple.SimplePlayerInventoryMenuInfo; import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessor; import me.shedaniel.rei.api.common.util.CollectionUtils; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.inventory.AbstractContainerMenu; @@ -109,6 +111,7 @@ public interface MenuInfo ex * @throws MenuTransferException the exception to throw if something is wrong, * this exception should be caught by the invoker */ + @Environment(EnvType.CLIENT) default void validate(MenuInfoContext context) throws MenuTransferException { } @@ -133,6 +136,7 @@ public interface MenuInfo ex * @return the {@link CompoundTag} serialized */ default CompoundTag save(MenuSerializationContext context, D display) { + // TODO Remove this, replace with getDisplay() return DisplaySerializerRegistry.getInstance().save(display, new CompoundTag()); } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoProvider.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoProvider.java index 393a6cab6..904c59dd4 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoProvider.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoProvider.java @@ -25,7 +25,12 @@ package me.shedaniel.rei.api.common.transfer.info; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +import org.jetbrains.annotations.ApiStatus; import java.util.Optional; @@ -37,5 +42,40 @@ import java.util.Optional; */ @FunctionalInterface public interface MenuInfoProvider { + @Environment(EnvType.CLIENT) + default Optional> provideClient(D display, T menu) { + return provide((CategoryIdentifier) display.getCategoryIdentifier(), (Class) menu.getClass()); + } + + default Optional> provide(CategoryIdentifier display, T menu, MenuSerializationProviderContext context, CompoundTag networkTag) { + Optional> menuInfo = provide(display, (Class) menu.getClass()); + if (menuInfo.isPresent()) { + menuInfo.get().read(new MenuSerializationContext() { + @Override + public MenuInfo getContainerInfo() { + return menuInfo.get(); + } + + @Override + public T getMenu() { + return context.getMenu(); + } + + @Override + public Player getPlayerEntity() { + return context.getPlayerEntity(); + } + + @Override + public CategoryIdentifier getCategoryIdentifier() { + return context.getCategoryIdentifier(); + } + }, networkTag); + } + return menuInfo; + } + + @Deprecated + @ApiStatus.ScheduledForRemoval Optional> provide(CategoryIdentifier categoryId, Class menuClass); } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoRegistry.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoRegistry.java index bd1b14ff6..fdb83fb30 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoRegistry.java @@ -28,7 +28,11 @@ import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.plugins.REIServerPlugin; import me.shedaniel.rei.api.common.registry.Reloadable; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.inventory.AbstractContainerMenu; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.function.Predicate; @@ -45,7 +49,17 @@ public interface MenuInfoRegistry extends Reloadable { void registerGeneric(Predicate> categoryPredicate, MenuInfoProvider menuInfo); - @Nullable MenuInfo get(CategoryIdentifier category, Class menuClass); + @Nullable + @ApiStatus.ScheduledForRemoval + @Deprecated + MenuInfo get(CategoryIdentifier category, Class menuClass); + + @Nullable + @Environment(EnvType.CLIENT) + MenuInfo getClient(D display, C menu); + + @Nullable + MenuInfo get(CategoryIdentifier category, C menu, MenuSerializationProviderContext context, CompoundTag tag); int infoSize(); } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationContext.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationContext.java index 7a335c064..b3ed73d5f 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationContext.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationContext.java @@ -34,12 +34,15 @@ import net.minecraft.world.inventory.AbstractContainerMenu; * @param the type of {@link AbstractContainerMenu} * @param

the type of {@link Player}, server sided contexts may pass {@link net.minecraft.server.level.ServerPlayer} instead */ -public interface MenuSerializationContext { +public interface MenuSerializationContext extends MenuSerializationProviderContext { + @Override T getMenu(); + @Override P getPlayerEntity(); MenuInfo getContainerInfo(); + @Override CategoryIdentifier getCategoryIdentifier(); } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationProviderContext.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationProviderContext.java new file mode 100644 index 000000000..19a8cb78a --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationProviderContext.java @@ -0,0 +1,43 @@ +/* + * This file is li