Class FluidIngredient
- All Implemented Interfaces:
Predicate<FluidStack>
- Direct Known Subclasses:
CompoundFluidIngredient
,DataComponentFluidIngredient
,DifferenceFluidIngredient
,EmptyFluidIngredient
,IntersectionFluidIngredient
,SingleFluidIngredient
,TagFluidIngredient
Ingredient
,
that is, a representation of both a predicate to test
FluidStack
s 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
Modifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec
<FluidIngredient> Full codec representing a fluid ingredient in all possible forms.static final com.mojang.serialization.Codec
<FluidIngredient> Same asCODEC
, except not allowing for empty ingredients ([]
) to be specified.static final com.mojang.serialization.Codec
<List<FluidIngredient>> static final com.mojang.serialization.Codec
<List<FluidIngredient>> private static final com.mojang.serialization.Codec
<FluidIngredient> static final com.mojang.serialization.MapCodec
<FluidIngredient> This is a codec that represents a singleFluidIngredient
in map form; either dispatched by type or falling back toSINGLE_OR_TAG_CODEC
if no type is specified.private static final com.mojang.serialization.MapCodec
<FluidIngredient> This is a codec that is used to represent basic "single fluid" or "tag" fluid ingredients directly, similar toIngredient.Value.CODEC
, except not using value subclasses and instead directly providing the correspondingFluidIngredient
.private @Nullable FluidStack[]
static final StreamCodec
<RegistryFriendlyByteBuf, FluidIngredient> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static com.mojang.serialization.Codec
<FluidIngredient> codec
(boolean allowEmpty) static FluidIngredient
empty()
abstract boolean
protected abstract Stream
<FluidStack> Generates a stream of all fluid stacks this ingredient matches against.final FluidStack[]
Returns an array of fluid stacks that this ingredient accepts.abstract FluidIngredientType
<?> getType()
Returns The type of this fluid ingredient..abstract int
hashCode()
final boolean
Checks if this ingredient matches no fluids, i.e.final boolean
isEmpty()
Checks if this ingredient is explicitly empty, i.e.abstract boolean
isSimple()
Returns whether this fluid ingredient always requires direct stack testing.private static com.mojang.serialization.MapCodec
<FluidIngredient> static FluidIngredient
of()
private static FluidIngredient
static FluidIngredient
static FluidIngredient
of
(FluidStack... fluids) static FluidIngredient
static FluidIngredient
static FluidIngredient
single
(FluidStack stack) private static com.mojang.serialization.MapCodec
<FluidIngredient> static FluidIngredient
abstract boolean
test
(FluidStack fluidStack) Checks if a given fluid stack matches this ingredient.
-
Field Details
-
SINGLE_OR_TAG_CODEC
This is a codec that is used to represent basic "single fluid" or "tag" fluid ingredients directly, similar toIngredient.Value.CODEC
, except not using value subclasses and instead directly providing the correspondingFluidIngredient
. -
MAP_CODEC_NONEMPTY
This is a codec that represents a singleFluidIngredient
in map form; either dispatched by type or falling back toSINGLE_OR_TAG_CODEC
if no type is specified.- See Also:
-
MAP_CODEC_CODEC
-
LIST_CODEC
-
LIST_CODEC_NON_EMPTY
-
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 thetype
field to be left out in case of a single fluid or tag ingredient.- See Also:
-
CODEC_NON_EMPTY
Same asCODEC
, except not allowing for empty ingredients ([]
) to be specified.- See Also:
-
STREAM_CODEC
-
stacks
-
-
Constructor Details
-
FluidIngredient
public FluidIngredient()
-
-
Method Details
-
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
Checks if a given fluid stack matches this ingredient. The stack must not be modified in any way.- Specified by:
test
in interfacePredicate<FluidStack>
- Parameters:
fluidStack
- the stack to test- Returns:
true
if the stack matches,false
otherwise
-
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
Fluid
s. - 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
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 toEmptyFluidIngredient.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 isempty()
,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() -
equals
-
empty
-
of
-
of
-
of
-
of
-
single
-
single
-
single
-
tag
-
singleOrTagCodec
-
makeMapCodec
-
codec
-