Package net.neoforged.neoforge.fluids
Class FluidStack
java.lang.Object
net.neoforged.neoforge.fluids.FluidStack
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 Summary
FieldsModifier and TypeFieldDescriptionprivate intstatic final com.mojang.serialization.Codec<FluidStack>static final FluidStackprivate final Fluidprivate booleanprivate static final org.apache.logging.log4j.Loggerprivate @Nullable CompoundTag -
Constructor Summary
ConstructorsConstructorDescriptionFluidStack(Holder<Fluid> fluid, int amount) FluidStack(Holder<Fluid> fluid, int amount, @Nullable CompoundTag nbt) FluidStack(Fluid fluid, int amount) FluidStack(Fluid fluid, int amount, @Nullable CompoundTag nbt) FluidStack(FluidStack stack, int amount) -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareFluidStackTagsEqual(FluidStack stack1, FluidStack stack2) Determines if the NBT Tags are equal.booleancontainsFluid(FluidStack other) Determines if the Fluids are equal and this stack is larger.copy()copyWithAmount(int amount) final booleanDefault equality comparison for a FluidStack.intgetChildTag(String childName) final FluidgetFluid()final FluidTypegetOrCreateChildTag(String childName) final Fluid@Nullable CompoundTaggetTag()getTags()voidgrow(int amount) final inthashCode()booleanhasTag()final booleanfinal booleanfinal booleanfinal booleanfinal booleanbooleanisEmpty()booleanisFluidEqual(ItemStack other) Determines if the FluidIDs and NBT Tags are equal compared to a registered container ItemStack.booleanisFluidEqual(FluidStack other) Determines if the FluidIDs and NBT Tags are equal.booleanisFluidStackIdentical(FluidStack other) Determines if the FluidIDs, Amounts, and NBT Tags are all equal.private booleanisFluidStackTagEqual(FluidStack other) static FluidStackThis provides a safe method for retrieving a FluidStack - if the Fluid is invalid, the stack will return as null.static FluidStackvoidremoveChildTag(String childName) voidsetAmount(int amount) voidsetTag(CompoundTag tag) voidshrink(int amount) protected voidwriteToNBT(CompoundTag nbt) void
-
Field Details
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER -
EMPTY
-
CODEC
-
isEmpty
private boolean isEmpty -
amount
private int amount -
tag
-
fluid
-
-
Constructor Details
-
FluidStack
-
FluidStack
-
FluidStack
-
FluidStack
-
FluidStack
-
-
Method Details
-
loadFluidStackFromNBT
This provides a safe method for retrieving a FluidStack - if the Fluid is invalid, the stack will return as null. -
writeToNBT
-
writeToPacket
-
readFromPacket
-
getFluid
-
getRawFluid
-
getFluidType
-
getFluidHolder
-
is
-
is
-
is
-
is
-
is
-
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
-
setTag
-
getOrCreateTag
-
getChildTag
-
getOrCreateChildTag
-
removeChildTag
-
getDisplayName
-
getTranslationKey
-
copy
- Returns:
- A copy of this FluidStack
-
copyWithAmount
- Returns:
- A copy of this FluidStack
-
isFluidEqual
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
-
areFluidStackTagsEqual
Determines if the NBT Tags are equal. Useful if the FluidIDs are known to be equal. -
containsFluid
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
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
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() -
equals
Default equality comparison for a FluidStack. Same functionality as isFluidEqual(). This is included for use in data structures.
-