Class DataComponentIngredient

java.lang.Object
net.neoforged.neoforge.common.crafting.DataComponentIngredient
All Implemented Interfaces:
ICustomIngredient

public class DataComponentIngredient extends Object implements 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

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.MapCodec<DataComponentIngredient>
     
    private final net.minecraft.core.component.DataComponentExactPredicate
     
    private final net.minecraft.core.HolderSet<net.minecraft.world.item.Item>
     
    private final net.minecraft.world.item.ItemStack[]
     
    private final boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DataComponentIngredient(net.minecraft.core.HolderSet<net.minecraft.world.item.Item> items, net.minecraft.core.component.DataComponentExactPredicate components, boolean strict)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    net.minecraft.core.component.DataComponentExactPredicate
     
    net.minecraft.world.item.crafting.display.SlotDisplay
    Returns the display for this ingredient.
    Returns the type of this ingredient.
    boolean
    Returns whether this ingredient always requires direct stack testing.
    boolean
     
    Stream<net.minecraft.core.Holder<net.minecraft.world.item.Item>>
    Returns the list of items that this ingredient accepts.
    net.minecraft.core.HolderSet<net.minecraft.world.item.Item>
     
    static <T> net.minecraft.world.item.crafting.Ingredient
    of(boolean strict, Supplier<? extends net.minecraft.core.component.DataComponentType<? super T>> type, T value, net.minecraft.world.level.ItemLike... items)
    Creates a new ingredient matching any item from the list, containing the given components
    static net.minecraft.world.item.crafting.Ingredient
    of(boolean strict, net.minecraft.core.component.DataComponentExactPredicate predicate, net.minecraft.core.Holder<net.minecraft.world.item.Item>... items)
    Creates a new ingredient matching any item from the list, containing the given components
    static net.minecraft.world.item.crafting.Ingredient
    of(boolean strict, net.minecraft.core.component.DataComponentExactPredicate predicate, net.minecraft.core.HolderSet<net.minecraft.world.item.Item> items)
    Creates a new ingredient matching any item from the list, containing the given components
    static net.minecraft.world.item.crafting.Ingredient
    of(boolean strict, net.minecraft.core.component.DataComponentExactPredicate predicate, net.minecraft.world.level.ItemLike... items)
    Creates a new ingredient matching any item from the list, containing the given components
    static net.minecraft.world.item.crafting.Ingredient
    of(boolean strict, net.minecraft.core.component.DataComponentMap map, net.minecraft.core.Holder<net.minecraft.world.item.Item>... items)
    Creates a new ingredient matching any item from the list, containing the given components
    static net.minecraft.world.item.crafting.Ingredient
    of(boolean strict, net.minecraft.core.component.DataComponentMap map, net.minecraft.core.HolderSet<net.minecraft.world.item.Item> items)
    Creates a new ingredient matching any item from the list, containing the given components
    static net.minecraft.world.item.crafting.Ingredient
    of(boolean strict, net.minecraft.core.component.DataComponentMap map, net.minecraft.world.level.ItemLike... items)
    Creates a new ingredient matching any item from the list, containing the given components
    static <T> net.minecraft.world.item.crafting.Ingredient
    of(boolean strict, net.minecraft.core.component.DataComponentType<? super T> type, T value, net.minecraft.world.level.ItemLike... items)
    Creates a new ingredient matching any item from the list, containing the given components
    static net.minecraft.world.item.crafting.Ingredient
    of(boolean strict, net.minecraft.world.item.ItemStack stack)
    Creates a new ingredient matching the given item, containing the given components
    boolean
    test(net.minecraft.world.item.ItemStack stack)
    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

      public static final com.mojang.serialization.MapCodec<DataComponentIngredient> CODEC
    • items

      private final net.minecraft.core.HolderSet<net.minecraft.world.item.Item> items
    • components

      private final net.minecraft.core.component.DataComponentExactPredicate components
    • strict

      private final boolean strict
    • stacks

      private final net.minecraft.world.item.ItemStack[] stacks
  • Constructor Details

    • DataComponentIngredient

      public DataComponentIngredient(net.minecraft.core.HolderSet<net.minecraft.world.item.Item> items, net.minecraft.core.component.DataComponentExactPredicate components, boolean strict)
  • Method Details

    • test

      public boolean test(net.minecraft.world.item.ItemStack stack)
      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 interface ICustomIngredient
      Parameters:
      stack - the stack to test
      Returns:
      true if the stack matches this ingredient, false otherwise
    • items

      public Stream<net.minecraft.core.Holder<net.minecraft.world.item.Item>> items()
      Description copied from interface: ICustomIngredient
      Returns 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 stack is 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:
      items in interface ICustomIngredient
      Returns:
      the list of items 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 interface ICustomIngredient
      Returns:
      true if this ingredient ignores NBT data when matching stacks, false otherwise
      See Also:
      • Ingredient.isSimple()
    • getType

      public IngredientType<?> 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 interface ICustomIngredient
      Returns:
      the type of this ingredient
    • display

      public net.minecraft.world.item.crafting.display.SlotDisplay display()
      Description copied from interface: ICustomIngredient
      Returns 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:
      display in interface ICustomIngredient
    • itemSet

      public net.minecraft.core.HolderSet<net.minecraft.world.item.Item> itemSet()
    • components

      public net.minecraft.core.component.DataComponentExactPredicate components()
    • isStrict

      public boolean isStrict()
    • of

      public static net.minecraft.world.item.crafting.Ingredient of(boolean strict, net.minecraft.world.item.ItemStack stack)
      Creates a new ingredient matching the given item, containing the given components
    • of

      public static <T> net.minecraft.world.item.crafting.Ingredient of(boolean strict, net.minecraft.core.component.DataComponentType<? super T> type, T value, net.minecraft.world.level.ItemLike... items)
      Creates a new ingredient matching any item from the list, containing the given components
    • of

      public static <T> net.minecraft.world.item.crafting.Ingredient of(boolean strict, Supplier<? extends net.minecraft.core.component.DataComponentType<? super T>> type, T value, net.minecraft.world.level.ItemLike... items)
      Creates a new ingredient matching any item from the list, containing the given components
    • of

      public static net.minecraft.world.item.crafting.Ingredient of(boolean strict, net.minecraft.core.component.DataComponentMap map, net.minecraft.world.level.ItemLike... items)
      Creates a new ingredient matching any item from the list, containing the given components
    • of

      @SafeVarargs public static net.minecraft.world.item.crafting.Ingredient of(boolean strict, net.minecraft.core.component.DataComponentMap map, net.minecraft.core.Holder<net.minecraft.world.item.Item>... items)
      Creates a new ingredient matching any item from the list, containing the given components
    • of

      public static net.minecraft.world.item.crafting.Ingredient of(boolean strict, net.minecraft.core.component.DataComponentMap map, net.minecraft.core.HolderSet<net.minecraft.world.item.Item> items)
      Creates a new ingredient matching any item from the list, containing the given components
    • of

      @SafeVarargs public static net.minecraft.world.item.crafting.Ingredient of(boolean strict, net.minecraft.core.component.DataComponentExactPredicate predicate, net.minecraft.core.Holder<net.minecraft.world.item.Item>... items)
      Creates a new ingredient matching any item from the list, containing the given components
    • of

      public static net.minecraft.world.item.crafting.Ingredient of(boolean strict, net.minecraft.core.component.DataComponentExactPredicate predicate, net.minecraft.world.level.ItemLike... items)
      Creates a new ingredient matching any item from the list, containing the given components
    • of

      public static net.minecraft.world.item.crafting.Ingredient of(boolean strict, net.minecraft.core.component.DataComponentExactPredicate predicate, net.minecraft.core.HolderSet<net.minecraft.world.item.Item> items)
      Creates a new ingredient matching any item from the list, containing the given components