Class DefaultCustomIngredients

java.lang.Object
net.fabricmc.fabric.api.recipe.v1.ingredient.DefaultCustomIngredients

public final class DefaultCustomIngredients extends Object
Factory methods for the custom ingredients directly provided by Fabric API.
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.minecraft.world.item.crafting.Ingredient
    all(net.minecraft.world.item.crafting.Ingredient... ingredients)
    Creates an ingredient that matches when its sub-ingredients all match.
    static net.minecraft.world.item.crafting.Ingredient
    any(net.minecraft.world.item.crafting.Ingredient... ingredients)
    Creates an ingredient that matches when any of its sub-ingredients matches.
    static net.minecraft.world.item.crafting.Ingredient
    components(net.minecraft.world.item.crafting.Ingredient base, UnaryOperator<net.minecraft.core.component.DataComponentPatch.Builder> operator)
     
    static net.minecraft.world.item.crafting.Ingredient
    components(net.minecraft.world.item.crafting.Ingredient base, net.minecraft.core.component.DataComponentPatch components)
    Creates an ingredient that wraps another ingredient to also check for matching components.
    static net.minecraft.world.item.crafting.Ingredient
    components(net.minecraft.world.item.ItemStack stack)
    Creates an ingredient that matches the components specified in the passed item stack.
    static net.minecraft.world.item.crafting.Ingredient
    customData(net.minecraft.world.item.crafting.Ingredient base, net.minecraft.nbt.CompoundTag nbt)
    Creates an ingredient that wraps another ingredient to also check for stack's custom data.
    static net.minecraft.world.item.crafting.Ingredient
    difference(net.minecraft.world.item.crafting.Ingredient base, net.minecraft.world.item.crafting.Ingredient subtracted)
    Creates an ingredient that matches if its base ingredient matches, and its subtracted ingredient does not match.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • all

      public static net.minecraft.world.item.crafting.Ingredient all(net.minecraft.world.item.crafting.Ingredient... ingredients)
      Creates an ingredient that matches when its sub-ingredients all match.

      The JSON format is as follows:

      {
          "fabric:type": "fabric:all",
          "ingredients": [
              // sub-ingredient 1,
              // sub-ingredient 2,
              // etc...
          ]
      }
      
      Throws:
      IllegalArgumentException - if the array is empty
    • any

      public static net.minecraft.world.item.crafting.Ingredient any(net.minecraft.world.item.crafting.Ingredient... ingredients)
      Creates an ingredient that matches when any of its sub-ingredients matches.

      The JSON format is as follows:

      {
          "fabric:type": "fabric:any",
          "ingredients": [
              // sub-ingredient 1,
              // sub-ingredient 2,
              // etc...
          ]
      }
      
      Throws:
      IllegalArgumentException - if the array is empty
    • difference

      public static net.minecraft.world.item.crafting.Ingredient difference(net.minecraft.world.item.crafting.Ingredient base, net.minecraft.world.item.crafting.Ingredient subtracted)
      Creates an ingredient that matches if its base ingredient matches, and its subtracted ingredient does not match.

      The JSON format is as follows:

      {
          "fabric:type": "fabric:difference",
          "base": // base ingredient,
          "subtracted": // subtracted ingredient
      }
      
    • components

      public static net.minecraft.world.item.crafting.Ingredient components(net.minecraft.world.item.crafting.Ingredient base, net.minecraft.core.component.DataComponentPatch components)
      Creates an ingredient that wraps another ingredient to also check for matching components.

      Use DataComponentPatch.builder() to add or remove components. Added components are checked to match on the target stack, either as the default or the item stack-specific override. Removed components are checked to not exist in the target stack. The check is "non-strict"; components that are neither added nor removed are ignored.

      The JSON format is as follows:

      {
          "fabric:type": "fabric:components",
          "base": // base ingredient,
          "components": // components to be checked
      }
      
      Throws:
      IllegalArgumentException - if there are no components to check
    • components

      public static net.minecraft.world.item.crafting.Ingredient components(net.minecraft.world.item.crafting.Ingredient base, UnaryOperator<net.minecraft.core.component.DataComponentPatch.Builder> operator)
      See Also:
    • components

      public static net.minecraft.world.item.crafting.Ingredient components(net.minecraft.world.item.ItemStack stack)
      Creates an ingredient that matches the components specified in the passed item stack. Note that the count of the stack is ignored.

      This does not check for the default component of the item stack that remains unchanged. For example, an undamaged pickaxe matches any pickaxes (regardless of damage), because having zero damage is the default, but a pickaxe with 1 damage would only match another pickaxe with 1 damage. To only match the default value, use the other methods and explicitly specify the default value.

      Throws:
      IllegalArgumentException - if stack has no changed components
      See Also:
    • customData

      public static net.minecraft.world.item.crafting.Ingredient customData(net.minecraft.world.item.crafting.Ingredient base, net.minecraft.nbt.CompoundTag nbt)
      Creates an ingredient that wraps another ingredient to also check for stack's custom data. This check is non-strict; the ingredient custom data must be a subset of the stack custom data. This is useful for mods that still rely on NBT-based custom data instead of custom components, such as those requiring vanilla compatibility or interacting with another data packs.

      Passing a null or empty nbt is not allowed, as it would always match. For strict matching, use components(Ingredient, UnaryOperator) like this instead:

      components(base, builder -> builder.add(DataComponents.CUSTOM_DATA, CustomData.of(nbt)));
      // or, to check for absence of custom data:
      components(base, builder -> builder.remove(DataComponents.CUSTOM_DATA));
      

      See NbtUtils.compareNbt(Tag, Tag, boolean) for how matching works.

      The JSON format is as follows:

      {
         "fabric:type": "fabric:custom_data",
         "base": // base ingredient,
         "nbt": // NBT tag to match, either in JSON directly or a string representation
      }
      
      Throws:
      IllegalArgumentException - if nbt is null or empty