Class DataComponentIngredient
java.lang.Object
net.neoforged.neoforge.common.crafting.DataComponentIngredient
- All Implemented Interfaces:
ICustomIngredient
Ingredient that matches the given items, performing either a
strict
or a partial NBT test.
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
Modifier and TypeFieldDescriptionstatic final com.mojang.serialization.MapCodec
<DataComponentIngredient> private final DataComponentPredicate
private final ItemStack[]
private final boolean
-
Constructor Summary
ConstructorDescriptionDataComponentIngredient
(HolderSet<Item> items, DataComponentPredicate components, boolean strict) -
Method Summary
Modifier and TypeMethodDescriptiongetItems()
Returns the list of stacks that this ingredient accepts.getType()
Returns the type of this ingredient.boolean
isSimple()
Returns whether this ingredient always requires direct stack testing.boolean
isStrict()
items()
static <T> Ingredient
of
(boolean strict, Supplier<? extends DataComponentType<? super T>> type, T value, ItemLike... items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredient
of
(boolean strict, DataComponentMap map, Holder<Item>... items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredient
of
(boolean strict, DataComponentMap map, HolderSet<Item> items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredient
of
(boolean strict, DataComponentMap map, ItemLike... items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredient
of
(boolean strict, DataComponentPredicate predicate, Holder<Item>... items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredient
of
(boolean strict, DataComponentPredicate predicate, HolderSet<Item> items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredient
of
(boolean strict, DataComponentPredicate predicate, ItemLike... items) Creates a new ingredient matching any item from the list, containing the given componentsstatic <T> Ingredient
of
(boolean strict, DataComponentType<? super T> type, T value, ItemLike... items) Creates a new ingredient matching any item from the list, containing the given componentsstatic Ingredient
Creates a new ingredient matching the given item, containing the given componentsboolean
Checks if a stack matches this ingredient.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.neoforged.neoforge.common.crafting.ICustomIngredient
toVanilla
-
Field Details
-
CODEC
-
items
-
components
-
strict
private final boolean strict -
stacks
-
-
Constructor Details
-
DataComponentIngredient
public DataComponentIngredient(HolderSet<Item> items, DataComponentPredicate components, boolean strict)
-
-
Method Details
-
test
Description copied from interface:ICustomIngredient
Checks if a stack matches this ingredient. The stack must not be modified in any way.- Specified by:
test
in interfaceICustomIngredient
- Parameters:
stack
- the stack to test- Returns:
true
if the stack matches this ingredient,false
otherwise
-
getItems
Description copied from interface:ICustomIngredient
Returns the list of stacks that this ingredient accepts.The following guidelines should be followed for good compatibility:
- These stacks are generally used for display purposes, and need not be exhaustive or perfectly accurate.
- An exception is ingredients that are simple,
for which it is important that the returned stacks correspond exactly to all the accepted
Item
s. - At least one stack must be returned for the ingredient not to be considered accidentally empty.
- The ingredient should try to return at least one stack with each accepted
Item
. This allows mods that inspect the ingredient to figure out which stacks it might accept.
Note: no caching needs to be done by the implementation, this is already handled by the ingredient itself.
- Specified by:
getItems
in interfaceICustomIngredient
- Returns:
- the list of stacks that this ingredient accepts
-
isSimple
public boolean isSimple()Description copied from interface:ICustomIngredient
Returns whether this ingredient always requires direct stack testing.- Specified by:
isSimple
in interfaceICustomIngredient
- Returns:
true
if this ingredient ignores NBT data when matching stacks,false
otherwise- See Also:
-
getType
Description copied from interface:ICustomIngredient
Returns the type of this ingredient.The type must be registered to
NeoForgeRegistries.INGREDIENT_TYPES
.- Specified by:
getType
in interfaceICustomIngredient
- Returns:
- the type of this ingredient
-
items
-
components
-
isStrict
public boolean isStrict() -
of
Creates a new ingredient matching the given item, containing the given components -
of
public static <T> Ingredient of(boolean strict, 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 strict, 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 strict, 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 -
of
@SafeVarargs public static Ingredient of(boolean strict, DataComponentPredicate 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, containing the given components -
of
public static Ingredient of(boolean strict, DataComponentPredicate predicate, HolderSet<Item> items) Creates a new ingredient matching any item from the list, containing the given components
-