Class SizedFluidIngredient

java.lang.Object
net.neoforged.neoforge.fluids.crafting.SizedFluidIngredient

public final class SizedFluidIngredient extends Object
Standard implementation for a FluidIngredient with an amount.

FluidIngredient, like its item counterpart, explicitly does not perform count checks, so this class is used to (a) wrap a standard FluidIngredient with an amount and (b) provide a standard serialization format for mods to use.

See Also:
  • Field Details

    • FLAT_CODEC

      public static final com.mojang.serialization.Codec<SizedFluidIngredient> FLAT_CODEC
      The "flat" codec for SizedFluidIngredient.

      The amount is serialized inline with the rest of the ingredient, for example:

      
       {
           "fluid": "minecraft:water",
           "amount": 250
       }
       

      Compound fluid ingredients are always serialized using the map codec, i.e.

      
       {
           "type": "neoforge:compound",
           "ingredients": [
               { "fluid": "minecraft:water" },
               { "fluid": "minecraft:milk" }
           ],
           "amount": 500
       }
       

    • NESTED_CODEC

      public static final com.mojang.serialization.Codec<SizedFluidIngredient> NESTED_CODEC
      The "nested" codec for SizedFluidIngredient.

      With this codec, the amount is always serialized separately from the ingredient itself, for example:

      
       {
           "ingredient": {
               "fluid": "minecraft:lava"
           },
           "amount": 1000
       }
       
    • STREAM_CODEC

      public static final StreamCodec<RegistryFriendlyByteBuf,SizedFluidIngredient> STREAM_CODEC
    • ingredient

      private final FluidIngredient ingredient
    • amount

      private final int amount
    • cachedStacks

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

    • SizedFluidIngredient

      public SizedFluidIngredient(FluidIngredient ingredient, int amount)
  • Method Details

    • of

      public static SizedFluidIngredient of(Fluid fluid, int amount)
    • of

      public static SizedFluidIngredient of(FluidStack stack)
      Helper method to create a simple sized ingredient that matches the given fluid stack
    • of

      public static SizedFluidIngredient of(TagKey<Fluid> tag, int amount)
      Helper method to create a simple sized ingredient that matches fluids in a tag.
    • ingredient

      public FluidIngredient ingredient()
    • amount

      public int amount()
    • test

      public boolean test(FluidStack stack)
      Performs a size-sensitive test on the given stack.
      Returns:
      true if the stack matches the ingredient and has at least the required amount.
    • getFluids

      public FluidStack[] getFluids()
      Returns a list of the stacks from this ingredient, with an updated amount.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object