Class FluidIngredient

java.lang.Object
net.neoforged.neoforge.fluids.crafting.FluidIngredient
All Implemented Interfaces:
Predicate<FluidStack>
Direct Known Subclasses:
CompoundFluidIngredient, DataComponentFluidIngredient, DifferenceFluidIngredient, EmptyFluidIngredient, IntersectionFluidIngredient, SingleFluidIngredient, TagFluidIngredient

public abstract class FluidIngredient extends Object implements Predicate<FluidStack>
This class serves as the fluid analogue of an item Ingredient, that is, a representation of both a predicate to test FluidStacks against, and a list of matching stacks for e.g. display purposes.

The most common use for fluid ingredients is found in modded recipe inputs, for example crafting mechanics accepting a list of different fluids; since those mechanics even rely on a certain amount of a fluid being present, and fluid ingredients inherently do not hold any information with respect to fluid amount; you may also want to take a look at SizedFluidIngredient!

  • Field Details

    • SINGLE_OR_TAG_CODEC

      private static final com.mojang.serialization.MapCodec<FluidIngredient> SINGLE_OR_TAG_CODEC
      This is a codec that is used to represent basic "single fluid" or "tag" fluid ingredients directly, similar to Ingredient.Value.CODEC, except not using value subclasses and instead directly providing the corresponding FluidIngredient.
    • MAP_CODEC_NONEMPTY

      public static final com.mojang.serialization.MapCodec<FluidIngredient> MAP_CODEC_NONEMPTY
      This is a codec that represents a single FluidIngredient in map form; either dispatched by type or falling back to SINGLE_OR_TAG_CODEC if no type is specified.
      See Also:
    • MAP_CODEC_CODEC

      private static final com.mojang.serialization.Codec<FluidIngredient> MAP_CODEC_CODEC
    • LIST_CODEC

      public static final com.mojang.serialization.Codec<List<FluidIngredient>> LIST_CODEC
    • LIST_CODEC_NON_EMPTY

      public static final com.mojang.serialization.Codec<List<FluidIngredient>> LIST_CODEC_NON_EMPTY
    • CODEC

      public static final com.mojang.serialization.Codec<FluidIngredient> CODEC
      Full codec representing a fluid ingredient in all possible forms.

      Allows for arrays of fluid ingredients to be read as a CompoundFluidIngredient, as well as for the type field to be left out in case of a single fluid or tag ingredient.

      See Also:
    • CODEC_NON_EMPTY

      public static final com.mojang.serialization.Codec<FluidIngredient> CODEC_NON_EMPTY
      Same as CODEC, except not allowing for empty ingredients ([]) to be specified.
      See Also:
    • STREAM_CODEC

      public static final StreamCodec<RegistryFriendlyByteBuf,FluidIngredient> STREAM_CODEC
    • stacks

      @Nullable private @Nullable FluidStack[] stacks
  • Constructor Details

    • FluidIngredient

      public FluidIngredient()
  • Method Details

    • getStacks

      public final FluidStack[] getStacks()
      Returns an array of fluid stacks that this ingredient accepts. The fluid stacks within the returned array must not be modified by the caller! Returns an array of fluid stacks this ingredient accepts.
      See Also:
    • test

      public abstract boolean test(FluidStack fluidStack)
      Checks if a given fluid stack matches this ingredient. The stack must not be modified in any way.
      Specified by:
      test in interface Predicate<FluidStack>
      Parameters:
      fluidStack - the stack to test
      Returns:
      true if the stack matches, false otherwise
    • generateStacks

      protected abstract Stream<FluidStack> generateStacks()
      Generates a stream of all fluid stacks this ingredient matches against.

      For compatibility reasons, implementations should follow the same guidelines as for custom item ingredients, i.e.:

      • 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 Fluids.
      • At least one stack should always be returned, otherwise the ingredient may be considered accidentally empty.
      • The ingredient should try to return at least one stack with each accepted Fluid. This allows mods that inspect the ingredient to figure out which stacks it might accept.
      Returns:
      a stream of all fluid stacks this ingredient accepts.

      Note: No guarantees are made as to the amount of the fluid, as FluidIngredients are generally not meant to match by amount and these stacks are mostly used for display.

      See Also:
    • isSimple

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

      public abstract FluidIngredientType<?> getType()
      Returns The type of this fluid ingredient..

      The type must be registered to NeoForgeRegistries.FLUID_INGREDIENT_TYPES.

      Returns:
      The type of this fluid ingredient.
    • isEmpty

      public final boolean isEmpty()
      Checks if this ingredient is explicitly empty, i.e. equal to EmptyFluidIngredient.INSTANCE.

      Note: This does not return true for "accidentally empty" ingredients, including compound ingredients that are explicitly constructed with no children or intersection / difference ingredients that resolve to an empty set.

      Returns:
      true if this ingredient is empty(), false otherwise
    • hasNoFluids

      public final boolean hasNoFluids()
      Checks if this ingredient matches no fluids, i.e. if its list of matching fluids is empty.

      Note that this method explicitly resolves the ingredient; if this is not desired, you will need to check for emptiness another way!

      Returns:
      true if this ingredient matches no fluids, false otherwise
      See Also:
    • hashCode

      public abstract int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public abstract boolean equals(Object obj)
      Overrides:
      equals in class Object
    • empty

      public static FluidIngredient empty()
    • of

      public static FluidIngredient of()
    • of

      public static FluidIngredient of(FluidStack... fluids)
    • of

      public static FluidIngredient of(Fluid... fluids)
    • of

      private static FluidIngredient of(Stream<Fluid> fluids)
    • single

      public static FluidIngredient single(FluidStack stack)
    • single

      public static FluidIngredient single(Fluid fluid)
    • single

      public static FluidIngredient single(Holder<Fluid> holder)
    • tag

      public static FluidIngredient tag(TagKey<Fluid> tag)
    • singleOrTagCodec

      private static com.mojang.serialization.MapCodec<FluidIngredient> singleOrTagCodec()
    • makeMapCodec

      private static com.mojang.serialization.MapCodec<FluidIngredient> makeMapCodec()
    • codec

      private static com.mojang.serialization.Codec<FluidIngredient> codec(boolean allowEmpty)