Class ItemAccessFluidHandler
java.lang.Object
net.neoforged.neoforge.transfer.ItemAccessResourceHandler<FluidResource>
net.neoforged.neoforge.transfer.fluid.ItemAccessFluidHandler
- All Implemented Interfaces:
ResourceHandler<FluidResource>
Base implementation of a simple fluid
ResourceHandler backed by an ItemAccess.
Data is stored in a SimpleFluidContent component.
This class allows the backing items to contain any partial level of fluid up to its capacity.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected final DataComponentType<SimpleFluidContent> protected final ItemFields inherited from class net.neoforged.neoforge.transfer.ItemAccessResourceHandler
itemAccess, size -
Constructor Summary
ConstructorsConstructorDescriptionItemAccessFluidHandler(ItemAccess itemAccess, DataComponentType<SimpleFluidContent> component, int capacity) -
Method Summary
Modifier and TypeMethodDescriptionprotected intgetAmountFrom(ItemResource accessResource, int index) Retrieves the amount stored in the current contents of the item access.protected intgetCapacity(int index, FluidResource resource) Return the maximum capacity of this handler for the passed resource.protected FluidResourcegetResourceFrom(ItemResource accessResource, int index) Retrieves the resource stored in the current contents of the item access.booleanisValid(int index, FluidResource resource) Returntrueif the passed non-empty resource can fit in this handler,falseotherwise.protected ItemResourceupdate(ItemResource accessResource, int index, FluidResource newResource, int newAmount) Returns a resource with updated resource and amount.Methods inherited from class net.neoforged.neoforge.transfer.ItemAccessResourceHandler
extract, getAmountAsLong, getCapacityAsLong, getResource, insert, sizeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.neoforged.neoforge.transfer.ResourceHandler
extract, getAmountAsInt, getCapacityAsInt, insert
-
Field Details
-
validItem
-
component
-
capacity
protected int capacity
-
-
Constructor Details
-
ItemAccessFluidHandler
public ItemAccessFluidHandler(ItemAccess itemAccess, DataComponentType<SimpleFluidContent> component, int capacity)
-
-
Method Details
-
getResourceFrom
Description copied from class:ItemAccessResourceHandlerRetrieves the resource stored in the current contents of the item access.- Specified by:
getResourceFromin classItemAccessResourceHandler<FluidResource>
-
getAmountFrom
Description copied from class:ItemAccessResourceHandlerRetrieves the amount stored in the current contents of the item access.- Specified by:
getAmountFromin classItemAccessResourceHandler<FluidResource>- See Also:
-
update
protected ItemResource update(ItemResource accessResource, int index, FluidResource newResource, int newAmount) Description copied from class:ItemAccessResourceHandlerReturns a resource with updated resource and amount.- Specified by:
updatein classItemAccessResourceHandler<FluidResource>- Parameters:
accessResource- current resource, before the updateindex- the index at which the resource and amount should be updatednewResource- the new resource, never empty: empty is indicated by a 0 amountnewAmount- the new amount- Returns:
accessResourceupdated with the new resource and amount, orItemResource.EMPTYif the new resource or amount cannot be stored
-
isValid
Description copied from class:ItemAccessResourceHandlerReturntrueif the passed non-empty resource can fit in this handler,falseotherwise.The result of this function is used in the provided implementations of:
ItemAccessResourceHandler.getCapacityAsLong(int, T), to report a capacity of0for invalid items;ItemAccessResourceHandler.insert(int, T, int, TransactionContext), to reject items that cannot fit in this handler.
- Specified by:
isValidin interfaceResourceHandler<FluidResource>- Overrides:
isValidin classItemAccessResourceHandler<FluidResource>- Parameters:
index- The index to check.resource- The resource to check. Must be non-empty.- Returns:
- whether the given resource is generally allowed to be contained at the given index, irrespective of the current amount or resource currently at that index
- See Also:
-
getCapacity
Description copied from class:ItemAccessResourceHandlerReturn the maximum capacity of this handler for the passed resource. If the passed resource is empty, an estimate should be returned.- Specified by:
getCapacityin classItemAccessResourceHandler<FluidResource>- Returns:
- The maximum capacity of this handler for the passed resource.
- See Also:
-