diff --git a/CommonApi/src/main/java/mezz/jei/api/IModPlugin.java b/CommonApi/src/main/java/mezz/jei/api/IModPlugin.java index 9d7405836..01d4d301c 100644 --- a/CommonApi/src/main/java/mezz/jei/api/IModPlugin.java +++ b/CommonApi/src/main/java/mezz/jei/api/IModPlugin.java @@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation; import mezz.jei.api.registration.IAdvancedRegistration; +import mezz.jei.api.registration.IExtraIngredientRegistration; import mezz.jei.api.registration.IGuiHandlerRegistration; import mezz.jei.api.registration.IModIngredientRegistration; import mezz.jei.api.registration.IRecipeCatalystRegistration; @@ -54,6 +55,16 @@ default void registerIngredients(IModIngredientRegistration registration) { } + /** + * Register extra ItemStacks that are not in the creative menu, + * or FluidStacks that are different from the default ones available via the fluid registry. + * + * @since 19.18.0 + */ + default void registerExtraIngredients(IExtraIngredientRegistration registration) { + + } + /** * Register search aliases for ingredients. * diff --git a/CommonApi/src/main/java/mezz/jei/api/registration/IExtraIngredientRegistration.java b/CommonApi/src/main/java/mezz/jei/api/registration/IExtraIngredientRegistration.java new file mode 100644 index 000000000..ede44aa04 --- /dev/null +++ b/CommonApi/src/main/java/mezz/jei/api/registration/IExtraIngredientRegistration.java @@ -0,0 +1,52 @@ +package mezz.jei.api.registration; + +import mezz.jei.api.IModPlugin; +import mezz.jei.api.constants.VanillaTypes; +import mezz.jei.api.helpers.IColorHelper; +import mezz.jei.api.helpers.IPlatformFluidHelper; +import mezz.jei.api.ingredients.IIngredientHelper; +import mezz.jei.api.ingredients.IIngredientRenderer; +import mezz.jei.api.ingredients.IIngredientType; +import mezz.jei.api.ingredients.subtypes.ISubtypeManager; +import mezz.jei.api.runtime.IIngredientManager; +import net.minecraft.world.item.ItemStack; + +import java.util.Collection; + +/** + * Allows adding extra ingredients (including ItemStack and FluidStack) for any registered ingredient type. + * + * This is intended to be used to add ingredients to another mod's type. + * If you want to add ingredients to your own custom type, + * pass them to {@link IModIngredientRegistration#register} instead. + * + * This is given to your {@link IModPlugin#registerExtraIngredients(IExtraIngredientRegistration)}. + * + * @since 19.18.0 + */ +public interface IExtraIngredientRegistration { + /** + * Add extra ItemStacks that are not already in the creative menu. + * + * @param extraItemStacks A collection of extra ItemStacks to be displayed in the ingredient list. + * + * @since 19.18.0 + */ + default void addExtraItemStacks(Collection extraItemStacks) { + addExtraIngredients(VanillaTypes.ITEM_STACK, extraItemStacks); + } + + /** + * Add extra ingredients to an existing ingredient type. + * + * @param ingredientType The type of the ingredient. + * This must already be registered with {@link IModIngredientRegistration#register} by another mod. + * @param extraIngredients A collection of extra ingredients to be displayed in the ingredient list. + * + * @since 19.18.0 + */ + void addExtraIngredients( + IIngredientType ingredientType, + Collection extraIngredients + ); +} 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 840f2325d..d58fe9ab6 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.IExtraIngredientRegistration; import mezz.jei.api.registration.IIngredientAliasRegistration; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Unmodifiable; @@ -86,6 +87,10 @@ default Collection getAllItemStacks() { /** * Add new ingredients to JEI at runtime. * Used by mods that have items created while the game is running, or use the server to define items. + * + * If you just want to add ingredients to an existing type + * (like adding more ItemStacks or FluidStacks, not at runtime), + * use {@link IExtraIngredientRegistration#addExtraIngredients} instead. */ void addIngredientsAtRuntime(IIngredientType ingredientType, Collection ingredients); 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 97b2e4ea5..6d208320a 100644 --- a/Library/src/main/java/mezz/jei/library/load/PluginLoader.java +++ b/Library/src/main/java/mezz/jei/library/load/PluginLoader.java @@ -84,6 +84,7 @@ public PluginLoader( 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)); if (ingredientFilterConfig.getSearchIngredientAliases()) { PluginCaller.callOnPlugins("Registering search ingredient aliases", plugins, p -> p.registerIngredientAliases(ingredientManagerBuilder)); 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 4bbc5bcfa..7f2e4bde1 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 @@ -8,6 +8,7 @@ import mezz.jei.api.ingredients.IIngredientType; import mezz.jei.api.ingredients.ITypedIngredient; import mezz.jei.api.ingredients.subtypes.ISubtypeManager; +import mezz.jei.api.registration.IExtraIngredientRegistration; import mezz.jei.api.registration.IIngredientAliasRegistration; import mezz.jei.api.registration.IModIngredientRegistration; import mezz.jei.api.runtime.IIngredientManager; @@ -20,7 +21,7 @@ import java.util.LinkedHashMap; import java.util.SequencedMap; -public class IngredientManagerBuilder implements IModIngredientRegistration, IIngredientAliasRegistration { +public class IngredientManagerBuilder implements IModIngredientRegistration, IIngredientAliasRegistration, IExtraIngredientRegistration { private final SequencedMap, IngredientInfo> ingredientInfos = new LinkedHashMap<>(); private final ISubtypeManager subtypeManager; private final IColorHelper colorHelper; @@ -46,7 +47,7 @@ public void register(IIngredientType ingredientType, Collection allIng "ingredients in the ingredient list, and it must have a height of 16" ); if (ingredientInfos.containsKey(ingredientType)) { - throw new IllegalArgumentException("Ingredient type has already been registered: " + ingredientType.getIngredientClass()); + throw new IllegalArgumentException("Ingredient type has already been registered: " + ingredientType.getUid()); } ingredientInfos.put(ingredientType, new IngredientInfo<>(ingredientType, allIngredients, ingredientHelper, ingredientRenderer, null)); @@ -81,6 +82,20 @@ public void register( ingredientInfos.put(ingredientType, new IngredientInfo<>(ingredientType, allIngredients, ingredientHelper, ingredientRenderer, ingredientCodec)); } + @Override + public void addExtraIngredients(IIngredientType ingredientType, Collection extraIngredients) { + ErrorUtil.checkNotNull(ingredientType, "ingredientType"); + ErrorUtil.checkNotNull(extraIngredients, "extraIngredients"); + + IngredientInfo ingredientInfo = ingredientInfos.get(ingredientType); + if (ingredientInfo == null) { + throw new IllegalArgumentException("Ingredient type has not been registered: " + ingredientType.getUid()); + } + @SuppressWarnings("unchecked") + IngredientInfo castIngredientInfo = (IngredientInfo) ingredientInfo; + castIngredientInfo.addIngredients(extraIngredients); + } + @Override public void addAlias(IIngredientType type, I ingredient, String alias) { ErrorUtil.checkNotNull(type, "type"); 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 a416fa4b0..308245fad 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.IIngredientTypeWithSubtypes; import mezz.jei.api.ingredients.ITypedIngredient; import mezz.jei.api.registration.IAdvancedRegistration; +import mezz.jei.api.registration.IExtraIngredientRegistration; import mezz.jei.api.registration.IGuiHandlerRegistration; import mezz.jei.api.registration.IIngredientAliasRegistration; import mezz.jei.api.registration.IModInfoRegistration; @@ -90,6 +91,13 @@ public void registerIngredients(IModIngredientRegistration registration) { } } + @Override + public void registerExtraIngredients(IExtraIngredientRegistration registration) { + if (DebugConfig.isDebugModeEnabled()) { + registration.addExtraIngredients(DebugIngredient.TYPE, DebugIngredientListFactory.create(0, 10)); + } + } + @Override public void registerIngredientAliases(IIngredientAliasRegistration registration) { registration.addAlias( @@ -357,7 +365,7 @@ public void onRuntimeAvailable(IJeiRuntime jeiRuntime) { debugRecipeCategory.setRuntime(jeiRuntime); } IIngredientManager ingredientManager = jeiRuntime.getIngredientManager(); - ingredientManager.addIngredientsAtRuntime(DebugIngredient.TYPE, DebugIngredientListFactory.create()); + ingredientManager.addIngredientsAtRuntime(DebugIngredient.TYPE, DebugIngredientListFactory.create(10, 20)); } } } diff --git a/Library/src/main/java/mezz/jei/library/plugins/debug/ingredients/DebugIngredientListFactory.java b/Library/src/main/java/mezz/jei/library/plugins/debug/ingredients/DebugIngredientListFactory.java index 4623e7ec0..3ed195543 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/debug/ingredients/DebugIngredientListFactory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/debug/ingredients/DebugIngredientListFactory.java @@ -8,9 +8,9 @@ public final class DebugIngredientListFactory { private DebugIngredientListFactory() { } - public static Collection create() { + public static Collection create(int start, int end) { List ingredients = new ArrayList<>(); - for (int i = 0; i < 10; i++) { + for (int i = start; i < end; i++) { DebugIngredient debugIngredient = new DebugIngredient(i); ingredients.add(debugIngredient); } diff --git a/gradle.properties b/gradle.properties index 434367c17..c336fd919 100644 --- a/gradle.properties +++ b/gradle.properties @@ -74,4 +74,4 @@ modrinthId=u6dRKJwZ jUnitVersion=5.8.2 # Version -specificationVersion=19.17.0 +specificationVersion=19.18.0