Class FluidResource
java.lang.Object
net.neoforged.neoforge.transfer.fluid.FluidResource
- All Implemented Interfaces:
DataComponentGetter,DataComponentHolder,IDataComponentHolderExtension,DataComponentHolderResource<Fluid>,RegisteredResource<Fluid>,Resource
Immutable combination of a
Fluid and data components.
Similar to a FluidStack, but immutable and without amount information.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec<FluidResource> Codec for a fluid resource.static final FluidResourceThe empty resource instance of aFluidResourceprivate final FluidStackA wrappedFluidStackwhich must never be modified or exposed.static final com.mojang.serialization.Codec<FluidResource> Codec for a fluid resource.static final StreamCodec<RegistryFriendlyByteBuf, FluidResource> Stream codec for a fluid resource. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanPatches currently applied to the resource's data component holder.getFluid()Returns The registered holder of the backing resource.inthashCode()booleanbooleanChecks if the resource's data component holder has no patches applied to it.booleanisEmpty()Checks if this resource is empty.booleanmatches(FluidStack stack) Returns true if this resource matches the fluid and components of the passed stack.static FluidResourceNote: This cannot be called before your fluid is registeredstatic FluidResourceof(Holder<Fluid> holder, DataComponentPatch patch) Note: This cannot be called before your fluid is registeredstatic FluidResourceNote: This cannot be called before your fluid is registeredstatic FluidResourceof(Fluid fluid, DataComponentPatch patch) Note: This cannot be called before your fluid is registeredstatic FluidResourceof(FluidStack stack) Creates aFluidResourcefor the given fluid stack.booleantest(Predicate<FluidStack> predicate) Tests aFluidStackpredicate with the inner stack.toStack(int amount) Creates aFluidStackof the specified amount.toString()value()Returns the backing instance of the resource.<D> FluidResourcewith(Supplier<? extends DataComponentType<D>> type, D data) Returns a resource with the data component set to the given value.<D> FluidResourcewith(DataComponentType<D> type, D data) Returns a resource with the data component set to the given value.Returns an instance of the resource with the desired patch applied on top of the existing one.without(Supplier<? extends DataComponentType<?>> type) Returns a resource without the data component, i.e. with the data component explicitly removed.without(DataComponentType<?> type) Returns a resource without the data component, i.e. with the data component explicitly removed.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.minecraft.core.component.DataComponentGetter
get, getOrDefault, getTyped, hasMethods inherited from interface net.minecraft.core.component.DataComponentHolder
get, getAllOfType, getOrDefault, hasMethods inherited from interface net.neoforged.neoforge.common.extensions.IDataComponentHolderExtension
addToTooltip, addToTooltip
-
Field Details
-
EMPTY
The empty resource instance of aFluidResource -
CODEC
Codec for a fluid resource. Same format asFluidStack.fixedAmountCodec(int). Does not accept empty resources. -
OPTIONAL_CODEC
Codec for a fluid resource. Same format asCODEC, and also accepts empty resources. -
STREAM_CODEC
Stream codec for a fluid resource. Accepts empty resources. -
innerStack
A wrappedFluidStackwhich must never be modified or exposed. This will be a size of 1 so that we can make use of the fact it is already an instance with a data component map.
-
-
Constructor Details
-
FluidResource
-
-
Method Details
-
of
Creates aFluidResourcefor the given fluid stack. Note the amount is lost.- Parameters:
stack- stack to copy with a size of 1- Returns:
- If there were no patches on the stack's data components, the fluid's default resource will be returned, otherwise a new instance with the copied stack.
-
of
Note: This cannot be called before your fluid is registered- Throws:
IllegalStateException- If the backing registry is unavailable or not yet ready.NullPointerException- If the underlying Holder has not been populated (the target object is not registered).
-
of
Note: This cannot be called before your fluid is registered- Parameters:
fluid- Fluid to create the resource with.patch- Data components that should be on the resource instance.- Returns:
- a new
FluidResource. If the fluid is empty, thenEMPTYwill be returned; If the patch matches the default values the default instance of that fluid will be provided. - Throws:
IllegalStateException- If the backing registry is unavailable or not yet ready.NullPointerException- If the underlying Holder has not been populated (the target object is not registered).
-
of
Note: This cannot be called before your fluid is registered- Throws:
IllegalStateException- If the backing registry is unavailable or not yet ready.NullPointerException- If the underlying Holder has not been populated (the target object is not registered).
-
of
Note: This cannot be called before your fluid is registered- Parameters:
holder- Fluid holder to create the resource with.patch- Data components that should be on the resource instance.- Returns:
- a new
FluidResource. If the fluid is empty, thenEMPTYwill be returned; If the patch matches the default values the default instance of that fluid will be provided. - Throws:
IllegalStateException- If the backing registry is unavailable or not yet ready.NullPointerException- If the underlying Holder has not been populated (the target object is not registered).
-
value
Description copied from interface:RegisteredResourceReturns the backing instance of the resource.- Specified by:
valuein interfaceRegisteredResource<Fluid>- Returns:
- the backing instance of the resource
-
getFluid
- Returns:
- The
Fluidof this resource from the innerFluidStack
-
getHolder
Description copied from interface:RegisteredResourceReturns The registered holder of the backing resource.- Specified by:
getHolderin interfaceRegisteredResource<Fluid>- Returns:
- the fluid holder of this resource
-
getFluidType
- Returns:
- the fluid type of this resource
-
isEmpty
public boolean isEmpty()Checks if this resource is empty. The resource will be empty if the fluid isFluids.EMPTY. -
withMergedPatch
Description copied from interface:DataComponentHolderResourceReturns an instance of the resource with the desired patch applied on top of the existing one.- Specified by:
withMergedPatchin interfaceDataComponentHolderResource<Fluid>- Parameters:
patch- The patch added to the new resource instance.- Returns:
- an instance of the resource with the desired patch applied on top of the existing one
-
with
Description copied from interface:DataComponentHolderResourceReturns a resource with the data component set to the given value.- Specified by:
within interfaceDataComponentHolderResource<Fluid>- Type Parameters:
D- the type of data component- Parameters:
type- the type of data componentdata- the data to set- Returns:
- a resource with the data component set to the given value
-
with
Description copied from interface:DataComponentHolderResourceReturns a resource with the data component set to the given value.- Specified by:
within interfaceDataComponentHolderResource<Fluid>- Type Parameters:
D- the type of data component- Parameters:
type- the supplier for the type of data componentdata- the data to set- Returns:
- a resource with the data component set to the given value
-
without
Description copied from interface:DataComponentHolderResourceReturns a resource without the data component, i.e. with the data component explicitly removed.- Specified by:
withoutin interfaceDataComponentHolderResource<Fluid>- Parameters:
type- the type of data component- Returns:
- a resource without the data component, i.e. with the data component explicitly removed
-
without
Description copied from interface:DataComponentHolderResourceReturns a resource without the data component, i.e. with the data component explicitly removed.- Specified by:
withoutin interfaceDataComponentHolderResource<Fluid>- Parameters:
type- the supplier for the type of data component- Returns:
- a resource without the data component, i.e. with the data component explicitly removed
-
getComponents
- Specified by:
getComponentsin interfaceDataComponentHolder
-
getComponentsPatch
Description copied from interface:DataComponentHolderResourcePatches currently applied to the resource's data component holder.- Specified by:
getComponentsPatchin interfaceDataComponentHolderResource<Fluid>
-
toStack
Creates aFluidStackof the specified amount.- Parameters:
amount- The amount of the fluid the stack should have. Must be non-negative.- Throws:
IllegalArgumentException- when amount is negative.
-
isComponentsPatchEmpty
public boolean isComponentsPatchEmpty()Description copied from interface:DataComponentHolderResourceChecks if the resource's data component holder has no patches applied to it. Equivalent to checking if thepatchis empty, but more efficient.- Specified by:
isComponentsPatchEmptyin interfaceDataComponentHolderResource<Fluid>
-
is
- Parameters:
fluidType- Fluid type to check- Returns:
trueif the inner stack's fluid type is the same as the specified fluid type.
-
matches
Returns true if this resource matches the fluid and components of the passed stack.- Parameters:
stack- the fluid stack to check- Returns:
- true if this resource matches the fluid and components of the passed stack
-
test
Tests aFluidStackpredicate with the inner stack.- Parameters:
predicate- Predicate to perform the test with- Returns:
trueif the test passed
-
getHoverName
- Returns:
- The hover name of the
FluidStack
-
equals
-
hashCode
public int hashCode() -
toString
-