Skip to content

Commit

Permalink
Add convenience methods for adding multiple catalysts to one recipe c…
Browse files Browse the repository at this point in the history
…ategory
  • Loading branch information
mezz committed Oct 1, 2024
1 parent 40f7fbd commit dee2eaf
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;

import java.util.List;

public interface IRecipeCatalystRegistration {
/**
* The {@link IIngredientManager} has some useful functions related to recipe ingredients.
Expand All @@ -21,6 +23,48 @@ public interface IRecipeCatalystRegistration {
*/
IJeiHelpers getJeiHelpers();

/**
* Add an association between {@link ItemLike}s and what it can craft.
* (i.e. Furnace Item can craft Smelting and Fuel Recipes)
* Allows players to see what ingredient they need to craft in order to make recipes from a recipe category.
*
* @param recipeType the types of recipe that the ingredient is a catalyst for
* @param ingredients the {@link ItemLike}s that can craft recipes (like a furnace or crafting table)
*
* @see #addRecipeCatalysts(RecipeType, ItemStack...) to add {@link ItemStack} catalysts.
* @see #addRecipeCatalysts(RecipeType, IIngredientType, List) to add non-{@link ItemLike} catalysts.
*
* @since 19.19.2
*/
void addRecipeCatalysts(RecipeType<?> recipeType, ItemLike... ingredients);

/**
* Add an association between an {@link ItemStack} and what it can craft.
* (i.e. Furnace ItemStack can craft Smelting and Fuel Recipes)
* Allows players to see what ingredient they need to craft in order to make recipes from a recipe category.
*
* @param ingredients the {@link ItemStack}s that can craft recipes (like a furnace or crafting table)
* @param recipeType the type of recipe that the ingredients are a catalyst for
*
* @see #addRecipeCatalysts(RecipeType, IIngredientType, List) to add non-{@link ItemStack} catalysts.
*
* @since 19.19.2
*/
default void addRecipeCatalysts(RecipeType<?> recipeType, ItemStack... ingredients) {
addRecipeCatalysts(recipeType, VanillaTypes.ITEM_STACK, List.of(ingredients));
}

/**
* Add an association between ingredients and what it can craft. (i.e. Furnace ItemStack -> Smelting and Fuel Recipes)
* Allows players to see what ingredients they need to craft in order to make recipes from a recipe category.
*
* @param recipeType the type of recipe that the ingredients are a catalyst for
* @param ingredientType the type of the ingredient
* @param ingredients the ingredients that can craft recipes (like a furnace or crafting table)
* @since 19.19.2
*/
<T> void addRecipeCatalysts(RecipeType<?> recipeType, IIngredientType<T> ingredientType, List<T> ingredients);

/**
* Add an association between an {@link ItemStack} and what it can craft.
* (i.e. Furnace ItemStack can craft Smelting and Fuel Recipes)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mezz.jei.library.load.registration;

import com.google.common.collect.ImmutableListMultimap;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.helpers.IJeiHelpers;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.ingredients.ITypedIngredient;
Expand All @@ -10,6 +11,10 @@
import mezz.jei.common.util.ErrorUtil;
import mezz.jei.core.collect.ListMultiMap;
import mezz.jei.library.ingredients.TypedIngredient;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;

import java.util.List;

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

@Override
public void addRecipeCatalysts(RecipeType<?> recipeType, ItemLike... ingredients) {
ErrorUtil.checkNotNull(recipeType, "recipeType");
ErrorUtil.checkNotNull(ingredients, "ingredients");

for (ItemLike itemLike : ingredients) {
ItemStack itemStack = itemLike.asItem().getDefaultInstance();
ITypedIngredient<ItemStack> typedIngredient = TypedIngredient.createAndFilterInvalid(this.ingredientManager, VanillaTypes.ITEM_STACK, itemStack, true)
.orElseThrow(() -> new IllegalArgumentException("Recipe catalyst must be valid"));
this.recipeCatalysts.put(recipeType, typedIngredient);
}
}

@Override
public <T> void addRecipeCatalysts(RecipeType<?> recipeType, IIngredientType<T> ingredientType, List<T> ingredients) {
ErrorUtil.checkNotNull(recipeType, "recipeType");
ErrorUtil.checkNotNull(ingredientType, "ingredientType");
ErrorUtil.checkNotNull(ingredients, "ingredients");

for (T ingredient : ingredients) {
ITypedIngredient<T> typedIngredient = TypedIngredient.createAndFilterInvalid(this.ingredientManager, ingredientType, ingredient, true)
.orElseThrow(() -> new IllegalArgumentException("Recipe catalyst must be valid"));
this.recipeCatalysts.put(recipeType, typedIngredient);
}
}

public ImmutableListMultimap<RecipeType<?>, ITypedIngredient<?>> getRecipeCatalysts() {
return recipeCatalysts.toImmutable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,23 @@ public void registerRecipeTransferHandlers(IRecipeTransferRegistration registrat

@Override
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
registration.addRecipeCatalyst(Blocks.CRAFTING_TABLE, RecipeTypes.CRAFTING);
registration.addRecipeCatalyst(Blocks.CRAFTER, RecipeTypes.CRAFTING);
registration.addRecipeCatalysts(RecipeTypes.CRAFTING,
Blocks.CRAFTING_TABLE,
Blocks.CRAFTER
);
registration.addRecipeCatalysts(RecipeTypes.FUELING,
Blocks.FURNACE,
Blocks.SMOKER,
Blocks.BLAST_FURNACE
);
registration.addRecipeCatalysts(RecipeTypes.CAMPFIRE_COOKING,
Blocks.CAMPFIRE,
Blocks.SOUL_CAMPFIRE
);
registration.addRecipeCatalyst(Blocks.STONECUTTER, RecipeTypes.STONECUTTING);
registration.addRecipeCatalyst(Blocks.FURNACE, RecipeTypes.SMELTING, RecipeTypes.FUELING);

registration.addRecipeCatalyst(Blocks.SMOKER, RecipeTypes.SMOKING, RecipeTypes.FUELING);
registration.addRecipeCatalyst(Blocks.BLAST_FURNACE, RecipeTypes.BLASTING, RecipeTypes.FUELING);
registration.addRecipeCatalyst(Blocks.CAMPFIRE, RecipeTypes.CAMPFIRE_COOKING);
registration.addRecipeCatalyst(Blocks.SOUL_CAMPFIRE, RecipeTypes.CAMPFIRE_COOKING);
registration.addRecipeCatalyst(Blocks.FURNACE, RecipeTypes.SMELTING);
registration.addRecipeCatalyst(Blocks.SMOKER, RecipeTypes.SMOKING);
registration.addRecipeCatalyst(Blocks.BLAST_FURNACE, RecipeTypes.BLASTING);
registration.addRecipeCatalyst(Blocks.BREWING_STAND, RecipeTypes.BREWING);
registration.addRecipeCatalyst(Blocks.ANVIL, RecipeTypes.ANVIL);
registration.addRecipeCatalyst(Blocks.SMITHING_TABLE, RecipeTypes.SMITHING);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ modrinthId=u6dRKJwZ
jUnitVersion=5.8.2

# Version
specificationVersion=19.19.1
specificationVersion=19.19.2

0 comments on commit dee2eaf

Please sign in to comment.