Skip to content

Commit dee2eaf

Browse files
committed
Add convenience methods for adding multiple catalysts to one recipe category
1 parent 40f7fbd commit dee2eaf

File tree

4 files changed

+92
-9
lines changed

4 files changed

+92
-9
lines changed

CommonApi/src/main/java/mezz/jei/api/registration/IRecipeCatalystRegistration.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import net.minecraft.world.item.ItemStack;
99
import net.minecraft.world.level.ItemLike;
1010

11+
import java.util.List;
12+
1113
public interface IRecipeCatalystRegistration {
1214
/**
1315
* The {@link IIngredientManager} has some useful functions related to recipe ingredients.
@@ -21,6 +23,48 @@ public interface IRecipeCatalystRegistration {
2123
*/
2224
IJeiHelpers getJeiHelpers();
2325

26+
/**
27+
* Add an association between {@link ItemLike}s and what it can craft.
28+
* (i.e. Furnace Item can craft Smelting and Fuel Recipes)
29+
* Allows players to see what ingredient they need to craft in order to make recipes from a recipe category.
30+
*
31+
* @param recipeType the types of recipe that the ingredient is a catalyst for
32+
* @param ingredients the {@link ItemLike}s that can craft recipes (like a furnace or crafting table)
33+
*
34+
* @see #addRecipeCatalysts(RecipeType, ItemStack...) to add {@link ItemStack} catalysts.
35+
* @see #addRecipeCatalysts(RecipeType, IIngredientType, List) to add non-{@link ItemLike} catalysts.
36+
*
37+
* @since 19.19.2
38+
*/
39+
void addRecipeCatalysts(RecipeType<?> recipeType, ItemLike... ingredients);
40+
41+
/**
42+
* Add an association between an {@link ItemStack} and what it can craft.
43+
* (i.e. Furnace ItemStack can craft Smelting and Fuel Recipes)
44+
* Allows players to see what ingredient they need to craft in order to make recipes from a recipe category.
45+
*
46+
* @param ingredients the {@link ItemStack}s that can craft recipes (like a furnace or crafting table)
47+
* @param recipeType the type of recipe that the ingredients are a catalyst for
48+
*
49+
* @see #addRecipeCatalysts(RecipeType, IIngredientType, List) to add non-{@link ItemStack} catalysts.
50+
*
51+
* @since 19.19.2
52+
*/
53+
default void addRecipeCatalysts(RecipeType<?> recipeType, ItemStack... ingredients) {
54+
addRecipeCatalysts(recipeType, VanillaTypes.ITEM_STACK, List.of(ingredients));
55+
}
56+
57+
/**
58+
* Add an association between ingredients and what it can craft. (i.e. Furnace ItemStack -> Smelting and Fuel Recipes)
59+
* Allows players to see what ingredients they need to craft in order to make recipes from a recipe category.
60+
*
61+
* @param recipeType the type of recipe that the ingredients are a catalyst for
62+
* @param ingredientType the type of the ingredient
63+
* @param ingredients the ingredients that can craft recipes (like a furnace or crafting table)
64+
* @since 19.19.2
65+
*/
66+
<T> void addRecipeCatalysts(RecipeType<?> recipeType, IIngredientType<T> ingredientType, List<T> ingredients);
67+
2468
/**
2569
* Add an association between an {@link ItemStack} and what it can craft.
2670
* (i.e. Furnace ItemStack can craft Smelting and Fuel Recipes)

Library/src/main/java/mezz/jei/library/load/registration/RecipeCatalystRegistration.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mezz.jei.library.load.registration;
22

33
import com.google.common.collect.ImmutableListMultimap;
4+
import mezz.jei.api.constants.VanillaTypes;
45
import mezz.jei.api.helpers.IJeiHelpers;
56
import mezz.jei.api.ingredients.IIngredientType;
67
import mezz.jei.api.ingredients.ITypedIngredient;
@@ -10,6 +11,10 @@
1011
import mezz.jei.common.util.ErrorUtil;
1112
import mezz.jei.core.collect.ListMultiMap;
1213
import mezz.jei.library.ingredients.TypedIngredient;
14+
import net.minecraft.world.item.ItemStack;
15+
import net.minecraft.world.level.ItemLike;
16+
17+
import java.util.List;
1318

1419
public class RecipeCatalystRegistration implements IRecipeCatalystRegistration {
1520
private final ListMultiMap<RecipeType<?>, ITypedIngredient<?>> recipeCatalysts = new ListMultiMap<>();
@@ -45,6 +50,32 @@ public <T> void addRecipeCatalyst(IIngredientType<T> ingredientType, T ingredien
4550
}
4651
}
4752

53+
@Override
54+
public void addRecipeCatalysts(RecipeType<?> recipeType, ItemLike... ingredients) {
55+
ErrorUtil.checkNotNull(recipeType, "recipeType");
56+
ErrorUtil.checkNotNull(ingredients, "ingredients");
57+
58+
for (ItemLike itemLike : ingredients) {
59+
ItemStack itemStack = itemLike.asItem().getDefaultInstance();
60+
ITypedIngredient<ItemStack> typedIngredient = TypedIngredient.createAndFilterInvalid(this.ingredientManager, VanillaTypes.ITEM_STACK, itemStack, true)
61+
.orElseThrow(() -> new IllegalArgumentException("Recipe catalyst must be valid"));
62+
this.recipeCatalysts.put(recipeType, typedIngredient);
63+
}
64+
}
65+
66+
@Override
67+
public <T> void addRecipeCatalysts(RecipeType<?> recipeType, IIngredientType<T> ingredientType, List<T> ingredients) {
68+
ErrorUtil.checkNotNull(recipeType, "recipeType");
69+
ErrorUtil.checkNotNull(ingredientType, "ingredientType");
70+
ErrorUtil.checkNotNull(ingredients, "ingredients");
71+
72+
for (T ingredient : ingredients) {
73+
ITypedIngredient<T> typedIngredient = TypedIngredient.createAndFilterInvalid(this.ingredientManager, ingredientType, ingredient, true)
74+
.orElseThrow(() -> new IllegalArgumentException("Recipe catalyst must be valid"));
75+
this.recipeCatalysts.put(recipeType, typedIngredient);
76+
}
77+
}
78+
4879
public ImmutableListMultimap<RecipeType<?>, ITypedIngredient<?>> getRecipeCatalysts() {
4980
return recipeCatalysts.toImmutable();
5081
}

Library/src/main/java/mezz/jei/library/plugins/vanilla/VanillaPlugin.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,23 @@ public void registerRecipeTransferHandlers(IRecipeTransferRegistration registrat
322322

323323
@Override
324324
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
325-
registration.addRecipeCatalyst(Blocks.CRAFTING_TABLE, RecipeTypes.CRAFTING);
326-
registration.addRecipeCatalyst(Blocks.CRAFTER, RecipeTypes.CRAFTING);
325+
registration.addRecipeCatalysts(RecipeTypes.CRAFTING,
326+
Blocks.CRAFTING_TABLE,
327+
Blocks.CRAFTER
328+
);
329+
registration.addRecipeCatalysts(RecipeTypes.FUELING,
330+
Blocks.FURNACE,
331+
Blocks.SMOKER,
332+
Blocks.BLAST_FURNACE
333+
);
334+
registration.addRecipeCatalysts(RecipeTypes.CAMPFIRE_COOKING,
335+
Blocks.CAMPFIRE,
336+
Blocks.SOUL_CAMPFIRE
337+
);
327338
registration.addRecipeCatalyst(Blocks.STONECUTTER, RecipeTypes.STONECUTTING);
328-
registration.addRecipeCatalyst(Blocks.FURNACE, RecipeTypes.SMELTING, RecipeTypes.FUELING);
329-
330-
registration.addRecipeCatalyst(Blocks.SMOKER, RecipeTypes.SMOKING, RecipeTypes.FUELING);
331-
registration.addRecipeCatalyst(Blocks.BLAST_FURNACE, RecipeTypes.BLASTING, RecipeTypes.FUELING);
332-
registration.addRecipeCatalyst(Blocks.CAMPFIRE, RecipeTypes.CAMPFIRE_COOKING);
333-
registration.addRecipeCatalyst(Blocks.SOUL_CAMPFIRE, RecipeTypes.CAMPFIRE_COOKING);
339+
registration.addRecipeCatalyst(Blocks.FURNACE, RecipeTypes.SMELTING);
340+
registration.addRecipeCatalyst(Blocks.SMOKER, RecipeTypes.SMOKING);
341+
registration.addRecipeCatalyst(Blocks.BLAST_FURNACE, RecipeTypes.BLASTING);
334342
registration.addRecipeCatalyst(Blocks.BREWING_STAND, RecipeTypes.BREWING);
335343
registration.addRecipeCatalyst(Blocks.ANVIL, RecipeTypes.ANVIL);
336344
registration.addRecipeCatalyst(Blocks.SMITHING_TABLE, RecipeTypes.SMITHING);

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ modrinthId=u6dRKJwZ
7474
jUnitVersion=5.8.2
7575

7676
# Version
77-
specificationVersion=19.19.1
77+
specificationVersion=19.19.2

0 commit comments

Comments
 (0)