Interface CustomIngredient


public interface CustomIngredient
Interface that modders can implement to create new behaviors for Ingredients.

This is not directly implemented on vanilla Ingredients, but conversions are possible:

  • toVanilla() converts a custom ingredient to a vanilla Ingredient.
  • FabricIngredient can be used to check if a vanilla Ingredient is custom, and retrieve the custom ingredient in that case.

The format for custom ingredients is as follows:

{
    "fabric:type": "<identifier of the serializer>",
    // extra ingredient data, dependent on the serializer
}

Implementors of this interface are strongly encouraged to also implement Object.equals(Object) and Object.hashCode().

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default net.minecraft.world.item.crafting.display.SlotDisplay
    Returns a SlotDisplay representing this ingredient, this is synced to the client to display in the recipe book.
    Returns the serializer for this ingredient.
    Stream<net.minecraft.core.Holder<net.minecraft.world.item.Item>>
    Returns the list of stacks that match this ingredient..
    boolean
    Returns whether this ingredient always requires direct stack testing.
    boolean
    test(net.minecraft.world.item.ItemStack stack)
    Checks if a stack matches this ingredient.
    default net.minecraft.world.item.crafting.Ingredient
    Returns a new Ingredient behaving as defined by this custom ingredient.
  • Method Details

    • test

      boolean test(net.minecraft.world.item.ItemStack stack)
      Checks if a stack matches this ingredient. The stack must not be modified in any way.
      Parameters:
      stack - the stack to test
      Returns:
      true if the stack matches this ingredient, false otherwise
    • items

      Stream<net.minecraft.core.Holder<net.minecraft.world.item.Item>> items()
      Returns the list of stacks that match this ingredient..

      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 don't require testing, for which it is important that the returned stacks correspond exactly to all the accepted Items.
      • 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.

      Returns:
      the list of stacks that match this ingredient.
    • requiresTesting

      boolean requiresTesting()
      Returns whether this ingredient always requires direct stack testing.
      Returns:
      false if this ingredient ignores NBT data when matching stacks, true otherwise
      See Also:
    • getSerializer

      CustomIngredientSerializer<?> getSerializer()
      Returns the serializer for this ingredient.

      The serializer must have been registered using CustomIngredientSerializer.register(CustomIngredientSerializer).

      Returns:
      the serializer for this ingredient
    • display

      default net.minecraft.world.item.crafting.display.SlotDisplay display()
      Returns a SlotDisplay representing this ingredient, this is synced to the client to display in the recipe book.
      Returns:
      a SlotDisplay instance.
    • toVanilla

      @NonExtendable default net.minecraft.world.item.crafting.Ingredient toVanilla()
      Returns a new Ingredient behaving as defined by this custom ingredient..
      Returns:
      a new Ingredient behaving as defined by this custom ingredient