Package net.neoforged.neoforge.fluids
Class FluidStack
java.lang.Object
net.neoforged.neoforge.fluids.FluidStack
- All Implemented Interfaces:
- DataComponentHolder,- IDataComponentHolderExtension,- MutableDataComponentHolder
ItemStack equivalent for fluids.
 The main difference is that a fluid stack is always required to have an amount, while an item stack defaults to 1.
 Another difference is that the component prototype of a fluid stack is currently always empty, while an item stack gets its component prototype from the item.
 Most methods in this class are adapted from ItemStack.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate intstatic final com.mojang.serialization.Codec<FluidStack> A standard codec for fluid stacks that does not accept empty stacks.private final PatchedDataComponentMapstatic final FluidStackprivate final Fluidprivate static final org.slf4j.Loggerstatic final com.mojang.serialization.Codec<FluidStack> A standard codec for fluid stacks that accepts empty stacks, serializing them as{}.static final StreamCodec<RegistryFriendlyByteBuf, FluidStack> A stream codec for fluid stacks that accepts empty stacks.static final StreamCodec<RegistryFriendlyByteBuf, FluidStack> A stream codec for fluid stacks that does not accept empty stacks.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprivateFluidStack(@Nullable Void unused) FluidStack(Holder<Fluid> fluid, int amount) FluidStack(Holder<Fluid> fluid, int amount, DataComponentPatch patch) FluidStack(Fluid fluid, int amount) privateFluidStack(Fluid fluid, int amount, PatchedDataComponentMap components) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidapplyComponents(DataComponentMap components) Applies a set of component changes to this stack.voidApplies a set of component changes to this stack.static booleanareFluidStackTagsEqual(FluidStack first, FluidStack second) Deprecated, for removal: This API element is subject to removal in a future version.booleancontainsFluid(FluidStack other) Deprecated, for removal: This API element is subject to removal in a future version.copy()Creates a copy of this fluid stack.Creates a copy of this stack with0amount.copyWithAmount(int amount) Creates a copy of this fluid stack with the given amount.static com.mojang.serialization.Codec<FluidStack> fixedAmountCodec(int amount) A standard codec for fluid stacks that always deserializes with a fixed amount, and does not accept empty stacks.intReturns the amount of this stack.Returns thedescription idof this stack.Deprecated, for removal: This API element is subject to removal in a future version.getFluid()Returns the fluid in this stack, orFluids.EMPTYif this stack is empty.Returns the fluid type of this stack.Returns the hover name of this stack.getTags()Deprecated, for removal: This API element is subject to removal in a future version.PrefergetHoverName().voidgrow(int addedAmount) Adds the given amount to this stack.static inthashFluidAndComponents(@Nullable FluidStack stack) Hashes the fluid and components of this stack, ignoring the amount.booleanbooleanbooleanbooleanbooleanbooleanCheck if the fluid type of this stack is equal to the given fluid type.booleanbooleanisEmpty()Checks if this fluid stack is empty.booleanisFluidEqual(ItemStack other) Deprecated, for removal: This API element is subject to removal in a future version.booleanisFluidEqual(FluidStack other) Deprecated, for removal: This API element is subject to removal in a future version.booleanisFluidStackIdentical(FluidStack other) Deprecated, for removal: This API element is subject to removal in a future version.static booleanisSameFluid(FluidStack first, FluidStack second) Checks if the two fluid stacks have the same fluid.static booleanisSameFluidSameComponents(FluidStack first, FluidStack second) Checks if the two fluid stacks have the same fluid and components.static com.mojang.serialization.MapCodec<FluidStack> lenientOtionalFieldOf(String fieldName) voidlimitSize(int amount) Limits the amount of this stack is at most the given amount.static booleanmatches(FluidStack first, FluidStack second) Checks if the two fluid stacks are equal.static Optional<FluidStack> parse(HolderLookup.Provider lookupProvider, Tag tag) Tries to parse a fluid stack.static FluidStackparseOptional(HolderLookup.Provider lookupProvider, CompoundTag tag) Tries to parse a fluid stack, defaulting toEMPTYon parsing failure.<T> Tremove(DataComponentType<? extends T> type) Removes a data component.save(HolderLookup.Provider lookupProvider) Saves this stack to a new tag.save(HolderLookup.Provider lookupProvider, Tag prefix) Saves this stack to a tag, directly writing the keys into the passed tag.saveOptional(HolderLookup.Provider lookupProvider) Saves this stack to a new tag.<T> Tset(DataComponentType<? super T> type, T component) Sets a data component.voidsetAmount(int amount) Sets the amount of this stack.voidshrink(int removedAmount) Removes the given amount from this stack.split(int amount) Splits off a stack of the given amount of this stack and reduces this stack by the amount.toString()Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.minecraft.core.component.DataComponentHolderget, getOrDefault, hasMethods inherited from interface net.neoforged.neoforge.common.extensions.IDataComponentHolderExtensionaddToTooltip, addToTooltip, get, getOrDefault, has
