Class DataComponentIngredient
java.lang.Object
net.neoforged.neoforge.common.crafting.DataComponentIngredient
- All Implemented Interfaces:
ICustomIngredient
Ingredient that matches the given items, and components as defined by a
DataComponentPatch.
Strict NBT ingredients will only match items that have exactly the provided tag, while partial ones will match if the item's tags contain all of the elements of the provided one, while allowing for additional elements to exist.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.MapCodec<DataComponentIngredient> private final DataComponentPatchprivate final boolean -
Constructor Summary
ConstructorsConstructorDescriptionDataComponentIngredient(HolderSet<Item> items, DataComponentPatch components, boolean exhaustive) -
Method Summary
Modifier and TypeMethodDescriptionprivate static DataComponentPatchasPatch(DataComponentMap map) booleanReturns true if item stacks that have any component not listed in the components of this ingredient will fail to match.display()Returns the display for this ingredient.getType()Returns the type of this ingredient.booleanisSimple()Returns whether this ingredient always requires direct stack testing.booleanisStrict()Deprecated, for removal: This API element is subject to removal in a future version.items()Returns the list of items that this ingredient accepts.itemSet()static <T> Ingredientof(boolean exhaustive, Supplier<? extends DataComponentType<? super T>> type, T value, ItemLike... items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredientof(boolean exhaustive, DataComponentMap map, Holder<Item>... items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredientof(boolean exhaustive, DataComponentMap map, HolderSet<Item> items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredientof(boolean exhaustive, DataComponentMap map, ItemLike... items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredientof(boolean exhaustive, DataComponentPatch predicate, Holder<Item>... items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredientof(boolean exhaustive, DataComponentPatch predicate, HolderSet<Item> items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredientof(boolean exhaustive, DataComponentPatch predicate, ItemLike... items) Creates a new ingredient matching any item from the list, that contains the components set on the given patch and that does not contain the components removed by the given patch.static <T> Ingredientof(boolean exhaustive, DataComponentType<? super T> type, T value, ItemLike... items) Creates a new ingredient matching any item from the list, containing the given componentsstatic IngredientCreates a new ingredient matching the given item, containing the given componentsstatic Ingredientof(boolean exhaustive, ItemStackTemplate stack) Creates a new ingredient matching the given item, containing the given componentsstatic Ingredientof(DataComponentPatch predicate, ItemLike... items) Creates a new ingredient matching any item from the list, that contains the components set on the given patch and that does not contain the components removed by the given patch.static <T> Ingredientof(DataComponentType<? super T> type, T value, ItemLike... items) Creates a new ingredient matching any item from the list, containing the given componentsbooleanChecks if a stack matches this ingredient.private booleantestComponents(DataComponentGetter getter) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ICustomIngredient
toVanilla
-
Field Details
-
CODEC
-
items
-
components
-
exhaustive
private final boolean exhaustive
-
-
Constructor Details
-
DataComponentIngredient
public DataComponentIngredient(HolderSet<Item> items, DataComponentPatch components, boolean exhaustive)
-
-
Method Details
-
test
Description copied from interface:ICustomIngredientChecks if a stack matches this ingredient. The stack must not be modified in any way.- Specified by:
testin interfaceICustomIngredient- Parameters:
stack- the stack to test- Returns:
trueif the stack matches this ingredient,falseotherwise
-
testComponents
-
items
Description copied from interface:ICustomIngredientReturns the list of items that this ingredient accepts.The following guidelines should be followed for good compatibility:
- At least one item must be returned for the ingredient not to be considered empty. Empty ingredients invalidate the entire recipe.
- The ingredient should return all
Items it might possible accept. This allows mods that inspect the ingredient to figure out which stacks it might accept. - Returned items might not always be accepted by the ingredient, as an ingredient might still perform additional NBT-dependent tests.
- An exception is ingredients that are simple,
for which
testing a stackis equivalent to testing if the item is in the returned list.
Note: no caching needs to be done by the implementation, this is already handled by the ingredient itself.
- Specified by:
itemsin interfaceICustomIngredient- Returns:
- the list of items that this ingredient accepts
-
isSimple
public boolean isSimple()Description copied from interface:ICustomIngredientReturns whether this ingredient always requires direct stack testing.- Specified by:
isSimplein interfaceICustomIngredient- Returns:
trueif this ingredient ignores NBT data when matching stacks,falseotherwise- See Also:
-
getType
Description copied from interface:ICustomIngredientReturns the type of this ingredient.The type must be registered to
NeoForgeRegistries.INGREDIENT_TYPES.- Specified by:
getTypein interfaceICustomIngredient- Returns:
- the type of this ingredient
-
display
Description copied from interface:ICustomIngredientReturns the display for this ingredient.The display is synced to the client, and is also used to retrieve the
ItemStacks that are shown to the client.- Specified by:
displayin interfaceICustomIngredient
-
itemSet
-
components
-
componentsExhaustive
public boolean componentsExhaustive()Returns true if item stacks that have any component not listed in the components of this ingredient will fail to match.- Returns:
- true if item stacks that have any component not listed in the components of this ingredient will fail to match
-
isStrict
Deprecated, for removal: This API element is subject to removal in a future version. -
of
Creates a new ingredient matching the given item, containing the given components -
of
Creates a new ingredient matching the given item, containing the given components -
of
Creates a new ingredient matching any item from the list, containing the given components -
of
public static <T> Ingredient of(boolean exhaustive, DataComponentType<? super T> type, T value, ItemLike... items) Creates a new ingredient matching any item from the list, containing the given components -
of
public static <T> Ingredient of(boolean exhaustive, Supplier<? extends DataComponentType<? super T>> type, T value, ItemLike... items) Creates a new ingredient matching any item from the list, containing the given components -
of
Creates a new ingredient matching any item from the list, containing the given components -
of
@SafeVarargs public static Ingredient of(boolean exhaustive, DataComponentMap map, Holder<Item>... items) Creates a new ingredient matching any item from the list, containing the given components -
of
Creates a new ingredient matching any item from the list, containing the given components -
asPatch
-
of
@SafeVarargs public static Ingredient of(boolean exhaustive, DataComponentPatch predicate, Holder<Item>... items) Creates a new ingredient matching any item from the list, containing the given components -
of
Creates a new ingredient matching any item from the list, that contains the components set on the given patch and that does not contain the components removed by the given patch. -
of
Creates a new ingredient matching any item from the list, that contains the components set on the given patch and that does not contain the components removed by the given patch.- Parameters:
exhaustive- If true, no other components besides the components set on the patch are allowed on an item to match.
-
of
public static Ingredient of(boolean exhaustive, DataComponentPatch predicate, HolderSet<Item> items) Creates a new ingredient matching any item from the list, containing the given components
-