diff --git a/gradle.properties b/gradle.properties index 7419472db..70f50fa0c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,5 +4,5 @@ mcp_mappings=snapshot_20180812 curse_project_id=238222 version_major=4 -version_minor=12 -version_patch=1 +version_minor=13 +version_patch=0 diff --git a/src/api/java/mezz/jei/api/IRecipeRegistry.java b/src/api/java/mezz/jei/api/IRecipeRegistry.java index b48edbbf4..614221979 100644 --- a/src/api/java/mezz/jei/api/IRecipeRegistry.java +++ b/src/api/java/mezz/jei/api/IRecipeRegistry.java @@ -138,6 +138,26 @@ public interface IRecipeRegistry { */ void unhideRecipe(IRecipeWrapper recipe, String recipeCategoryUid); + /** + * Hide an entire recipe category of recipes from JEI. + * This can be used by mods that create recipe progression. + * + * @param recipeCategoryUid the unique ID for the recipe category + * @see #unhideRecipeCategory(String) + * @since JEI 4.13.0 + */ + void hideRecipeCategory(String recipeCategoryUid); + + /** + * Unhides a recipe category that was hidden by {@link #hideRecipeCategory(String)}. + * This can be used by mods that create recipe progression. + * + * @param recipeCategoryUid the unique ID for the recipe category + * @see #hideRecipeCategory(String) + * @since JEI 4.13.0 + */ + void unhideRecipeCategory(String recipeCategoryUid); + // DEPRECATED BELOW /** diff --git a/src/main/java/mezz/jei/plugins/jei/debug/DebugRecipe.java b/src/main/java/mezz/jei/plugins/jei/debug/DebugRecipe.java index 07f29fb2e..fda57a91a 100644 --- a/src/main/java/mezz/jei/plugins/jei/debug/DebugRecipe.java +++ b/src/main/java/mezz/jei/plugins/jei/debug/DebugRecipe.java @@ -10,7 +10,6 @@ import mezz.jei.api.IRecipeRegistry; import mezz.jei.api.ingredients.IIngredients; import mezz.jei.api.ingredients.VanillaTypes; -import mezz.jei.api.recipe.IRecipeCategory; import mezz.jei.api.recipe.IRecipeWrapper; import mezz.jei.api.recipe.VanillaRecipeCategoryUid; import mezz.jei.plugins.jei.JEIInternalPlugin; @@ -27,13 +26,10 @@ import net.minecraftforge.fml.client.config.GuiButtonExt; import net.minecraftforge.fml.client.config.HoverChecker; -import javax.annotation.Nullable; - public class DebugRecipe implements IRecipeWrapper { private final GuiButtonExt button; private final HoverChecker buttonHoverChecker; - @Nullable - private List hiddenRecipes; + private boolean hiddenRecipes; public DebugRecipe() { this.button = new GuiButtonExt(0, 110, 30, "test"); @@ -99,20 +95,12 @@ public boolean handleClick(Minecraft minecraft, int mouseX, int mouseY, int mous ingredientFilter.setFilterText(filterText + " test"); IRecipeRegistry recipeRegistry = runtime.getRecipeRegistry(); - if (hiddenRecipes == null) { - @SuppressWarnings("unchecked") - IRecipeCategory craftingRecipeCategory = recipeRegistry.getRecipeCategory(VanillaRecipeCategoryUid.CRAFTING); - if (craftingRecipeCategory != null) { - hiddenRecipes = recipeRegistry.getRecipeWrappers(craftingRecipeCategory); - } - for (IRecipeWrapper recipeWrapper : hiddenRecipes) { - recipeRegistry.hideRecipe(recipeWrapper, VanillaRecipeCategoryUid.CRAFTING); - } + if (!hiddenRecipes) { + recipeRegistry.hideRecipeCategory(VanillaRecipeCategoryUid.CRAFTING); + hiddenRecipes = true; } else { - for (IRecipeWrapper recipeWrapper : hiddenRecipes) { - recipeRegistry.unhideRecipe(recipeWrapper, VanillaRecipeCategoryUid.CRAFTING); - } - hiddenRecipes = null; + recipeRegistry.unhideRecipeCategory(VanillaRecipeCategoryUid.CRAFTING); + hiddenRecipes = false; } } return true; diff --git a/src/main/java/mezz/jei/recipes/RecipeRegistry.java b/src/main/java/mezz/jei/recipes/RecipeRegistry.java index 7c18d39eb..5d08d8ea3 100644 --- a/src/main/java/mezz/jei/recipes/RecipeRegistry.java +++ b/src/main/java/mezz/jei/recipes/RecipeRegistry.java @@ -61,6 +61,7 @@ public class RecipeRegistry implements IRecipeRegistry { private final ImmutableList unsortedRecipeHandlers; private final ImmutableMultimap recipeHandlers; private final ImmutableList recipeCategories; + private final Set hiddenRecipeCategoryUids = new HashSet<>(); private final List recipeCategoriesVisibleCache = new ArrayList<>(); private final ImmutableTable recipeTransferHandlers; private final ImmutableMultimap, RecipeClickableArea> recipeClickableAreasMap; @@ -371,6 +372,9 @@ public List getRecipeCategories() { } private boolean isCategoryVisible(IRecipeCategory recipeCategory) { + if (hiddenRecipeCategoryUids.contains(recipeCategory.getUid())) { + return false; + } List allCatalysts = getRecipeCatalysts(recipeCategory, true); if (!allCatalysts.isEmpty()) { List visibleCatalysts = getRecipeCatalysts(recipeCategory, false); @@ -728,6 +732,29 @@ public void unhideRecipe(IRecipeWrapper recipe, String recipeCategoryUid) { recipeCategoriesVisibleCache.clear(); } + @Override + public void hideRecipeCategory(String recipeCategoryUid) { + ErrorUtil.checkNotNull(recipeCategoryUid, "recipeCategoryUid"); + ErrorUtil.assertMainThread(); + IRecipeCategory recipeCategory = recipeCategoriesMap.get(recipeCategoryUid); + if (recipeCategory == null) { + throw new IllegalArgumentException("Unknown recipe category: " + recipeCategoryUid); + } + hiddenRecipeCategoryUids.add(recipeCategoryUid); + recipeCategoriesVisibleCache.remove(recipeCategory); + } + + @Override + public void unhideRecipeCategory(String recipeCategoryUid) { + ErrorUtil.checkNotNull(recipeCategoryUid, "recipeCategoryUid"); + ErrorUtil.assertMainThread(); + if (!recipeCategoriesMap.containsKey(recipeCategoryUid)) { + throw new IllegalArgumentException("Unknown recipe category: " + recipeCategoryUid); + } + hiddenRecipeCategoryUids.remove(recipeCategoryUid); + recipeCategoriesVisibleCache.clear(); + } + @Override @Deprecated public void hideRecipe(IRecipeWrapper recipe) { diff --git a/src/main/java/mezz/jei/util/ErrorUtil.java b/src/main/java/mezz/jei/util/ErrorUtil.java index e65d8a928..5ebba5c32 100644 --- a/src/main/java/mezz/jei/util/ErrorUtil.java +++ b/src/main/java/mezz/jei/util/ErrorUtil.java @@ -231,7 +231,12 @@ public static void checkIsValidIngredient(@Nullable Object ingredient, String na public static void assertMainThread() { Minecraft minecraft = Minecraft.getMinecraft(); if (minecraft != null && !minecraft.isCallingFromMinecraftThread()) { - throw new IllegalStateException("A JEI API method is being called by another mod from the wrong thread. It must be called on the main thread."); + Thread currentThread = Thread.currentThread(); + throw new IllegalStateException( + "A JEI API method is being called by another mod from the wrong thread:\n" + + currentThread + "\n" + + "It must be called on the main thread by using Minecraft.addScheduledTask." + ); } }