Record Class FluidProduct

java.lang.Object
java.lang.Record
forestry.api.core.FluidProduct
Record Components:
stack - The fluid stack this product always produces. Must not be empty.
All Implemented Interfaces:
IFluidProduct

public record FluidProduct(net.neoforged.neoforge.fluids.FluidStack stack) extends Record implements IFluidProduct
Default implementation of IFluidProduct: a fixed fluid output. Used by all of Forestry's own squeezer recipes. Wraps a FluidStack so fluid, amount, and data components are captured together.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.MapCodec<FluidProduct>
     
    static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,FluidProduct>
     
    The default product type.

    Fields inherited from interface forestry.api.core.IFluidProduct

    CODEC, TYPE_KEY
  • Constructor Summary

    Constructors
    Constructor
    Description
    FluidProduct(net.neoforged.neoforge.fluids.FluidStack stack)
    Creates an instance of a FluidProduct record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    net.neoforged.neoforge.fluids.FluidStack
    Creates a new, non-random stack to represent this product in recipe viewers.
    net.neoforged.neoforge.fluids.FluidStack
    createRandomFluidStack(net.minecraft.util.RandomSource random)
    Used to produce a fluid stack from this product, taking randomness into account.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    of(net.minecraft.world.level.material.Fluid fluid, int amount)
     
    of(net.neoforged.neoforge.fluids.FluidStack stack)
     
    net.neoforged.neoforge.fluids.FluidStack
    Returns the value of the stack record component.
    final String
    Returns a string representation of this record class.
    The type of this product, used to (de)serialize it via IFluidProduct.CODEC.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • MAP_CODEC

      public static final com.mojang.serialization.MapCodec<FluidProduct> MAP_CODEC
    • STREAM_CODEC

      public static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,FluidProduct> STREAM_CODEC
    • TYPE

      public static final FluidProductType<FluidProduct> TYPE
      The default product type. The dispatch codec IFluidProduct.CODEC treats this type specially: products of this type serialize without a "type" key, and a missing "type" key on decode resolves back to it.
  • Constructor Details

    • FluidProduct

      public FluidProduct(net.neoforged.neoforge.fluids.FluidStack stack)
      Creates an instance of a FluidProduct record class.
      Parameters:
      stack - the value for the stack record component
  • Method Details

    • createFluidStack

      public net.neoforged.neoforge.fluids.FluidStack createFluidStack()
      Description copied from interface: IFluidProduct
      Creates a new, non-random stack to represent this product in recipe viewers.

      The fluid amount should be the MAXIMUM amount of fluid a stack returned by this product's IFluidProduct.createRandomFluidStack(RandomSource) can have. For example, if your recipe produces 100-300 mB of some fluid, this method should return a stack with 300 mB of fluid. This ensures machines like the Squeezer know how much space must be available to fit this fluid product into the output tank.

      This can return empty, like in the case where the product is a modded fluid not present in the current instance. However, in these cases, your recipe should use the proper conditions to disable itself rather than relying on this behavior.

      Specified by:
      createFluidStack in interface IFluidProduct
      Returns:
      A new stack representing this product. If your product is dynamic, return a "default" stack.
    • createRandomFluidStack

      public net.neoforged.neoforge.fluids.FluidStack createRandomFluidStack(net.minecraft.util.RandomSource random)
      Description copied from interface: IFluidProduct
      Used to produce a fluid stack from this product, taking randomness into account. This is the final result produced by machines.

      Specified by:
      createRandomFluidStack in interface IFluidProduct
      Parameters:
      random - The random source. If no randomness is desired, this defaults to IFluidProduct.createFluidStack().
      Returns:
      A new stack for this cycle, possibly empty or smaller than the representative stack.
    • type

      public FluidProductType<?> type()
      Description copied from interface: IFluidProduct
      The type of this product, used to (de)serialize it via IFluidProduct.CODEC. Plain FluidProduct instances return TYPE, which the dispatch codec treats as the default: it serializes without a "type" key.
      Specified by:
      type in interface IFluidProduct
      Returns:
      The type of this product.
    • of

      public static FluidProduct of(net.neoforged.neoforge.fluids.FluidStack stack)
    • of

      public static FluidProduct of(net.minecraft.world.level.material.Fluid fluid, int amount)
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • stack

      public net.neoforged.neoforge.fluids.FluidStack stack()
      Returns the value of the stack record component.
      Returns:
      the value of the stack record component