Class FluidStack

java.lang.Object
net.neoforged.neoforge.fluids.FluidStack

public class FluidStack extends Object
ItemStack substitute for Fluids. NOTE: Equality is based on the Fluid, not the amount. Use isFluidStackIdentical(FluidStack) to determine if FluidID, Amount and NBT Tag are all equal.
  • Field Details

    • LOGGER

      private static final org.apache.logging.log4j.Logger LOGGER
    • EMPTY

      public static final FluidStack EMPTY
    • CODEC

      public static final com.mojang.serialization.Codec<FluidStack> CODEC
    • isEmpty

      private boolean isEmpty
    • amount

      private int amount
    • tag

      @Nullable private @Nullable CompoundTag tag
    • fluid

      private final Fluid fluid
  • Constructor Details

    • FluidStack

      public FluidStack(Fluid fluid, int amount)
    • FluidStack

      public FluidStack(Holder<Fluid> fluid, int amount)
    • FluidStack

      public FluidStack(Fluid fluid, int amount, @Nullable @Nullable CompoundTag nbt)
    • FluidStack

      public FluidStack(Holder<Fluid> fluid, int amount, @Nullable @Nullable CompoundTag nbt)
    • FluidStack

      public FluidStack(FluidStack stack, int amount)
  • Method Details

    • loadFluidStackFromNBT

      public static FluidStack loadFluidStackFromNBT(CompoundTag nbt)
      This provides a safe method for retrieving a FluidStack - if the Fluid is invalid, the stack will return as null.
    • writeToNBT

      public CompoundTag writeToNBT(CompoundTag nbt)
    • writeToPacket

      public void writeToPacket(FriendlyByteBuf buf)
    • readFromPacket

      public static FluidStack readFromPacket(FriendlyByteBuf buf)
    • getFluid

      public final Fluid getFluid()
    • getRawFluid

      public final Fluid getRawFluid()
    • getFluidType

      public final FluidType getFluidType()
    • getFluidHolder

      public final Holder<Fluid> getFluidHolder()
    • is

      public final boolean is(TagKey<Fluid> tag)
    • is

      public final boolean is(Fluid fluid)
    • is

      public final boolean is(FluidType fluidType)
    • is

      public final boolean is(Holder<Fluid> holder)
    • is

      public final boolean is(HolderSet<Fluid> holderSet)
    • getTags

      public final Stream<TagKey<Fluid>> getTags()
    • isEmpty

      public boolean isEmpty()
    • updateEmpty

      protected void updateEmpty()
    • getAmount

      public int getAmount()
    • setAmount

      public void setAmount(int amount)
    • grow

      public void grow(int amount)
    • shrink

      public void shrink(int amount)
    • hasTag

      public boolean hasTag()
    • getTag

      @Nullable public @Nullable CompoundTag getTag()
    • setTag

      public void setTag(CompoundTag tag)
    • getOrCreateTag

      public CompoundTag getOrCreateTag()
    • getChildTag

      public CompoundTag getChildTag(String childName)
    • getOrCreateChildTag

      public CompoundTag getOrCreateChildTag(String childName)
    • removeChildTag

      public void removeChildTag(String childName)
    • getDisplayName

      public Component getDisplayName()
    • getTranslationKey

      public String getTranslationKey()
    • copy

      public FluidStack copy()
      Returns:
      A copy of this FluidStack
    • copyWithAmount

      public FluidStack copyWithAmount(int amount)
      Returns:
      A copy of this FluidStack
    • isFluidEqual

      public boolean isFluidEqual(FluidStack other)
      Determines if the FluidIDs and NBT Tags are equal. This does not check amounts.
      Parameters:
      other - The FluidStack for comparison
      Returns:
      true if the Fluids (IDs and NBT Tags) are the same
    • isFluidStackTagEqual

      private boolean isFluidStackTagEqual(FluidStack other)
    • areFluidStackTagsEqual

      public static boolean areFluidStackTagsEqual(FluidStack stack1, FluidStack stack2)
      Determines if the NBT Tags are equal. Useful if the FluidIDs are known to be equal.
    • containsFluid

      public boolean containsFluid(FluidStack other)
      Determines if the Fluids are equal and this stack is larger.
      Returns:
      true if this FluidStack contains the other FluidStack (same fluid and >= amount)
    • isFluidStackIdentical

      public boolean isFluidStackIdentical(FluidStack other)
      Determines if the FluidIDs, Amounts, and NBT Tags are all equal.
      Parameters:
      other - - the FluidStack for comparison
      Returns:
      true if the two FluidStacks are exactly the same
    • isFluidEqual

      public boolean isFluidEqual(ItemStack other)
      Determines if the FluidIDs and NBT Tags are equal compared to a registered container ItemStack. This does not check amounts.
      Parameters:
      other - The ItemStack for comparison
      Returns:
      true if the Fluids (IDs and NBT Tags) are the same
    • hashCode

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

      public final boolean equals(Object o)
      Default equality comparison for a FluidStack. Same functionality as isFluidEqual(). This is included for use in data structures.
      Overrides:
      equals in class Object