From 9e686846238fa4b55be6ba5461b9057d3ab6f503 Mon Sep 17 00:00:00 2001 From: mezz Date: Wed, 18 Sep 2024 21:45:37 +0900 Subject: [PATCH] make IIngredientVisibility available earlier, in IJeiHelpers --- .../mezz/jei/api/helpers/IJeiHelpers.java | 9 ++ .../api/registration/IRecipeRegistration.java | 6 +- .../registration/IRuntimeRegistration.java | 6 +- .../api/runtime/IIngredientVisibility.java | 10 +- .../mezz/jei/api/runtime/IJeiRuntime.java | 6 +- .../mezz/jei/gui/startup/JeiGuiStarter.java | 2 +- .../library/gui/ingredients/RecipeSlot.java | 2 +- .../ingredients/IngredientVisibility.java | 2 +- .../mezz/jei/library/load/PluginLoader.java | 115 ++++++++++-------- .../load/registration/RecipeRegistration.java | 9 -- .../RecipeTransferRegistration.java | 7 +- .../registration/RuntimeRegistration.java | 9 -- .../mezz/jei/library/runtime/JeiHelpers.java | 16 ++- .../mezz/jei/library/runtime/JeiRuntime.java | 9 -- .../mezz/jei/library/startup/JeiStarter.java | 54 ++++---- gradle.properties | 2 +- 16 files changed, 136 insertions(+), 128 deletions(-) diff --git a/CommonApi/src/main/java/mezz/jei/api/helpers/IJeiHelpers.java b/CommonApi/src/main/java/mezz/jei/api/helpers/IJeiHelpers.java index d5bc411ee..1648677a2 100644 --- a/CommonApi/src/main/java/mezz/jei/api/helpers/IJeiHelpers.java +++ b/CommonApi/src/main/java/mezz/jei/api/helpers/IJeiHelpers.java @@ -6,6 +6,7 @@ import mezz.jei.api.recipe.RecipeType; import mezz.jei.api.recipe.vanilla.IVanillaRecipeFactory; import mezz.jei.api.runtime.IIngredientManager; +import mezz.jei.api.runtime.IIngredientVisibility; import net.minecraft.resources.ResourceLocation; import java.util.Optional; @@ -102,4 +103,12 @@ public interface IJeiHelpers { * @since 19.15.0 */ IVanillaRecipeFactory getVanillaRecipeFactory(); + + /** + * The {@link IIngredientVisibility} allows mod plugins to do advanced filtering of + * ingredients based on what is visible in JEI. + * + * @since 19.18.4 + */ + IIngredientVisibility getIngredientVisibility(); } diff --git a/CommonApi/src/main/java/mezz/jei/api/registration/IRecipeRegistration.java b/CommonApi/src/main/java/mezz/jei/api/registration/IRecipeRegistration.java index 791c33ed8..ef9c129ea 100644 --- a/CommonApi/src/main/java/mezz/jei/api/registration/IRecipeRegistration.java +++ b/CommonApi/src/main/java/mezz/jei/api/registration/IRecipeRegistration.java @@ -34,8 +34,12 @@ public interface IRecipeRegistration { * ingredients based on what is visible in JEI. * * @since 9.3.1 + * @deprecated use {@link IJeiHelpers#getIngredientVisibility()} */ - IIngredientVisibility getIngredientVisibility(); + @Deprecated(since = "19.18.4", forRemoval = true) + default IIngredientVisibility getIngredientVisibility() { + return getJeiHelpers().getIngredientVisibility(); + } /** * Add the recipes provided by your plugin. diff --git a/CommonApi/src/main/java/mezz/jei/api/registration/IRuntimeRegistration.java b/CommonApi/src/main/java/mezz/jei/api/registration/IRuntimeRegistration.java index 979b0db1d..488664685 100644 --- a/CommonApi/src/main/java/mezz/jei/api/registration/IRuntimeRegistration.java +++ b/CommonApi/src/main/java/mezz/jei/api/registration/IRuntimeRegistration.java @@ -68,8 +68,12 @@ public interface IRuntimeRegistration { /** * The {@link IIngredientVisibility} allows mod plugins to do advanced filtering of * ingredients based on what is visible in JEI. + * @deprecated use {@link IJeiHelpers#getIngredientVisibility()} */ - IIngredientVisibility getIngredientVisibility(); + @Deprecated(since = "19.18.4", forRemoval = true) + default IIngredientVisibility getIngredientVisibility() { + return getJeiHelpers().getIngredientVisibility(); + } /** * Get a helper for all runtime Screen functions. diff --git a/CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientVisibility.java b/CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientVisibility.java index 913ab4dd0..db33d054c 100644 --- a/CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientVisibility.java +++ b/CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientVisibility.java @@ -1,21 +1,19 @@ package mezz.jei.api.runtime; -import mezz.jei.api.IModPlugin; +import mezz.jei.api.helpers.IJeiHelpers; import mezz.jei.api.ingredients.IIngredientType; import mezz.jei.api.ingredients.ITypedIngredient; -import mezz.jei.api.registration.IRecipeRegistration; +import org.jetbrains.annotations.ApiStatus; /** * The {@link IIngredientVisibility} allows mod plugins to do advanced filtering of * ingredients based on what is visible in JEI. * - * An instance available during {@link IModPlugin#registerRecipes} - * from {@link IRecipeRegistration#getIngredientVisibility()} - * and it is accessible at runtime from - * {@link IJeiRuntime#getIngredientVisibility()}. + * An instance available from {@link IJeiHelpers#getIngredientVisibility()}. * * @since JEI 9.3.0 */ +@ApiStatus.NonExtendable public interface IIngredientVisibility { /** * Returns true if the given ingredient is visible in JEI's ingredient list. diff --git a/CommonApi/src/main/java/mezz/jei/api/runtime/IJeiRuntime.java b/CommonApi/src/main/java/mezz/jei/api/runtime/IJeiRuntime.java index 01749c3af..83aa29d77 100644 --- a/CommonApi/src/main/java/mezz/jei/api/runtime/IJeiRuntime.java +++ b/CommonApi/src/main/java/mezz/jei/api/runtime/IJeiRuntime.java @@ -57,8 +57,12 @@ public interface IJeiRuntime { * ingredients based on what is visible in JEI. * * @since 9.3.0 + * @deprecated use {@link IJeiHelpers#getIngredientVisibility()} */ - IIngredientVisibility getIngredientVisibility(); + @Deprecated(since = "19.18.4", forRemoval = true) + default IIngredientVisibility getIngredientVisibility() { + return getJeiHelpers().getIngredientVisibility(); + } /** * The {@link IJeiKeyMappings} gives access to key mappings used by JEI. diff --git a/Gui/src/main/java/mezz/jei/gui/startup/JeiGuiStarter.java b/Gui/src/main/java/mezz/jei/gui/startup/JeiGuiStarter.java index f849e438a..5a51491d4 100644 --- a/Gui/src/main/java/mezz/jei/gui/startup/JeiGuiStarter.java +++ b/Gui/src/main/java/mezz/jei/gui/startup/JeiGuiStarter.java @@ -76,11 +76,11 @@ public static JeiEventHandlers start(IRuntimeRegistration registration) { IScreenHelper screenHelper = registration.getScreenHelper(); IRecipeTransferManager recipeTransferManager = registration.getRecipeTransferManager(); IRecipeManager recipeManager = registration.getRecipeManager(); - IIngredientVisibility ingredientVisibility = registration.getIngredientVisibility(); IIngredientManager ingredientManager = registration.getIngredientManager(); IEditModeConfig editModeConfig = registration.getEditModeConfig(); IJeiHelpers jeiHelpers = registration.getJeiHelpers(); + IIngredientVisibility ingredientVisibility = jeiHelpers.getIngredientVisibility(); IColorHelper colorHelper = jeiHelpers.getColorHelper(); IModIdHelper modIdHelper = jeiHelpers.getModIdHelper(); IFocusFactory focusFactory = jeiHelpers.getFocusFactory(); diff --git a/Library/src/main/java/mezz/jei/library/gui/ingredients/RecipeSlot.java b/Library/src/main/java/mezz/jei/library/gui/ingredients/RecipeSlot.java index 95bc33faa..b4740a5bd 100644 --- a/Library/src/main/java/mezz/jei/library/gui/ingredients/RecipeSlot.java +++ b/Library/src/main/java/mezz/jei/library/gui/ingredients/RecipeSlot.java @@ -120,7 +120,7 @@ private static List>> calculateDisplayIngredients(L // hide invisible ingredients if there are any // try scanning through all the ingredients without building the list of visible ingredients. // if an invisible ingredient is found, start building the list of visible ingredients - IIngredientVisibility ingredientVisibility = Internal.getJeiRuntime().getIngredientVisibility(); + IIngredientVisibility ingredientVisibility = Internal.getJeiRuntime().getJeiHelpers().getIngredientVisibility(); for (int i = 0; i < allIngredients.size() && visibleIngredients.size() < MAX_DISPLAYED_INGREDIENTS; i++) { Optional> ingredient = allIngredients.get(i); boolean visible = ingredient.isEmpty() || ingredientVisibility.isIngredientVisible(ingredient.get()); diff --git a/Library/src/main/java/mezz/jei/library/ingredients/IngredientVisibility.java b/Library/src/main/java/mezz/jei/library/ingredients/IngredientVisibility.java index cfe9346af..38e7ed531 100644 --- a/Library/src/main/java/mezz/jei/library/ingredients/IngredientVisibility.java +++ b/Library/src/main/java/mezz/jei/library/ingredients/IngredientVisibility.java @@ -41,7 +41,7 @@ public boolean isIngredientVisible(ITypedIngredient typedIngredient) { @Override public boolean isIngredientVisible(IIngredientType ingredientType, V ingredient) { IIngredientHelper ingredientHelper = ingredientManager.getIngredientHelper(ingredientType); - return TypedIngredient.createAndFilterInvalid(ingredientManager, ingredientType, ingredient, false) + return TypedIngredient.createAndFilterInvalid(ingredientHelper, ingredientType, ingredient, false) .map(i -> isIngredientVisible(i, ingredientHelper)) .orElse(false); } 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 6d208320a..3defbdf2d 100644 --- a/Library/src/main/java/mezz/jei/library/load/PluginLoader.java +++ b/Library/src/main/java/mezz/jei/library/load/PluginLoader.java @@ -2,7 +2,6 @@ import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableSetMultimap; -import com.google.common.collect.ImmutableTable; import mezz.jei.api.IModPlugin; import mezz.jei.api.helpers.IColorHelper; import mezz.jei.api.helpers.IJeiHelpers; @@ -13,23 +12,29 @@ import mezz.jei.api.recipe.advanced.IRecipeManagerPlugin; import mezz.jei.api.recipe.category.IRecipeCategory; import mezz.jei.api.recipe.category.extensions.IRecipeCategoryDecorator; -import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper; +import mezz.jei.api.recipe.transfer.IRecipeTransferManager; import mezz.jei.api.runtime.IIngredientManager; import mezz.jei.api.runtime.IIngredientVisibility; import mezz.jei.api.runtime.IJeiFeatures; import mezz.jei.api.runtime.IScreenHelper; import mezz.jei.common.Internal; +import mezz.jei.common.config.IClientToggleState; import mezz.jei.common.config.IIngredientFilterConfig; +import mezz.jei.common.network.IConnectionToServer; import mezz.jei.common.platform.IPlatformFluidHelperInternal; import mezz.jei.common.platform.Services; import mezz.jei.common.util.StackHelper; import mezz.jei.core.util.LoggedTimer; +import mezz.jei.library.config.EditModeConfig; import mezz.jei.library.config.IModIdFormatConfig; import mezz.jei.library.config.RecipeCategorySortingConfig; import mezz.jei.library.focus.FocusFactory; import mezz.jei.library.gui.helpers.GuiHelper; +import mezz.jei.library.helpers.CodecHelper; import mezz.jei.library.helpers.ModIdHelper; +import mezz.jei.library.ingredients.IngredientBlacklistInternal; +import mezz.jei.library.ingredients.IngredientVisibility; import mezz.jei.library.ingredients.subtypes.SubtypeInterpreters; import mezz.jei.library.ingredients.subtypes.SubtypeManager; import mezz.jei.library.load.registration.AdvancedRegistration; @@ -52,26 +57,14 @@ import mezz.jei.library.runtime.JeiHelpers; import mezz.jei.library.startup.StartData; import mezz.jei.library.transfer.RecipeTransferHandlerHelper; -import net.minecraft.world.inventory.AbstractContainerMenu; import org.jetbrains.annotations.Unmodifiable; import java.util.List; -public class PluginLoader { - private final StartData data; - private final LoggedTimer timer; - private final IIngredientManager ingredientManager; - private final JeiHelpers jeiHelpers; - - public PluginLoader( - StartData data, - IModIdFormatConfig modIdFormatConfig, - IIngredientFilterConfig ingredientFilterConfig, - IColorHelper colorHelper - ) { - this.data = data; - this.timer = new LoggedTimer(); +public final class PluginLoader { + private PluginLoader() {} + public static SubtypeManager registerSubtypes(StartData data) { IPlatformFluidHelperInternal fluidHelper = Services.PLATFORM.getFluidHelper(); List plugins = data.plugins(); SubtypeRegistration subtypeRegistration = new SubtypeRegistration(); @@ -80,8 +73,11 @@ public PluginLoader( p.registerFluidSubtypes(subtypeRegistration, fluidHelper) ); SubtypeInterpreters subtypeInterpreters = subtypeRegistration.getInterpreters(); - SubtypeManager subtypeManager = new SubtypeManager(subtypeInterpreters); + return new SubtypeManager(subtypeInterpreters); + } + public static IIngredientManager registerIngredients(StartData data, SubtypeManager subtypeManager, IColorHelper colorHelper, IIngredientFilterConfig ingredientFilterConfig) { + List plugins = data.plugins(); IngredientManagerBuilder ingredientManagerBuilder = new IngredientManagerBuilder(subtypeManager, colorHelper); PluginCaller.callOnPlugins("Registering ingredients", plugins, p -> p.registerIngredients(ingredientManagerBuilder)); PluginCaller.callOnPlugins("Registering extra ingredients", plugins, p -> p.registerExtraIngredients(ingredientManagerBuilder)); @@ -89,29 +85,53 @@ public PluginLoader( if (ingredientFilterConfig.getSearchIngredientAliases()) { PluginCaller.callOnPlugins("Registering search ingredient aliases", plugins, p -> p.registerIngredientAliases(ingredientManagerBuilder)); } + return ingredientManagerBuilder.build(); + } - this.ingredientManager = ingredientManagerBuilder.build(); - - 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(); + public static ImmutableSetMultimap registerModAliases( + StartData data, + IIngredientFilterConfig ingredientFilterConfig + ) { + List plugins = data.plugins(); + if (!ingredientFilterConfig.getSearchModAliases()) { + return ImmutableSetMultimap.of(); } + ModInfoRegistration modInfoRegistration = new ModInfoRegistration(); + PluginCaller.callOnPlugins("Registering Mod Info", plugins, p -> p.registerModInfo(modInfoRegistration)); + return modInfoRegistration.getModAliases(); + } + public static JeiHelpers createJeiHelpers( + ImmutableSetMultimap modAliases, + IModIdFormatConfig modIdFormatConfig, + IColorHelper colorHelper, + EditModeConfig editModeConfig, + FocusFactory focusFactory, + CodecHelper codecHelper, + IIngredientManager ingredientManager, + SubtypeManager subtypeManager + ) { VanillaRecipeFactory vanillaRecipeFactory = new VanillaRecipeFactory(ingredientManager); - StackHelper stackHelper = new StackHelper(subtypeManager); GuiHelper guiHelper = new GuiHelper(ingredientManager); - FocusFactory focusFactory = new FocusFactory(ingredientManager); IModIdHelper modIdHelper = new ModIdHelper(modIdFormatConfig, ingredientManager, modAliases); - this.jeiHelpers = new JeiHelpers(guiHelper, stackHelper, modIdHelper, focusFactory, colorHelper, ingredientManager, vanillaRecipeFactory); + + IClientToggleState toggleState = Internal.getClientToggleState(); + IngredientBlacklistInternal blacklist = new IngredientBlacklistInternal(); + ingredientManager.registerIngredientListener(blacklist); + + IIngredientVisibility ingredientVisibility = new IngredientVisibility( + blacklist, + toggleState, + editModeConfig, + ingredientManager + ); + + return new JeiHelpers(guiHelper, stackHelper, modIdHelper, focusFactory, colorHelper, ingredientManager, vanillaRecipeFactory, codecHelper, ingredientVisibility); } @Unmodifiable - private List> createRecipeCategories(List plugins, VanillaPlugin vanillaPlugin) { + private static List> createRecipeCategories(List plugins, VanillaPlugin vanillaPlugin, JeiHelpers jeiHelpers) { RecipeCategoryRegistration recipeCategoryRegistration = new RecipeCategoryRegistration(jeiHelpers); PluginCaller.callOnPlugins("Registering categories", plugins, p -> p.registerCategories(recipeCategoryRegistration)); CraftingRecipeCategory craftingCategory = vanillaPlugin.getCraftingCategory() @@ -123,41 +143,48 @@ private List> createRecipeCategories(List plugins return recipeCategoryRegistration.getRecipeCategories(); } - public IScreenHelper createGuiScreenHelper(List plugins, IJeiHelpers jeiHelpers) { + public static IScreenHelper createGuiScreenHelper(List plugins, IJeiHelpers jeiHelpers, IIngredientManager ingredientManager) { GuiHandlerRegistration guiHandlerRegistration = new GuiHandlerRegistration(jeiHelpers); PluginCaller.callOnPlugins("Registering gui handlers", plugins, p -> p.registerGuiHandlers(guiHandlerRegistration)); return guiHandlerRegistration.createGuiScreenHelper(ingredientManager); } - public ImmutableTable, RecipeType, IRecipeTransferHandler> createRecipeTransferHandlers(VanillaPlugin vanillaPlugin, List plugins) { + public static IRecipeTransferManager createRecipeTransferManager( + VanillaPlugin vanillaPlugin, + List plugins, + JeiHelpers jeiHelpers, + IConnectionToServer connectionToServer + ) { IStackHelper stackHelper = jeiHelpers.getStackHelper(); CraftingRecipeCategory craftingCategory = vanillaPlugin.getCraftingCategory() .orElseThrow(() -> new NullPointerException("vanilla crafting category")); IRecipeTransferHandlerHelper handlerHelper = new RecipeTransferHandlerHelper(stackHelper, craftingCategory); - RecipeTransferRegistration recipeTransferRegistration = new RecipeTransferRegistration(stackHelper, handlerHelper, this.jeiHelpers, data.serverConnection()); + RecipeTransferRegistration recipeTransferRegistration = new RecipeTransferRegistration(stackHelper, handlerHelper, jeiHelpers, connectionToServer); PluginCaller.callOnPlugins("Registering recipes transfer handlers", plugins, p -> p.registerRecipeTransferHandlers(recipeTransferRegistration)); - return recipeTransferRegistration.getRecipeTransferHandlers(); + return recipeTransferRegistration.createRecipeTransferManager(); } - public RecipeManager createRecipeManager( + public static RecipeManager createRecipeManager( List plugins, VanillaPlugin vanillaPlugin, RecipeCategorySortingConfig recipeCategorySortingConfig, - IIngredientVisibility ingredientVisibility + JeiHelpers jeiHelpers, + IIngredientManager ingredientManager ) { - List> recipeCategories = createRecipeCategories(plugins, vanillaPlugin); + List> recipeCategories = createRecipeCategories(plugins, vanillaPlugin, jeiHelpers); RecipeCatalystRegistration recipeCatalystRegistration = new RecipeCatalystRegistration(ingredientManager, jeiHelpers); PluginCaller.callOnPlugins("Registering recipe catalysts", plugins, p -> p.registerRecipeCatalysts(recipeCatalystRegistration)); ImmutableListMultimap, ITypedIngredient> recipeCatalysts = recipeCatalystRegistration.getRecipeCatalysts(); + LoggedTimer timer = new LoggedTimer(); timer.start("Building recipe registry"); RecipeManagerInternal recipeManagerInternal = new RecipeManagerInternal( recipeCategories, recipeCatalysts, ingredientManager, recipeCategorySortingConfig, - ingredientVisibility + jeiHelpers.getIngredientVisibility() ); timer.stop(); @@ -171,19 +198,11 @@ public RecipeManager createRecipeManager( recipeManagerInternal.addPlugins(recipeManagerPlugins); recipeManagerInternal.addDecorators(recipeCategoryDecorators); - RecipeRegistration recipeRegistration = new RecipeRegistration(jeiHelpers, ingredientManager, ingredientVisibility, recipeManagerInternal); + RecipeRegistration recipeRegistration = new RecipeRegistration(jeiHelpers, ingredientManager, recipeManagerInternal); PluginCaller.callOnPlugins("Registering recipes", plugins, p -> p.registerRecipes(recipeRegistration)); recipeManagerInternal.compact(); return new RecipeManager(recipeManagerInternal, ingredientManager); } - - public IIngredientManager getIngredientManager() { - return ingredientManager; - } - - public JeiHelpers getJeiHelpers() { - return jeiHelpers; - } } diff --git a/Library/src/main/java/mezz/jei/library/load/registration/RecipeRegistration.java b/Library/src/main/java/mezz/jei/library/load/registration/RecipeRegistration.java index b4819719c..b5d19f818 100644 --- a/Library/src/main/java/mezz/jei/library/load/registration/RecipeRegistration.java +++ b/Library/src/main/java/mezz/jei/library/load/registration/RecipeRegistration.java @@ -8,7 +8,6 @@ import mezz.jei.api.recipe.vanilla.IVanillaRecipeFactory; import mezz.jei.api.registration.IRecipeRegistration; import mezz.jei.api.runtime.IIngredientManager; -import mezz.jei.api.runtime.IIngredientVisibility; import mezz.jei.common.util.ErrorUtil; import mezz.jei.library.plugins.jei.info.IngredientInfoRecipe; import mezz.jei.library.recipes.RecipeManagerInternal; @@ -19,18 +18,15 @@ public class RecipeRegistration implements IRecipeRegistration { private final IJeiHelpers jeiHelpers; private final IIngredientManager ingredientManager; - private final IIngredientVisibility ingredientVisibility; private final RecipeManagerInternal recipeManager; public RecipeRegistration( IJeiHelpers jeiHelpers, IIngredientManager ingredientManager, - IIngredientVisibility ingredientVisibility, RecipeManagerInternal recipeManager ) { this.jeiHelpers = jeiHelpers; this.ingredientManager = ingredientManager; - this.ingredientVisibility = ingredientVisibility; this.recipeManager = recipeManager; } @@ -49,11 +45,6 @@ public IVanillaRecipeFactory getVanillaRecipeFactory() { return jeiHelpers.getVanillaRecipeFactory(); } - @Override - public IIngredientVisibility getIngredientVisibility() { - return ingredientVisibility; - } - @Override public void addRecipes(RecipeType recipeType, List recipes) { ErrorUtil.checkNotNull(recipeType, "recipeType"); diff --git a/Library/src/main/java/mezz/jei/library/load/registration/RecipeTransferRegistration.java b/Library/src/main/java/mezz/jei/library/load/registration/RecipeTransferRegistration.java index 0ad76c28c..d55001bf2 100644 --- a/Library/src/main/java/mezz/jei/library/load/registration/RecipeTransferRegistration.java +++ b/Library/src/main/java/mezz/jei/library/load/registration/RecipeTransferRegistration.java @@ -1,16 +1,17 @@ package mezz.jei.library.load.registration; -import com.google.common.collect.ImmutableTable; import mezz.jei.api.helpers.IJeiHelpers; import mezz.jei.api.helpers.IStackHelper; import mezz.jei.api.recipe.RecipeType; import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper; import mezz.jei.api.recipe.transfer.IRecipeTransferInfo; +import mezz.jei.api.recipe.transfer.IRecipeTransferManager; import mezz.jei.api.recipe.transfer.IUniversalRecipeTransferHandler; import mezz.jei.api.registration.IRecipeTransferRegistration; import mezz.jei.common.Constants; import mezz.jei.common.network.IConnectionToServer; +import mezz.jei.library.recipes.RecipeTransferManager; import mezz.jei.library.recipes.UniversalRecipeTransferHandlerAdapter; import mezz.jei.library.transfer.BasicRecipeTransferHandler; import mezz.jei.library.transfer.BasicRecipeTransferInfo; @@ -93,7 +94,7 @@ public void addUniversalRecipeTransferHandl this.recipeTransferHandlers.put(containerClass, Constants.UNIVERSAL_RECIPE_TRANSFER_TYPE, recipeTransferHandler); } - public ImmutableTable, RecipeType, IRecipeTransferHandler> getRecipeTransferHandlers() { - return recipeTransferHandlers.toImmutable(); + public IRecipeTransferManager createRecipeTransferManager() { + return new RecipeTransferManager(recipeTransferHandlers.toImmutable()); } } diff --git a/Library/src/main/java/mezz/jei/library/load/registration/RuntimeRegistration.java b/Library/src/main/java/mezz/jei/library/load/registration/RuntimeRegistration.java index 2baec766a..e781dcf6a 100644 --- a/Library/src/main/java/mezz/jei/library/load/registration/RuntimeRegistration.java +++ b/Library/src/main/java/mezz/jei/library/load/registration/RuntimeRegistration.java @@ -9,7 +9,6 @@ import mezz.jei.api.runtime.IIngredientFilter; import mezz.jei.api.runtime.IIngredientListOverlay; import mezz.jei.api.runtime.IIngredientManager; -import mezz.jei.api.runtime.IIngredientVisibility; import mezz.jei.api.runtime.IRecipesGui; import mezz.jei.api.runtime.IScreenHelper; import mezz.jei.library.gui.BookmarkOverlayDummy; @@ -22,7 +21,6 @@ public class RuntimeRegistration implements IRuntimeRegistration { private final IJeiHelpers jeiHelpers; private final IEditModeConfig editModeConfig; private final IIngredientManager ingredientManager; - private final IIngredientVisibility ingredientVisibility; private final IRecipeTransferManager recipeTransferManager; private final IScreenHelper screenHelper; @@ -36,7 +34,6 @@ public RuntimeRegistration( IJeiHelpers jeiHelpers, IEditModeConfig editModeConfig, IIngredientManager ingredientManager, - IIngredientVisibility ingredientVisibility, IRecipeTransferManager recipeTransferManager, IScreenHelper screenHelper ) { @@ -44,7 +41,6 @@ public RuntimeRegistration( this.jeiHelpers = jeiHelpers; this.editModeConfig = editModeConfig; this.ingredientManager = ingredientManager; - this.ingredientVisibility = ingredientVisibility; this.recipeTransferManager = recipeTransferManager; this.screenHelper = screenHelper; } @@ -84,11 +80,6 @@ public IIngredientManager getIngredientManager() { return this.ingredientManager; } - @Override - public IIngredientVisibility getIngredientVisibility() { - return this.ingredientVisibility; - } - @Override public IScreenHelper getScreenHelper() { return this.screenHelper; diff --git a/Library/src/main/java/mezz/jei/library/runtime/JeiHelpers.java b/Library/src/main/java/mezz/jei/library/runtime/JeiHelpers.java index 0aed5f5c6..60a55a0ba 100644 --- a/Library/src/main/java/mezz/jei/library/runtime/JeiHelpers.java +++ b/Library/src/main/java/mezz/jei/library/runtime/JeiHelpers.java @@ -12,9 +12,9 @@ import mezz.jei.api.recipe.category.IRecipeCategory; import mezz.jei.api.recipe.vanilla.IVanillaRecipeFactory; import mezz.jei.api.runtime.IIngredientManager; +import mezz.jei.api.runtime.IIngredientVisibility; import mezz.jei.common.platform.Services; import mezz.jei.library.gui.helpers.GuiHelper; -import mezz.jei.library.helpers.CodecHelper; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; @@ -31,6 +31,7 @@ public class JeiHelpers implements IJeiHelpers { private final IColorHelper colorHelper; private final IIngredientManager ingredientManager; private final IVanillaRecipeFactory vanillaRecipeFactory; + private final IIngredientVisibility ingredientVisibility; private final IPlatformFluidHelper platformFluidHelper; private final ICodecHelper codecHelper; private @Nullable Collection> recipeCategories; @@ -42,7 +43,9 @@ public JeiHelpers( IFocusFactory focusFactory, IColorHelper colorHelper, IIngredientManager ingredientManager, - IVanillaRecipeFactory vanillaRecipeFactory + IVanillaRecipeFactory vanillaRecipeFactory, + ICodecHelper codecHelper, + IIngredientVisibility ingredientVisibility ) { this.guiHelper = guiHelper; this.stackHelper = stackHelper; @@ -51,8 +54,9 @@ public JeiHelpers( this.colorHelper = colorHelper; this.ingredientManager = ingredientManager; this.vanillaRecipeFactory = vanillaRecipeFactory; + this.ingredientVisibility = ingredientVisibility; this.platformFluidHelper = Services.PLATFORM.getFluidHelper(); - this.codecHelper = new CodecHelper(ingredientManager, focusFactory); + this.codecHelper = codecHelper; } public void setRecipeCategories(Collection> recipeCategories) { @@ -104,7 +108,6 @@ public Optional> getRecipeType(ResourceLocation uid, Class> getRecipeType(ResourceLocation uid) { return Optional.ofNullable(this.recipeCategories) @@ -138,4 +141,9 @@ public ICodecHelper getCodecHelper() { public IVanillaRecipeFactory getVanillaRecipeFactory() { return vanillaRecipeFactory; } + + @Override + public IIngredientVisibility getIngredientVisibility() { + return ingredientVisibility; + } } diff --git a/Library/src/main/java/mezz/jei/library/runtime/JeiRuntime.java b/Library/src/main/java/mezz/jei/library/runtime/JeiRuntime.java index 816ffdb42..c20ac8b70 100644 --- a/Library/src/main/java/mezz/jei/library/runtime/JeiRuntime.java +++ b/Library/src/main/java/mezz/jei/library/runtime/JeiRuntime.java @@ -8,7 +8,6 @@ import mezz.jei.api.runtime.IIngredientFilter; import mezz.jei.api.runtime.IIngredientListOverlay; import mezz.jei.api.runtime.IIngredientManager; -import mezz.jei.api.runtime.IIngredientVisibility; import mezz.jei.api.runtime.IJeiKeyMappings; import mezz.jei.api.runtime.IJeiRuntime; import mezz.jei.api.runtime.IRecipesGui; @@ -21,7 +20,6 @@ public class JeiRuntime implements IJeiRuntime { private final IRecipeTransferManager recipeTransferManager; private final IEditModeConfig editModeConfig; private final IIngredientManager ingredientManager; - private final IIngredientVisibility ingredientVisibility; private final IJeiKeyMappings keyMappings; private final IJeiHelpers jeiHelpers; private final IScreenHelper screenHelper; @@ -34,7 +32,6 @@ public class JeiRuntime implements IJeiRuntime { public JeiRuntime( IRecipeManager recipeManager, IIngredientManager ingredientManager, - IIngredientVisibility ingredientVisibility, IJeiKeyMappings keyMappings, IJeiHelpers jeiHelpers, IScreenHelper screenHelper, @@ -50,7 +47,6 @@ public JeiRuntime( this.recipeTransferManager = recipeTransferManager; this.editModeConfig = editModeConfig; this.ingredientListOverlay = ingredientListOverlay; - this.ingredientVisibility = ingredientVisibility; this.bookmarkOverlay = bookmarkOverlay; this.recipesGui = recipesGui; this.ingredientFilter = ingredientFilter; @@ -96,11 +92,6 @@ public IRecipesGui getRecipesGui() { return recipesGui; } - @Override - public IIngredientVisibility getIngredientVisibility() { - return ingredientVisibility; - } - @Override public IJeiKeyMappings getKeyMappings() { return keyMappings; 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 314140a59..5ca61d56c 100644 --- a/Library/src/main/java/mezz/jei/library/startup/JeiStarter.java +++ b/Library/src/main/java/mezz/jei/library/startup/JeiStarter.java @@ -1,18 +1,14 @@ package mezz.jei.library.startup; -import com.google.common.collect.ImmutableTable; +import com.google.common.collect.ImmutableSetMultimap; import mezz.jei.api.IModPlugin; import mezz.jei.api.helpers.IColorHelper; -import mezz.jei.api.recipe.RecipeType; -import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; import mezz.jei.api.recipe.transfer.IRecipeTransferManager; import mezz.jei.api.runtime.IIngredientManager; -import mezz.jei.api.runtime.IIngredientVisibility; import mezz.jei.api.runtime.IScreenHelper; import mezz.jei.common.Internal; 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; @@ -26,8 +22,9 @@ import mezz.jei.library.config.EditModeConfig; import mezz.jei.library.config.ModIdFormatConfig; import mezz.jei.library.config.RecipeCategorySortingConfig; -import mezz.jei.library.ingredients.IngredientBlacklistInternal; -import mezz.jei.library.ingredients.IngredientVisibility; +import mezz.jei.library.focus.FocusFactory; +import mezz.jei.library.helpers.CodecHelper; +import mezz.jei.library.ingredients.subtypes.SubtypeManager; import mezz.jei.library.load.PluginCaller; import mezz.jei.library.load.PluginHelper; import mezz.jei.library.load.PluginLoader; @@ -35,12 +32,10 @@ import mezz.jei.library.plugins.jei.JeiInternalPlugin; import mezz.jei.library.plugins.vanilla.VanillaPlugin; import mezz.jei.library.recipes.RecipeManager; -import mezz.jei.library.recipes.RecipeTransferManager; import mezz.jei.library.runtime.JeiHelpers; import mezz.jei.library.runtime.JeiRuntime; import net.minecraft.client.Minecraft; import net.minecraft.core.RegistryAccess; -import net.minecraft.world.inventory.AbstractContainerMenu; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -110,53 +105,47 @@ public void start() { totalTime.start("Starting JEI"); IColorHelper colorHelper = new ColorHelper(colorNameConfig); - - IClientToggleState toggleState = Internal.getClientToggleState(); - IIngredientFilterConfig ingredientFilterConfig = jeiClientConfigs.getIngredientFilterConfig(); - PluginLoader pluginLoader = new PluginLoader(data, modIdFormatConfig, ingredientFilterConfig, colorHelper); - JeiHelpers jeiHelpers = pluginLoader.getJeiHelpers(); - - IIngredientManager ingredientManager = pluginLoader.getIngredientManager(); + SubtypeManager subtypeManager = PluginLoader.registerSubtypes(data); + IIngredientManager ingredientManager = PluginLoader.registerIngredients(data, subtypeManager, colorHelper, ingredientFilterConfig); - IngredientBlacklistInternal blacklist = new IngredientBlacklistInternal(); - ingredientManager.registerIngredientListener(blacklist); + FocusFactory focusFactory = new FocusFactory(ingredientManager); + CodecHelper codecHelper = new CodecHelper(ingredientManager, focusFactory); Path configDir = Services.PLATFORM.getConfigHelper().createJeiConfigDir(); EditModeConfig.FileSerializer editModeSerializer = new EditModeConfig.FileSerializer( configDir.resolve("blacklist.json"), registryAccess, - jeiHelpers.getCodecHelper() + codecHelper ); EditModeConfig editModeConfig = new EditModeConfig(editModeSerializer, ingredientManager); - IIngredientVisibility ingredientVisibility = new IngredientVisibility( - blacklist, - toggleState, - editModeConfig, - ingredientManager - ); + ImmutableSetMultimap modAliases = PluginLoader.registerModAliases(data, ingredientFilterConfig); + JeiHelpers jeiHelpers = PluginLoader.createJeiHelpers(modAliases, modIdFormatConfig, colorHelper, editModeConfig, focusFactory, codecHelper, ingredientManager, subtypeManager); - RecipeManager recipeManager = pluginLoader.createRecipeManager( + RecipeManager recipeManager = PluginLoader.createRecipeManager( plugins, vanillaPlugin, recipeCategorySortingConfig, - ingredientVisibility + jeiHelpers, + ingredientManager + ); + IRecipeTransferManager recipeTransferManager = PluginLoader.createRecipeTransferManager( + vanillaPlugin, + plugins, + jeiHelpers, + data.serverConnection() ); - ImmutableTable, RecipeType, IRecipeTransferHandler> recipeTransferHandlers = - pluginLoader.createRecipeTransferHandlers(vanillaPlugin, plugins); - IRecipeTransferManager recipeTransferManager = new RecipeTransferManager(recipeTransferHandlers); LoggedTimer timer = new LoggedTimer(); timer.start("Building runtime"); - IScreenHelper screenHelper = pluginLoader.createGuiScreenHelper(plugins, jeiHelpers); + IScreenHelper screenHelper = PluginLoader.createGuiScreenHelper(plugins, jeiHelpers, ingredientManager); RuntimeRegistration runtimeRegistration = new RuntimeRegistration( recipeManager, jeiHelpers, editModeConfig, ingredientManager, - ingredientVisibility, recipeTransferManager, screenHelper ); @@ -165,7 +154,6 @@ public void start() { JeiRuntime jeiRuntime = new JeiRuntime( recipeManager, ingredientManager, - ingredientVisibility, data.keyBindings(), jeiHelpers, screenHelper, diff --git a/gradle.properties b/gradle.properties index e2a246e71..f71ed44fb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -74,4 +74,4 @@ modrinthId=u6dRKJwZ jUnitVersion=5.8.2 # Version -specificationVersion=19.18.3 +specificationVersion=19.18.4