- 
Field Details- 
FLUID_NON_EMPTY_CODEC
- 
CODECA standard codec for fluid stacks that does not accept empty stacks.
- 
OPTIONAL_CODECA standard codec for fluid stacks that accepts empty stacks, serializing them as{}.
- 
OPTIONAL_STREAM_CODECA stream codec for fluid stacks that accepts empty stacks.
- 
STREAM_CODECA stream codec for fluid stacks that does not accept empty stacks.
- 
LOGGERprivate static final org.slf4j.Logger LOGGER
- 
EMPTY
- 
amountprivate int amount
- 
fluid
- 
components
 
- 
- 
Constructor Details- 
FluidStack
- 
FluidStack
- 
FluidStack
- 
FluidStack
- 
FluidStack
 
- 
- 
Method Details- 
fixedAmountCodecA standard codec for fluid stacks that always deserializes with a fixed amount, and does not accept empty stacks.Fluid equivalent of ItemStack.SINGLE_ITEM_CODEC.
- 
getComponents- Specified by:
- getComponentsin interface- DataComponentHolder
 
- 
getComponentsPatch
- 
isComponentsPatchEmptypublic boolean isComponentsPatchEmpty()
- 
parseTries to parse a fluid stack. Empty stacks cannot be parsed with this method.
- 
parseOptionalTries to parse a fluid stack, defaulting toEMPTYon parsing failure.
- 
isEmptypublic boolean isEmpty()Checks if this fluid stack is empty.
- 
splitSplits off a stack of the given amount of this stack and reduces this stack by the amount.
- 
copyAndClearCreates a copy of this stack with0amount.
- 
getFluidReturns the fluid in this stack, orFluids.EMPTYif this stack is empty.
- 
getFluidHolder
- 
is
- 
is
- 
is
- 
is
- 
is
- 
getTags
- 
saveSaves this stack to a tag, directly writing the keys into the passed tag.- Throws:
- IllegalStateException- if this stack is empty
 
- 
saveSaves this stack to a new tag.- Throws:
- IllegalStateException- if this stack is empty
 
- 
saveOptionalSaves this stack to a new tag. Empty stacks are supported and will be saved as an empty tag.
- 
copyCreates a copy of this fluid stack.
- 
copyWithAmountCreates a copy of this fluid stack with the given amount.
- 
matchesChecks if the two fluid stacks are equal. This checks the fluid, amount, and components.- Returns:
- trueif the two fluid stacks have equal fluid, amount, and components
 
- 
isSameFluidChecks if the two fluid stacks have the same fluid. Ignores amount and components.- Returns:
- trueif the two fluid stacks have the same fluid
 
- 
isSameFluidSameComponentsChecks if the two fluid stacks have the same fluid and components. Ignores amount.- Returns:
- trueif the two fluid stacks have the same fluid and components
 
- 
lenientOtionalFieldOf
- 
hashFluidAndComponentsHashes the fluid and components of this stack, ignoring the amount.
- 
getDescriptionIdReturns thedescription idof this stack.
- 
toString
- 
setSets a data component.- Specified by:
- setin interface- MutableDataComponentHolder
 
- 
removeRemoves a data component.- Specified by:
- removein interface- MutableDataComponentHolder
 
- 
applyComponentsApplies a set of component changes to this stack.- Specified by:
- applyComponentsin interface- MutableDataComponentHolder
 
- 
applyComponentsApplies a set of component changes to this stack.- Specified by:
- applyComponentsin interface- MutableDataComponentHolder
 
- 
getHoverNameReturns the hover name of this stack.
- 
getAmountpublic int getAmount()Returns the amount of this stack.
- 
setAmountpublic void setAmount(int amount) Sets the amount of this stack.
- 
limitSizepublic void limitSize(int amount) Limits the amount of this stack is at most the given amount.
- 
growpublic void grow(int addedAmount) Adds the given amount to this stack.
- 
shrinkpublic void shrink(int removedAmount) Removes the given amount from this stack.
- 
getFluidTypeReturns the fluid type of this stack.
- 
isCheck if the fluid type of this stack is equal to the given fluid type.
- 
getDisplayNameDeprecated, for removal: This API element is subject to removal in a future version.UsegetHoverName()instead.
- 
getTranslationKeyDeprecated, for removal: This API element is subject to removal in a future version.PrefergetHoverName().
- 
isFluidEqualDeprecated, for removal: This API element is subject to removal in a future version.Determines if the fluid and the components are equal. This does not check amounts.
- 
areFluidStackTagsEqual@Deprecated(forRemoval=true, since="1.20.5") public static boolean areFluidStackTagsEqual(FluidStack first, FluidStack second) Deprecated, for removal: This API element is subject to removal in a future version.Determines if components are equal.
- 
containsFluidDeprecated, for removal: This API element is subject to removal in a future version.Determines if Fluids are equal and this stack is larger.- Returns:
- true if this FluidStack contains the other FluidStack (same fluid, same components and >= amount)
 
- 
isFluidStackIdenticalDeprecated, for removal: This API element is subject to removal in a future version.Determines if Fluids, Amounts, and components are all equal.
- 
isFluidEqualDeprecated, for removal: This API element is subject to removal in a future version.Determines if the FluidIDs and components are equal compared to a container item stack. This does not check amounts.
 
- 
getHoverName()instead.