Class RecipeOutputWrapper
java.lang.Object
net.neoforged.neoforge.common.data.RecipeOutputWrapper
- All Implemented Interfaces:
AutoCloseable, RecipeOutput, BootstrapContextAccess, ScopedRecipeOutput, BootstrapContextAccessExtension, IRecipeOutputExtension
An internal wrapper around
RecipeOutput to handle scoping conditions and changing the
default mod id used in RecipeBuilders.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final record -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final it.unimi.dsi.fastutil.Stack<RecipeOutputWrapper.Context> (package private) static final ICondition[]private final RecipeOutput -
Constructor Summary
ConstructorsModifierConstructorDescriptionRecipeOutputWrapper(RecipeOutput output, @Nullable String defaultModId, ICondition[] defaultConditions) privateRecipeOutputWrapper(RecipeOutput output, RecipeOutputWrapper.Context context) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(ResourceKey<Recipe<?>> key, Recipe<?> recipe, @Nullable AdvancementHolder advancement, ICondition... conditions) Generates a recipe with the given conditions.voidclose()private ICondition[]Returns the conditions at the top the stack, or an empty array.<S> Stream<Holder.Reference<S>> listContextElements(ResourceKey<? extends Registry<? extends S>> key) <S> HolderGetter<S> lookup(ResourceKey<? extends Registry<? extends S>> key) (package private) static ICondition[]mergeConditions(ICondition[] originalConditions, ICondition... newConditions) A helper to merge two condition arrays into a new array.modId()Returns the mod id at the top the stack, ornull.static ResourceKey<Recipe<?>> modifyKey(RecipeOutput output, ResourceKey<Recipe<?>> original) Modifies the namespace of the key identifier if the current mod id context is notnull.static RecipeOutputsingleUse(RecipeOutput output, UnaryOperator<RecipeContextBuilder> builder) Sets the context of the providedRecipeOutputusing theRecipeContextBuilder.static RecipeOutputWrapperwithContext(RecipeOutput output, UnaryOperator<RecipeContextBuilder> builder) Sets the context of the providedRecipeOutputusing theRecipeContextBuilder.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BootstrapContextAccessExtension
holderLookupMethods inherited from interface IRecipeOutputExtension
withConditions, withContextMethods inherited from interface RecipeOutput
accept
-
Field Details
-
EMPTY
-
output
-
context
-
-
Constructor Details
-
RecipeOutputWrapper
public RecipeOutputWrapper(RecipeOutput output, @Nullable String defaultModId, ICondition[] defaultConditions) - Parameters:
output- The originalRecipeOutput.defaultModId- The default mod id to apply toRecipeBuilder.save(RecipeOutput)andRecipeBuilder.save(RecipeOutput, String).defaultConditions- The base conditions to apply to all recipes.
-
RecipeOutputWrapper
-
-
Method Details
-
withContext
public static RecipeOutputWrapper withContext(RecipeOutput output, UnaryOperator<RecipeContextBuilder> builder) Sets the context of the providedRecipeOutputusing theRecipeContextBuilder. If the provided output is already aRecipeOutputWrapper, then the context is appended to the existing wrapper. Otherwise, a newRecipeOutputWrapperis created. This should be used in atry-with-resources block.- Parameters:
output- The original recipe output.builder- A unary operator used to construct the context.- Returns:
- A wrapped recipe output.
-
singleUse
public static RecipeOutput singleUse(RecipeOutput output, UnaryOperator<RecipeContextBuilder> builder) Sets the context of the provided
RecipeOutputusing theRecipeContextBuilder. If the provided output is already aRecipeOutputWrapper, then the context is appended to the existing wrapper. Otherwise, a newRecipeOutputWrapperis created.This should be used only if the context is provided for a few recipes. Otherwise, use
withContext(RecipeOutput, UnaryOperator).- Parameters:
output- The original recipe output.builder- A unary operator used to construct the context.- Returns:
- A single use recipe output.
-
modifyKey
public static ResourceKey<Recipe<?>> modifyKey(RecipeOutput output, ResourceKey<Recipe<?>> original) Modifies the namespace of the key identifier if the current mod id context is notnull. Otherwise, the original key is returned.- Parameters:
output- The original recipe output.original- The originalResourceKeyof the recipe.- Returns:
- The newly wrapped recipe key, or the original if the mod id context is
null.
-
advancement
- Specified by:
advancementin interfaceRecipeOutput
-
lookup
- Specified by:
lookupin interfaceBootstrapContextAccess
-
listContextElements
public <S> Stream<Holder.Reference<S>> listContextElements(ResourceKey<? extends Registry<? extends S>> key) - Specified by:
listContextElementsin interfaceBootstrapContextAccess
-
accept
public void accept(ResourceKey<Recipe<?>> key, Recipe<?> recipe, @Nullable AdvancementHolder advancement, ICondition... conditions) Description copied from interface:IRecipeOutputExtensionGenerates a recipe with the given conditions.- Specified by:
acceptin interfaceIRecipeOutputExtension
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceScopedRecipeOutput
-
modId
-
conditions
Returns the conditions at the top the stack, or an empty array.- Returns:
- the conditions at the top the stack, or an empty array
-
mergeConditions
A helper to merge two condition arrays into a new array.- Parameters:
originalConditions- The original condition array to merge.newConditions- The array of new conditions to merge.- Returns:
- A new array containing all conditions.
-