Class FluidIngredient

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

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 Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.Codec<FluidIngredient>
     
    private @Nullable List<net.minecraft.core.Holder<net.minecraft.world.level.material.Fluid>>
     
    static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,Optional<FluidIngredient>>
     
    static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,FluidIngredient>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    net.minecraft.world.item.crafting.display.SlotDisplay
    Returns a slot display for this ingredient, used for display on the client-side.
    static net.minecraft.world.item.crafting.display.SlotDisplay
    displayForSingleFluid(net.minecraft.core.Holder<net.minecraft.world.level.material.Fluid> holder)
     
    abstract boolean
     
    final List<net.minecraft.core.Holder<net.minecraft.world.level.material.Fluid>>
    Returns a cached list of all Fluid holders that this ingredient accepts.
    protected abstract Stream<net.minecraft.core.Holder<net.minecraft.world.level.material.Fluid>>
    Returns a stream of fluids accepted by this ingredient.
    Returns The type of this fluid ingredient..
    abstract int
     
    abstract boolean
    Returns whether this fluid ingredient always requires direct stack testing.
    of(Stream<net.minecraft.world.level.material.Fluid> fluids)
     
    of(net.minecraft.core.HolderSet<net.minecraft.world.level.material.Fluid> fluids)
     
    of(net.minecraft.world.level.material.Fluid... fluids)
     
    of(FluidStack... fluids)
     
    abstract boolean
    test(FluidStack fluidStack)
    Checks if a given fluid stack matches this ingredient.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.function.Predicate

    and, negate, or
  • Field Details

    • CODEC

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

      public static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,FluidIngredient> STREAM_CODEC
    • OPTIONAL_STREAM_CODEC

      public static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,Optional<FluidIngredient>> OPTIONAL_STREAM_CODEC
    • fluids

      @Nullable private @Nullable List<net.minecraft.core.Holder<net.minecraft.world.level.material.Fluid>> fluids
  • Constructor Details

    • FluidIngredient

      public FluidIngredient()
  • Method Details

    • fluids

      public final List<net.minecraft.core.Holder<net.minecraft.world.level.material.Fluid>> fluids()
      Returns a cached list of all Fluid holders that this ingredient accepts. This list is immutable and thus can and should not be modified by the caller!
      Returns:
      a cached list of all Fluid holders that 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
    • generateFluids

      @OverrideOnly protected abstract Stream<net.minecraft.core.Holder<net.minecraft.world.level.material.Fluid>> generateFluids()
      Returns a stream of fluids accepted by this ingredient.

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

      • Returned fluids are generally used for display purposes, and need not be exhaustive or perfectly accurate, as ingredients may additionally filter by e.g. data component values.
      • An exception is ingredients that are simple, for which it is important that this stream corresponds exactly all fluids accepted by test(FluidStack)!
      • At least one stack should always be returned, so that the ingredient is not considered empty. Empty ingredients may invalidate recipes!

      Note: no caching needs to be done by the implementation, this is already handled by fluids!

      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:
    • display

      public net.minecraft.world.item.crafting.display.SlotDisplay display()
      Returns a slot display for this ingredient, used for display on the client-side.
      Returns:
      a slot display for this ingredient, used for display on the client-side
      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.
    • hashCode

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

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

      public static net.minecraft.world.item.crafting.display.SlotDisplay displayForSingleFluid(net.minecraft.core.Holder<net.minecraft.world.level.material.Fluid> holder)
    • of

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

      public static FluidIngredient of(net.minecraft.world.level.material.Fluid... fluids)
    • of

      public static FluidIngredient of(Stream<net.minecraft.world.level.material.Fluid> fluids)
    • of

      public static FluidIngredient of(net.minecraft.core.HolderSet<net.minecraft.world.level.material.Fluid> fluids)