diff --git a/Common/src/main/java/mezz/jei/common/config/IIngredientFilterConfig.java b/Common/src/main/java/mezz/jei/common/config/IIngredientFilterConfig.java index d8eae7a98..66f484791 100644 --- a/Common/src/main/java/mezz/jei/common/config/IIngredientFilterConfig.java +++ b/Common/src/main/java/mezz/jei/common/config/IIngredientFilterConfig.java @@ -19,5 +19,7 @@ public interface IIngredientFilterConfig { boolean getSearchModAliases(); + boolean getSearchIngredientAliases(); + boolean getSearchShortModNames(); } diff --git a/Common/src/main/java/mezz/jei/common/config/IngredientFilterConfig.java b/Common/src/main/java/mezz/jei/common/config/IngredientFilterConfig.java index 4a23acfa9..7a3957ae1 100644 --- a/Common/src/main/java/mezz/jei/common/config/IngredientFilterConfig.java +++ b/Common/src/main/java/mezz/jei/common/config/IngredientFilterConfig.java @@ -16,6 +16,7 @@ public class IngredientFilterConfig implements IIngredientFilterConfig { public final Supplier searchModIds; public final Supplier searchModAliases; public final Supplier searchShortModNames; + public final Supplier searchIngredientAliases; public IngredientFilterConfig(IConfigSchemaBuilder builder) { IConfigCategoryBuilder search = builder.addCategory("search"); @@ -57,13 +58,18 @@ public IngredientFilterConfig(IConfigSchemaBuilder builder) { searchModAliases = search.addBoolean( "SearchModAliases", true, - "Search mod aliases in addition to mod names" + "Search mod aliases (alternative names) that are added by plugins, in addition to mod names" ); searchShortModNames = search.addBoolean( "SearchShortModNames", true, "Search by the shorthand first letters of a mod's name" ); + searchIngredientAliases = search.addBoolean( + "SearchIngredientAliases", + true, + "Search ingredient aliases (alternative names) that are added by plugins, in addition to ingredient names" + ); } @Override @@ -106,6 +112,11 @@ public boolean getSearchModAliases() { return searchModAliases.get(); } + @Override + public boolean getSearchIngredientAliases() { + return searchIngredientAliases.get(); + } + @Override public boolean getSearchShortModNames() { return searchShortModNames.get(); diff --git a/Common/src/main/resources/assets/jei/lang/en_us.json b/Common/src/main/resources/assets/jei/lang/en_us.json index 604ef8ab7..34fcbaee7 100644 --- a/Common/src/main/resources/assets/jei/lang/en_us.json +++ b/Common/src/main/resources/assets/jei/lang/en_us.json @@ -10,6 +10,7 @@ "jei.tooltip.transfer": "Move Items", "jei.tooltip.recipe.tag": "Accepts tag: %s", "jei.tooltip.item.colors": "Colors: %s", + "jei.tooltip.item.search.aliases": "Search Aliases:", "jei.tooltip.shapeless.recipe": "Shapeless Recipe", "jei.tooltip.cheat.mode.button.enabled": "Cheat Mode enabled", "jei.tooltip.cheat.mode.how.to.disable.hotkey": "Press \"%s\" to toggle it.", @@ -201,5 +202,7 @@ "description.jei.wooden.door.3": "Wooden Doors can be opened/closed via redstone circuits.", "description.jei.debug.formatting.1": "Testing %s formatting replacements.", "description.jei.debug.formatting.2": "Testing %s %s formatting replacements.", - "description.jei.debug.formatting.3": "%s nested" + "description.jei.debug.formatting.3": "%s nested", + "jei.alias.panda.spawn.egg": "endangered", + "jei.alias.villager.spawn.egg": "HMMM" } diff --git a/CommonApi/src/main/java/mezz/jei/api/IModPlugin.java b/CommonApi/src/main/java/mezz/jei/api/IModPlugin.java index 9319c97c1..9d7405836 100644 --- a/CommonApi/src/main/java/mezz/jei/api/IModPlugin.java +++ b/CommonApi/src/main/java/mezz/jei/api/IModPlugin.java @@ -1,6 +1,7 @@ package mezz.jei.api; import mezz.jei.api.helpers.IPlatformFluidHelper; +import mezz.jei.api.registration.IIngredientAliasRegistration; import mezz.jei.api.registration.IModInfoRegistration; import mezz.jei.api.registration.IRuntimeRegistration; import mezz.jei.api.runtime.config.IJeiConfigManager; @@ -53,6 +54,17 @@ default void registerIngredients(IModIngredientRegistration registration) { } + /** + * Register search aliases for ingredients. + * + * @implNote If the player has disabled search aliases in the config, this will not be called. + * + * @since 19.10.0 + */ + default void registerIngredientAliases(IIngredientAliasRegistration registration) { + + } + /** * Register extra info about a mod, such as aliases for the mod that users can search for. * diff --git a/CommonApi/src/main/java/mezz/jei/api/registration/IIngredientAliasRegistration.java b/CommonApi/src/main/java/mezz/jei/api/registration/IIngredientAliasRegistration.java new file mode 100644 index 000000000..aab346f83 --- /dev/null +++ b/CommonApi/src/main/java/mezz/jei/api/registration/IIngredientAliasRegistration.java @@ -0,0 +1,79 @@ +package mezz.jei.api.registration; + +import mezz.jei.api.ingredients.IIngredientType; +import mezz.jei.api.ingredients.ITypedIngredient; + +import java.util.Collection; +import java.util.List; + +/** + * Allows registration of search aliases for ingredients. + * Search aliases allow mods to add alternative names for ingredients, to help players find them more easily. + * + * @since 19.10.0 + */ +public interface IIngredientAliasRegistration { + /** + * Register a search alias for an ingredient. + * An alias may be a translation key. + * + * @since 19.10.0 + */ + void addAlias(IIngredientType type, I ingredient, String alias); + + /** + * Register a search alias for an ingredient. + * An alias may be a translation key. + * + * @since 19.10.0 + */ + void addAlias(ITypedIngredient typedIngredient, String alias); + + /** + * Register multiple search aliases for an ingredient. + * An alias may be a translation key. + * + * @since 19.10.0 + */ + void addAliases(IIngredientType type, I ingredient, Collection aliases); + + /** + * Register multiple search aliases for an ingredient. + * An alias may be a translation key. + * + * @since 19.10.0 + */ + void addAliases(ITypedIngredient typedIngredient, Collection aliases); + + /** + * Register a search aliases for multiple ingredients. + * An alias may be a translation key. + * + * @since 19.10.0 + */ + void addAliases(IIngredientType type, Collection ingredients, String alias); + + /** + * Register a search aliases for multiple ingredients. + * An alias may be a translation key. + * + * @since 19.10.0 + */ + void addAliases(Collection> typedIngredients, String alias); + + /** + * Register multiple search aliases for multiple ingredients. + * An alias may be a translation key. + * + * @since 19.10.0 + */ + void addAliases(IIngredientType type, Collection ingredients, Collection aliases); + + /** + * Register multiple search aliases for multiple ingredients. + * An alias may be a translation key. + * + * @since 19.10.0 + */ + void addAliases(Collection> typedIngredients, Collection aliases); +} diff --git a/CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientManager.java b/CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientManager.java index aada9d6e9..c73e6cc78 100644 --- a/CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientManager.java +++ b/CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientManager.java @@ -11,6 +11,7 @@ import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes; import mezz.jei.api.ingredients.ITypedIngredient; import mezz.jei.api.ingredients.subtypes.UidContext; +import mezz.jei.api.registration.IIngredientAliasRegistration; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Unmodifiable; @@ -176,6 +177,16 @@ default Optional> createTypedIngredient(V ingredient) { @Deprecated(since = "19.9.0", forRemoval = true) Optional> getTypedIngredientByUid(IIngredientType ingredientType, String ingredientUuid); + /** + * Get localized search aliases for ingredients. + * Registered by mods with {@link IIngredientAliasRegistration#addAlias}. + * + * If search aliases are disabled by the player in the configs, this will return an empty collection. + * + * @since 19.10.0 + */ + Collection getIngredientAliases(ITypedIngredient ingredient); + /** * Add a listener to receive updates when ingredients are added or removed from the ingredient manager. * diff --git a/Gui/src/main/java/mezz/jei/gui/ingredients/IListElementInfo.java b/Gui/src/main/java/mezz/jei/gui/ingredients/IListElementInfo.java index ed4473fc6..b6cc7ac67 100644 --- a/Gui/src/main/java/mezz/jei/gui/ingredients/IListElementInfo.java +++ b/Gui/src/main/java/mezz/jei/gui/ingredients/IListElementInfo.java @@ -13,7 +13,7 @@ public interface IListElementInfo { - String getName(); + List getNames(); String getModNameForSorting(); @@ -39,5 +39,4 @@ public interface IListElementInfo { void setSortedIndex(int sortIndex); int getSortedIndex(); - } diff --git a/Gui/src/main/java/mezz/jei/gui/ingredients/IngredientSorterComparators.java b/Gui/src/main/java/mezz/jei/gui/ingredients/IngredientSorterComparators.java index 609e282ae..d32b584c0 100644 --- a/Gui/src/main/java/mezz/jei/gui/ingredients/IngredientSorterComparators.java +++ b/Gui/src/main/java/mezz/jei/gui/ingredients/IngredientSorterComparators.java @@ -72,7 +72,7 @@ private static Comparator> getCreativeMenuComparator() { } private static Comparator> getAlphabeticalComparator() { - return Comparator.comparing(IListElementInfo::getName); + return Comparator.comparing(i -> i.getNames().getFirst()); } private Comparator> getModNameComparator() { diff --git a/Gui/src/main/java/mezz/jei/gui/ingredients/ListElementInfo.java b/Gui/src/main/java/mezz/jei/gui/ingredients/ListElementInfo.java index 225edbad8..bf4d9728e 100644 --- a/Gui/src/main/java/mezz/jei/gui/ingredients/ListElementInfo.java +++ b/Gui/src/main/java/mezz/jei/gui/ingredients/ListElementInfo.java @@ -1,6 +1,5 @@ package mezz.jei.gui.ingredients; -import com.google.common.collect.ImmutableSet; import mezz.jei.api.helpers.IModIdHelper; import mezz.jei.api.ingredients.IIngredientHelper; import mezz.jei.api.ingredients.IIngredientRenderer; @@ -8,6 +7,7 @@ import mezz.jei.api.runtime.IIngredientManager; import mezz.jei.common.config.IIngredientFilterConfig; import mezz.jei.common.util.SafeIngredientUtil; +import mezz.jei.common.util.Translator; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.TooltipFlag; import org.apache.logging.log4j.LogManager; @@ -15,6 +15,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Locale; @@ -25,7 +26,7 @@ public class ListElementInfo implements IListElementInfo { private static final Logger LOGGER = LogManager.getLogger(); private final IListElement element; - private final String displayNameLowercase; + private final List names; private final List modIds; private final List modNames; private final ResourceLocation resourceLocation; @@ -36,7 +37,7 @@ public static IListElementInfo create(IListElement element, IIngredien ITypedIngredient value = element.getTypedIngredient(); IIngredientHelper ingredientHelper = ingredientManager.getIngredientHelper(value.getType()); try { - return new ListElementInfo<>(element, ingredientHelper, modIdHelper); + return new ListElementInfo<>(element, ingredientHelper, ingredientManager, modIdHelper); } catch (RuntimeException e) { try { String ingredientInfo = ingredientHelper.getErrorInfo(value.getIngredient()); @@ -48,7 +49,7 @@ public static IListElementInfo create(IListElement element, IIngredien } } - protected ListElementInfo(IListElement element, IIngredientHelper ingredientHelper, IModIdHelper modIdHelper) { + protected ListElementInfo(IListElement element, IIngredientHelper ingredientHelper, IIngredientManager ingredientManager, IModIdHelper modIdHelper) { this.element = element; ITypedIngredient value = element.getTypedIngredient(); V ingredient = value.getIngredient(); @@ -65,12 +66,24 @@ protected ListElementInfo(IListElement element, IIngredientHelper ingredie modIdHelper.getModNameForModId(displayModId) ); } - this.displayNameLowercase = DisplayNameUtil.getLowercaseDisplayNameForSearch(ingredient, ingredientHelper); + + String displayNameLowercase = DisplayNameUtil.getLowercaseDisplayNameForSearch(ingredient, ingredientHelper); + Collection aliases = ingredientManager.getIngredientAliases(value); + if (aliases.isEmpty()) { + this.names = List.of(displayNameLowercase); + } else { + this.names = new ArrayList<>(1 + aliases.size()); + this.names.add(displayNameLowercase); + for (String alias : aliases) { + String lowercaseAlias = Translator.toLowercaseWithLocale(alias); + this.names.add(lowercaseAlias); + } + } } @Override - public String getName() { - return this.displayNameLowercase; + public List getNames() { + return names; } @Override @@ -91,20 +104,20 @@ public List getModIds() { @Override @Unmodifiable public final Set getTooltipStrings(IIngredientFilterConfig config, IIngredientManager ingredientManager) { - String modName = this.modNames.getFirst(); - String modId = this.modIds.getFirst(); - String modNameLowercase = modName.toLowerCase(Locale.ENGLISH); ITypedIngredient value = element.getTypedIngredient(); IIngredientRenderer ingredientRenderer = ingredientManager.getIngredientRenderer(value.getType()); - ImmutableSet toRemove = ImmutableSet.of(modId, modNameLowercase, displayNameLowercase, resourceLocation.getPath()); TooltipFlag.Default tooltipFlag = config.getSearchAdvancedTooltips() ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL; tooltipFlag = tooltipFlag.asCreative(); ListElementInfoTooltip tooltip = new ListElementInfoTooltip(); SafeIngredientUtil.getTooltip(tooltip, ingredientManager, ingredientRenderer, value, tooltipFlag); - Set strings = tooltip.getStrings(); - strings.removeAll(toRemove); + + strings.remove(this.names.getFirst()); + strings.remove(this.modNames.getFirst().toLowerCase(Locale.ENGLISH)); + strings.remove(this.modIds.getFirst()); + strings.remove(resourceLocation.getPath()); + return strings; } diff --git a/Gui/src/main/java/mezz/jei/gui/overlay/IngredientGridTooltipHelper.java b/Gui/src/main/java/mezz/jei/gui/overlay/IngredientGridTooltipHelper.java index 238e85d22..f216d4ff9 100644 --- a/Gui/src/main/java/mezz/jei/gui/overlay/IngredientGridTooltipHelper.java +++ b/Gui/src/main/java/mezz/jei/gui/overlay/IngredientGridTooltipHelper.java @@ -15,6 +15,7 @@ import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; +import java.util.Collection; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -51,11 +52,33 @@ public void getIngredientTooltip( addColorSearchInfoToTooltip(tooltip, typedIngredient, ingredientHelper); } + if (ingredientFilterConfig.getSearchIngredientAliases()) { + addIngredientAliasesToTooltip(tooltip, typedIngredient, ingredientManager); + } + if (toggleState.isEditModeEnabled()) { addEditModeInfoToTooltip(tooltip, keyBindings); } } + private void addIngredientAliasesToTooltip(JeiTooltip tooltip, ITypedIngredient typedIngredient, IIngredientManager ingredientManager) { + Collection aliases = ingredientManager.getIngredientAliases(typedIngredient); + if (aliases.isEmpty()) { + return; + } + tooltip.add(Component.empty()); + tooltip.add( + Component.translatable("jei.tooltip.item.search.aliases") + .withStyle(ChatFormatting.GRAY) + ); + for (String alias : aliases) { + tooltip.add( + Component.literal("• " + alias) + .withStyle(ChatFormatting.GRAY) + ); + } + } + private void addColorSearchInfoToTooltip(JeiTooltip tooltip, ITypedIngredient typedIngredient, IIngredientHelper ingredientHelper) { Iterable colors = ingredientHelper.getColors(typedIngredient.getIngredient()); String colorNamesString = StreamSupport.stream(colors.spliterator(), false) diff --git a/Gui/src/main/java/mezz/jei/gui/search/ElementPrefixParser.java b/Gui/src/main/java/mezz/jei/gui/search/ElementPrefixParser.java index b9ee9bbe0..95bdf81d3 100644 --- a/Gui/src/main/java/mezz/jei/gui/search/ElementPrefixParser.java +++ b/Gui/src/main/java/mezz/jei/gui/search/ElementPrefixParser.java @@ -26,7 +26,7 @@ public class ElementPrefixParser { public static final PrefixInfo> NO_PREFIX = new PrefixInfo<>( '\0', () -> SearchMode.ENABLED, - i -> List.of(i.getName()), + IListElementInfo::getNames, GeneralizedSuffixTree::new ); private static final Pattern SPACE_PATTERN = Pattern.compile("\\s"); diff --git a/Library/src/main/java/mezz/jei/library/ingredients/IngredientInfo.java b/Library/src/main/java/mezz/jei/library/ingredients/IngredientInfo.java index a3f8b9faf..65234681c 100644 --- a/Library/src/main/java/mezz/jei/library/ingredients/IngredientInfo.java +++ b/Library/src/main/java/mezz/jei/library/ingredients/IngredientInfo.java @@ -5,6 +5,7 @@ import mezz.jei.api.ingredients.IIngredientRenderer; import mezz.jei.api.ingredients.IIngredientType; import mezz.jei.api.ingredients.subtypes.UidContext; +import mezz.jei.core.collect.ListMultiMap; import mezz.jei.library.load.registration.LegacyUidCodec; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; @@ -19,6 +20,7 @@ public class IngredientInfo { private final IIngredientRenderer ingredientRenderer; private final Codec ingredientCodec; private final IngredientSet ingredientSet; + private final ListMultiMap aliases; public IngredientInfo( IIngredientType ingredientType, @@ -39,6 +41,8 @@ public IngredientInfo( this.ingredientSet = new IngredientSet<>(ingredientHelper, UidContext.Ingredient); this.ingredientSet.addAll(ingredients); + + this.aliases = new ListMultiMap<>(); } public IIngredientType getIngredientType() { @@ -75,4 +79,20 @@ public void removeIngredients(Collection ingredients) { public Optional getIngredientByLegacyUid(String uid) { return ingredientSet.getByLegacyUid(uid); } + + @Unmodifiable + public Collection getIngredientAliases(T ingredient) { + Object uid = ingredientHelper.getUid(ingredient, UidContext.Ingredient); + return aliases.get(uid); + } + + public void addIngredientAlias(T ingredient, String alias) { + Object uid = ingredientHelper.getUid(ingredient, UidContext.Ingredient); + this.aliases.put(uid, alias); + } + + public void addIngredientAliases(T ingredient, Collection aliases) { + Object uid = ingredientHelper.getUid(ingredient, UidContext.Ingredient); + this.aliases.putAll(uid, aliases); + } } diff --git a/Library/src/main/java/mezz/jei/library/ingredients/IngredientManager.java b/Library/src/main/java/mezz/jei/library/ingredients/IngredientManager.java index a2f49938f..03877ec65 100644 --- a/Library/src/main/java/mezz/jei/library/ingredients/IngredientManager.java +++ b/Library/src/main/java/mezz/jei/library/ingredients/IngredientManager.java @@ -8,6 +8,7 @@ import mezz.jei.api.ingredients.ITypedIngredient; import mezz.jei.api.runtime.IIngredientManager; import mezz.jei.common.util.ErrorUtil; +import mezz.jei.common.util.Translator; import mezz.jei.core.util.WeakList; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -209,4 +210,19 @@ public Codec getIngredientCodec(IIngredientType ingredientType) { .getIngredientInfo(ingredientType) .getIngredientCodec(); } + + @Override + public Collection getIngredientAliases(ITypedIngredient ingredient) { + return getIngredientAliasesInternal(ingredient); + } + + private Collection getIngredientAliasesInternal(ITypedIngredient typedIngredient) { + return registeredIngredients + .getIngredientInfo(typedIngredient.getType()) + .getIngredientAliases(typedIngredient.getIngredient()) + .stream() + .map(Translator::translateToLocal) + .sorted(String::compareToIgnoreCase) + .toList(); + } } diff --git a/Library/src/main/java/mezz/jei/library/ingredients/RegisteredIngredients.java b/Library/src/main/java/mezz/jei/library/ingredients/RegisteredIngredients.java index 55640d71b..050315c63 100644 --- a/Library/src/main/java/mezz/jei/library/ingredients/RegisteredIngredients.java +++ b/Library/src/main/java/mezz/jei/library/ingredients/RegisteredIngredients.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.SequencedMap; import java.util.function.Function; import java.util.stream.Collectors; @@ -25,13 +26,12 @@ public class RegisteredIngredients { /** for looking up types with subtypes by base ingredient class */ private final Map, IIngredientTypeWithSubtypes> baseClassToType; - public RegisteredIngredients(List> ingredientInfoList) { - this.orderedTypes = ingredientInfoList.stream() + public RegisteredIngredients(SequencedMap, IngredientInfo> ingredientInfoList) { + this.orderedTypes = ingredientInfoList.sequencedValues().stream() .>map(IngredientInfo::getIngredientType) .toList(); - this.typeToInfo = ingredientInfoList.stream() - .collect(Collectors.toUnmodifiableMap(IngredientInfo::getIngredientType, Function.identity())); + this.typeToInfo = Map.copyOf(ingredientInfoList); this.classToType = this.orderedTypes.stream() .collect(Collectors.toMap(IIngredientType::getIngredientClass, Function.identity())); diff --git a/Library/src/main/java/mezz/jei/library/load/PluginLoader.java b/Library/src/main/java/mezz/jei/library/load/PluginLoader.java index 33c61551e..10ef1e56f 100644 --- a/Library/src/main/java/mezz/jei/library/load/PluginLoader.java +++ b/Library/src/main/java/mezz/jei/library/load/PluginLoader.java @@ -20,6 +20,7 @@ import mezz.jei.api.runtime.IJeiFeatures; import mezz.jei.api.runtime.IScreenHelper; import mezz.jei.common.Internal; +import mezz.jei.common.config.IIngredientFilterConfig; import mezz.jei.common.platform.IPlatformFluidHelperInternal; import mezz.jei.common.platform.Services; import mezz.jei.common.util.StackHelper; @@ -62,7 +63,12 @@ public class PluginLoader { private final IIngredientManager ingredientManager; private final JeiHelpers jeiHelpers; - public PluginLoader(StartData data, IModIdFormatConfig modIdFormatConfig, IColorHelper colorHelper) { + public PluginLoader( + StartData data, + IModIdFormatConfig modIdFormatConfig, + IIngredientFilterConfig ingredientFilterConfig, + IColorHelper colorHelper + ) { this.data = data; this.timer = new LoggedTimer(); @@ -78,11 +84,21 @@ public PluginLoader(StartData data, IModIdFormatConfig modIdFormatConfig, IColor IngredientManagerBuilder ingredientManagerBuilder = new IngredientManagerBuilder(subtypeManager, colorHelper); PluginCaller.callOnPlugins("Registering ingredients", plugins, p -> p.registerIngredients(ingredientManagerBuilder)); + + if (ingredientFilterConfig.getSearchIngredientAliases()) { + PluginCaller.callOnPlugins("Registering search ingredient aliases", plugins, p -> p.registerIngredientAliases(ingredientManagerBuilder)); + } + this.ingredientManager = ingredientManagerBuilder.build(); - ModInfoRegistration modInfoRegistration = new ModInfoRegistration(); - PluginCaller.callOnPlugins("Registering Mod Info", plugins, p -> p.registerModInfo(modInfoRegistration)); - ImmutableSetMultimap modAliases = modInfoRegistration.getModAliases(); + ImmutableSetMultimap modAliases; + if (ingredientFilterConfig.getSearchModAliases()) { + ModInfoRegistration modInfoRegistration = new ModInfoRegistration(); + PluginCaller.callOnPlugins("Registering Mod Info", plugins, p -> p.registerModInfo(modInfoRegistration)); + modAliases = modInfoRegistration.getModAliases(); + } else { + modAliases = ImmutableSetMultimap.of(); + } StackHelper stackHelper = new StackHelper(subtypeManager); GuiHelper guiHelper = new GuiHelper(ingredientManager); diff --git a/Library/src/main/java/mezz/jei/library/load/registration/IngredientManagerBuilder.java b/Library/src/main/java/mezz/jei/library/load/registration/IngredientManagerBuilder.java index c7d07dafe..f11917fa9 100644 --- a/Library/src/main/java/mezz/jei/library/load/registration/IngredientManagerBuilder.java +++ b/Library/src/main/java/mezz/jei/library/load/registration/IngredientManagerBuilder.java @@ -6,7 +6,9 @@ import mezz.jei.api.ingredients.IIngredientHelper; import mezz.jei.api.ingredients.IIngredientRenderer; import mezz.jei.api.ingredients.IIngredientType; +import mezz.jei.api.ingredients.ITypedIngredient; import mezz.jei.api.ingredients.subtypes.ISubtypeManager; +import mezz.jei.api.registration.IIngredientAliasRegistration; import mezz.jei.api.registration.IModIngredientRegistration; import mezz.jei.api.runtime.IIngredientManager; import mezz.jei.common.util.ErrorUtil; @@ -14,16 +16,16 @@ import mezz.jei.library.ingredients.IngredientManager; import mezz.jei.library.ingredients.RegisteredIngredients; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.IdentityHashMap; +import java.util.LinkedHashMap; import java.util.List; -import java.util.Set; +import java.util.Map; +import java.util.SequencedMap; +import java.util.function.Function; +import java.util.stream.Collectors; -public class IngredientManagerBuilder implements IModIngredientRegistration { - private final List> ingredientInfos = new ArrayList<>(); - private final Set> registeredIngredientSet = Collections.newSetFromMap(new IdentityHashMap<>()); +public class IngredientManagerBuilder implements IModIngredientRegistration, IIngredientAliasRegistration { + private final SequencedMap, IngredientInfo> ingredientInfos = new LinkedHashMap<>(); private final ISubtypeManager subtypeManager; private final IColorHelper colorHelper; @@ -47,12 +49,11 @@ public void register(IIngredientType ingredientType, Collection allIng "the default ingredient renderer registered here will be used for drawing " + "ingredients in the ingredient list, and it must have a height of 16" ); - if (registeredIngredientSet.contains(ingredientType)) { + if (ingredientInfos.containsKey(ingredientType)) { throw new IllegalArgumentException("Ingredient type has already been registered: " + ingredientType.getIngredientClass()); } - ingredientInfos.add(new IngredientInfo<>(ingredientType, allIngredients, ingredientHelper, ingredientRenderer, null)); - registeredIngredientSet.add(ingredientType); + ingredientInfos.put(ingredientType, new IngredientInfo<>(ingredientType, allIngredients, ingredientHelper, ingredientRenderer, null)); } @Override @@ -77,12 +78,111 @@ public void register( "ingredients in the ingredient list, and it must have a height of 16" ); - if (registeredIngredientSet.contains(ingredientType)) { + if (ingredientInfos.containsKey(ingredientType)) { throw new IllegalArgumentException("Ingredient type has already been registered: " + ingredientType.getIngredientClass()); } - ingredientInfos.add(new IngredientInfo<>(ingredientType, allIngredients, ingredientHelper, ingredientRenderer, ingredientCodec)); - registeredIngredientSet.add(ingredientType); + ingredientInfos.put(ingredientType, new IngredientInfo<>(ingredientType, allIngredients, ingredientHelper, ingredientRenderer, ingredientCodec)); + } + + @Override + public void addAlias(IIngredientType type, I ingredient, String alias) { + ErrorUtil.checkNotNull(type, "type"); + ErrorUtil.checkNotNull(ingredient, "ingredient"); + ErrorUtil.checkNotNull(alias, "alias"); + + @SuppressWarnings("unchecked") + IngredientInfo ingredientInfo = (IngredientInfo) ingredientInfos.get(type); + ingredientInfo.addIngredientAlias(ingredient, alias); + } + + @Override + public void addAlias(ITypedIngredient typedIngredient, String alias) { + ErrorUtil.checkNotNull(typedIngredient, "typedIngredient"); + ErrorUtil.checkNotNull(alias, "alias"); + + @SuppressWarnings("unchecked") + IngredientInfo ingredientInfo = (IngredientInfo) ingredientInfos.get(typedIngredient.getType()); + ingredientInfo.addIngredientAlias(typedIngredient.getIngredient(), alias); + } + + @Override + public void addAliases(IIngredientType type, I ingredient, Collection aliases) { + ErrorUtil.checkNotNull(type, "type"); + ErrorUtil.checkNotNull(ingredient, "ingredient"); + ErrorUtil.checkNotNull(aliases, "aliases"); + + @SuppressWarnings("unchecked") + IngredientInfo ingredientInfo = (IngredientInfo) ingredientInfos.get(type); + ingredientInfo.addIngredientAliases(ingredient, aliases); + } + + @Override + public void addAliases(ITypedIngredient typedIngredient, Collection aliases) { + ErrorUtil.checkNotNull(typedIngredient, "typedIngredient"); + ErrorUtil.checkNotNull(aliases, "aliases"); + + @SuppressWarnings("unchecked") + IngredientInfo ingredientInfo = (IngredientInfo) ingredientInfos.get(typedIngredient.getType()); + ingredientInfo.addIngredientAliases(typedIngredient.getIngredient(), aliases); + } + + @Override + public void addAliases(IIngredientType type, Collection ingredients, String alias) { + ErrorUtil.checkNotNull(type, "type"); + ErrorUtil.checkNotNull(ingredients, "ingredients"); + ErrorUtil.checkNotNull(alias, "alias"); + + @SuppressWarnings("unchecked") + IngredientInfo ingredientInfo = (IngredientInfo) ingredientInfos.get(type); + for (I ingredient : ingredients) { + ingredientInfo.addIngredientAlias(ingredient, alias); + } + } + + @Override + public void addAliases(Collection> typedIngredients, String alias) { + ErrorUtil.checkNotNull(typedIngredients, "typedIngredients"); + ErrorUtil.checkNotNull(alias, "alias"); + + IngredientInfo ingredientInfo = null; + for (ITypedIngredient typedIngredient : typedIngredients) { + IIngredientType ingredientType = typedIngredient.getType(); + if (ingredientInfo == null) { + //noinspection unchecked + ingredientInfo = (IngredientInfo) ingredientInfos.get(ingredientType); + } + ingredientInfo.addIngredientAlias(typedIngredient.getIngredient(), alias); + } + } + + @Override + public void addAliases(IIngredientType type, Collection ingredients, Collection aliases) { + ErrorUtil.checkNotNull(type, "type"); + ErrorUtil.checkNotNull(ingredients, "ingredients"); + ErrorUtil.checkNotNull(aliases, "aliases"); + + @SuppressWarnings("unchecked") + IngredientInfo ingredientInfo = (IngredientInfo) ingredientInfos.get(type); + for (I ingredient : ingredients) { + ingredientInfo.addIngredientAliases(ingredient, aliases); + } + } + + @Override + public void addAliases(Collection> typedIngredients, Collection aliases) { + ErrorUtil.checkNotNull(typedIngredients, "typedIngredients"); + ErrorUtil.checkNotNull(aliases, "aliases"); + + IngredientInfo ingredientInfo = null; + for (ITypedIngredient typedIngredient : typedIngredients) { + IIngredientType ingredientType = typedIngredient.getType(); + if (ingredientInfo == null) { + //noinspection unchecked + ingredientInfo = (IngredientInfo) ingredientInfos.get(ingredientType); + } + ingredientInfo.addIngredientAliases(typedIngredient.getIngredient(), aliases); + } } @Override diff --git a/Library/src/main/java/mezz/jei/library/plugins/debug/JeiDebugPlugin.java b/Library/src/main/java/mezz/jei/library/plugins/debug/JeiDebugPlugin.java index ce6808c31..0f8037510 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/debug/JeiDebugPlugin.java +++ b/Library/src/main/java/mezz/jei/library/plugins/debug/JeiDebugPlugin.java @@ -13,6 +13,7 @@ import mezz.jei.api.ingredients.ITypedIngredient; import mezz.jei.api.registration.IAdvancedRegistration; import mezz.jei.api.registration.IGuiHandlerRegistration; +import mezz.jei.api.registration.IIngredientAliasRegistration; import mezz.jei.api.registration.IModInfoRegistration; import mezz.jei.api.registration.IModIngredientRegistration; import mezz.jei.api.registration.IRecipeCatalystRegistration; @@ -23,6 +24,7 @@ import mezz.jei.api.runtime.IIngredientManager; import mezz.jei.api.runtime.IJeiRuntime; import mezz.jei.common.config.DebugConfig; +import mezz.jei.common.platform.IPlatformFluidHelperInternal; import mezz.jei.common.platform.IPlatformScreenHelper; import mezz.jei.common.platform.Services; import mezz.jei.common.util.ErrorUtil; @@ -39,6 +41,7 @@ import net.minecraft.ChatFormatting; import net.minecraft.client.gui.screens.inventory.BrewingStandScreen; import net.minecraft.client.renderer.Rect2i; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; @@ -86,6 +89,52 @@ public void registerIngredients(IModIngredientRegistration registration) { } } + @Override + public void registerIngredientAliases(IIngredientAliasRegistration registration) { + registration.addAlias( + VanillaTypes.ITEM_STACK, + new ItemStack(Items.PANDA_SPAWN_EGG), + "jei.alias.panda.spawn.egg" + ); + + registration.addAlias( + VanillaTypes.ITEM_STACK, + new ItemStack(Items.VILLAGER_SPAWN_EGG), + "jei.alias.villager.spawn.egg" + ); + + registration.addAliases( + VanillaTypes.ITEM_STACK, + List.of( + new ItemStack(Items.STRUCTURE_VOID), + new ItemStack(Items.BARRIER) + ), + "nothing" + ); + + registration.addAliases( + VanillaTypes.ITEM_STACK, + List.of( + new ItemStack(Items.GOLDEN_HOE), + new ItemStack(Items.DIAMOND_BLOCK) + ), + List.of("shiny", "valuable", "Expensive", "expansive", "extensive") + ); + + IPlatformFluidHelperInternal fluidHelper = Services.PLATFORM.getFluidHelper(); + registerFluidAliases(registration, fluidHelper); + } + + private void registerFluidAliases(IIngredientAliasRegistration registration, IPlatformFluidHelper fluidHelper) { + @SuppressWarnings("deprecation") + Holder.Reference water = Fluids.WATER.builtInRegistryHolder(); + registration.addAliases( + fluidHelper.getFluidIngredientType(), + fluidHelper.create(water, fluidHelper.bucketVolume()), + List.of("wet", "aqua", "sea", "ocean") + ); + } + @Override public void registerModInfo(IModInfoRegistration registration) { registration.addModAliases(ModIds.JEI_ID, "jei"); diff --git a/Library/src/main/java/mezz/jei/library/startup/JeiStarter.java b/Library/src/main/java/mezz/jei/library/startup/JeiStarter.java index d4570c1de..208370e58 100644 --- a/Library/src/main/java/mezz/jei/library/startup/JeiStarter.java +++ b/Library/src/main/java/mezz/jei/library/startup/JeiStarter.java @@ -13,6 +13,7 @@ import mezz.jei.common.config.ConfigManager; import mezz.jei.common.config.DebugConfig; import mezz.jei.common.config.IClientToggleState; +import mezz.jei.common.config.IIngredientFilterConfig; import mezz.jei.common.config.JeiClientConfigs; import mezz.jei.common.config.file.ConfigSchemaBuilder; import mezz.jei.common.config.file.FileWatcher; @@ -58,6 +59,7 @@ public final class JeiStarter { @SuppressWarnings("FieldCanBeLocal") private final FileWatcher fileWatcher = new FileWatcher("JEI Config File Watcher"); private final ConfigManager configManager; + private final JeiClientConfigs jeiClientConfigs; public JeiStarter(StartData data) { ErrorUtil.checkNotEmpty(data.plugins(), "plugins"); @@ -85,7 +87,7 @@ public JeiStarter(StartData data) { this.colorNameConfig = new ColorNameConfig(colorFileBuilder); colorFileBuilder.build().register(fileWatcher, configManager); - JeiClientConfigs jeiClientConfigs = new JeiClientConfigs(configDir.resolve("jei-client.ini")); + this.jeiClientConfigs = new JeiClientConfigs(configDir.resolve("jei-client.ini")); jeiClientConfigs.register(fileWatcher, configManager); Internal.setJeiClientConfigs(jeiClientConfigs); @@ -111,7 +113,8 @@ public void start() { IClientToggleState toggleState = Internal.getClientToggleState(); - PluginLoader pluginLoader = new PluginLoader(data, modIdFormatConfig, colorHelper); + IIngredientFilterConfig ingredientFilterConfig = jeiClientConfigs.getIngredientFilterConfig(); + PluginLoader pluginLoader = new PluginLoader(data, modIdFormatConfig, ingredientFilterConfig, colorHelper); JeiHelpers jeiHelpers = pluginLoader.getJeiHelpers(); IIngredientManager ingredientManager = pluginLoader.getIngredientManager(); diff --git a/NeoForge/src/test/java/mezz/jei/test/lib/TestIngredientFilterConfig.java b/NeoForge/src/test/java/mezz/jei/test/lib/TestIngredientFilterConfig.java index 0a0c6f725..2712c820d 100644 --- a/NeoForge/src/test/java/mezz/jei/test/lib/TestIngredientFilterConfig.java +++ b/NeoForge/src/test/java/mezz/jei/test/lib/TestIngredientFilterConfig.java @@ -45,6 +45,11 @@ public boolean getSearchModAliases() { return false; } + @Override + public boolean getSearchIngredientAliases() { + return false; + } + @Override public boolean getSearchShortModNames() { return false; diff --git a/gradle.properties b/gradle.properties index 1f549e6da..838a23f79 100644 --- a/gradle.properties +++ b/gradle.properties @@ -60,4 +60,4 @@ curseHomepageUrl=https://www.curseforge.com/minecraft/mc-mods/jei jUnitVersion=5.8.2 # Version -specificationVersion=19.9.1 +specificationVersion=19.10.0