Package net.minecraftforge.fluids
Class FluidStack
- java.lang.Object
-
- net.minecraftforge.fluids.FluidStack
-
public class FluidStack extends java.lang.Object
ItemStack substitute for Fluids. NOTE: Equality is based on the Fluid, not the amount. UseisFluidStackIdentical(FluidStack)
to determine if FluidID, Amount and NBT Tag are all equal.
-
-
Field Summary
Fields Modifier and Type Field Description private int
amount
static com.mojang.serialization.Codec<FluidStack>
CODEC
static FluidStack
EMPTY
private IRegistryDelegate<Fluid>
fluidDelegate
private boolean
isEmpty
private static org.apache.logging.log4j.Logger
LOGGER
private CompoundNBT
tag
-
Constructor Summary
Constructors Constructor Description FluidStack(Fluid fluid, int amount)
FluidStack(Fluid fluid, int amount, CompoundNBT nbt)
FluidStack(FluidStack stack, int amount)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
areFluidStackTagsEqual(FluidStack stack1, FluidStack stack2)
Determines if the NBT Tags are equal.boolean
containsFluid(FluidStack other)
Determines if the Fluids are equal and this stack is larger.FluidStack
copy()
boolean
equals(java.lang.Object o)
Default equality comparison for a FluidStack.int
getAmount()
CompoundNBT
getChildTag(java.lang.String childName)
ITextComponent
getDisplayName()
Fluid
getFluid()
CompoundNBT
getOrCreateChildTag(java.lang.String childName)
CompoundNBT
getOrCreateTag()
Fluid
getRawFluid()
CompoundNBT
getTag()
java.lang.String
getTranslationKey()
void
grow(int amount)
int
hashCode()
boolean
hasTag()
boolean
isEmpty()
boolean
isFluidEqual(ItemStack other)
Determines if the FluidIDs and NBT Tags are equal compared to a registered container ItemStack.boolean
isFluidEqual(FluidStack other)
Determines if the FluidIDs and NBT Tags are equal.boolean
isFluidStackIdentical(FluidStack other)
Determines if the FluidIDs, Amounts, and NBT Tags are all equal.private boolean
isFluidStackTagEqual(FluidStack other)
static FluidStack
loadFluidStackFromNBT(CompoundNBT nbt)
This provides a safe method for retrieving a FluidStack - if the Fluid is invalid, the stack will return as null.static FluidStack
readFromPacket(PacketBuffer buf)
void
removeChildTag(java.lang.String childName)
void
setAmount(int amount)
void
setTag(CompoundNBT tag)
void
shrink(int amount)
protected void
updateEmpty()
CompoundNBT
writeToNBT(CompoundNBT nbt)
void
writeToPacket(PacketBuffer buf)
-
-
-
Field Detail
-
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
private CompoundNBT tag
-
fluidDelegate
private IRegistryDelegate<Fluid> fluidDelegate
-
-
Constructor Detail
-
FluidStack
public FluidStack(Fluid fluid, int amount)
-
FluidStack
public FluidStack(Fluid fluid, int amount, CompoundNBT nbt)
-
FluidStack
public FluidStack(FluidStack stack, int amount)
-
-
Method Detail
-
loadFluidStackFromNBT
public static FluidStack loadFluidStackFromNBT(CompoundNBT nbt)
This provides a safe method for retrieving a FluidStack - if the Fluid is invalid, the stack will return as null.
-
writeToNBT
public CompoundNBT writeToNBT(CompoundNBT nbt)
-
writeToPacket
public void writeToPacket(PacketBuffer buf)
-
readFromPacket
public static FluidStack readFromPacket(PacketBuffer buf)
-
getFluid
public final Fluid getFluid()
-
getRawFluid
public final Fluid getRawFluid()
-
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
public CompoundNBT getTag()
-
setTag
public void setTag(CompoundNBT tag)
-
getOrCreateTag
public CompoundNBT getOrCreateTag()
-
getChildTag
public CompoundNBT getChildTag(java.lang.String childName)
-
getOrCreateChildTag
public CompoundNBT getOrCreateChildTag(java.lang.String childName)
-
removeChildTag
public void removeChildTag(java.lang.String childName)
-
getDisplayName
public ITextComponent getDisplayName()
-
getTranslationKey
public java.lang.String getTranslationKey()
-
copy
public FluidStack copy()
- Returns:
- A copy of this FluidStack
-
isFluidEqual
public boolean isFluidEqual(@Nonnull 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(@Nonnull FluidStack stack1, @Nonnull FluidStack stack2)
Determines if the NBT Tags are equal. Useful if the FluidIDs are known to be equal.
-
containsFluid
public boolean containsFluid(@Nonnull FluidStack other)
Determines if the Fluids are equal and this stack is larger.- Parameters:
other
-- 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(@Nonnull 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 classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object o)
Default equality comparison for a FluidStack. Same functionality as isFluidEqual(). This is included for use in data structures.- Overrides:
equals
in classjava.lang.Object
-
-