Class FluidUtil
java.lang.Object
net.neoforged.neoforge.transfer.fluid.FluidUtil
Helper functions to work with
ResourceHandlers of FluidResources.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FluidStackgetFirstStackContained(ItemStack stack) Returns a new fluid stack with the first fluid contents of the given item stack, ignoring the count of the stack.static FluidStackgetStack(ResourceHandler<FluidResource> handler, int index) Returns a new fluid stack with the contents of the handler at the given index.static booleaninteractWithFluidHandler(Player player, InteractionHand hand, @Nullable BlockPos pos, ResourceHandler<FluidResource> handler) Used to handle the common case of a player holding a fluid item and right-clicking on a fluid handler.static booleaninteractWithFluidHandler(Player player, InteractionHand hand, Level level, BlockPos pos, @Nullable Direction side) Used to handle the common case of a player holding a fluid item and right-clicking on a fluid handler block.private static FluidStackmoveWithSound(ResourceHandler<FluidResource> from, ResourceHandler<FluidResource> to, Level level, @Nullable BlockPos pos, @Nullable Player player, boolean pickup) private static voidplaySoundAndGameEvent(FluidStack stack, Level level, @Nullable BlockPos blockPos, @Nullable Player player, boolean pickup) static FluidStacktryPickupFluid(@Nullable ResourceHandler<FluidResource> destination, @Nullable Player player, Level level, BlockPos pos, @Nullable Direction side) Attempts to pick up a fluid in the level and put it into a fluid handler, first from aBucketPickupblock (such as fluid sources and waterlogged blocks), or second from aCapabilities.Fluid.BLOCKcapability instance.static FluidStacktryPlaceFluid(@Nullable ResourceHandler<FluidResource> source, @Nullable Player player, Level level, InteractionHand hand, BlockPos pos) Tries to extract one bucket of a fluid resource from a resource handler and place it into the level as a block.static booleantryPlaceFluid(FluidResource resource, @Nullable Player player, Level level, InteractionHand hand, BlockPos pos) Tries to place one bucket of a fluid resource into the level as a block.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
-
Constructor Details
-
FluidUtil
private FluidUtil()
-
-
Method Details
-
getStack
Returns a new fluid stack with the contents of the handler at the given index. -
getFirstStackContained
Returns a new fluid stack with the first fluid contents of the given item stack, ignoring the count of the stack.The contents from the first non-empty index are returned. As such the returned contents might not be extractable, and the stack might contain additional contents.
-
interactWithFluidHandler
public static boolean interactWithFluidHandler(Player player, InteractionHand hand, Level level, BlockPos pos, @Nullable @Nullable Direction side) Used to handle the common case of a player holding a fluid item and right-clicking on a fluid handler block. First it tries to fill the item from the block, if that action fails then it tries to drain the item into the block. Automatically updates the item in the player's hand and stashes any extra items created.- Parameters:
player- The player doing the interaction between the item and fluid handler block.hand- The player's hand that is holding an item that should interact with the fluid handler block.level- The level that contains the fluid handler block.pos- The position of the fluid handler block in the level.side- The side of the block to interact with. May be null.- Returns:
- true if the interaction succeeded, false otherwise.
-
interactWithFluidHandler
public static boolean interactWithFluidHandler(Player player, InteractionHand hand, @Nullable @Nullable BlockPos pos, ResourceHandler<FluidResource> handler) Used to handle the common case of a player holding a fluid item and right-clicking on a fluid handler. First it tries to fill the item from the handler, if that action fails then it tries to drain the item into the handler. Automatically updates the item in the player's hand and stashes any extra items created.- Parameters:
player- The player doing the interaction between the item and fluid handler.hand- The player's hand that is holding an item that should interact with the fluid handler.pos- The position at which to send game events and play sounds. Ifnull, the player's position will be used.handler- The fluid handler.- Returns:
- true if the interaction succeeded, false otherwise.
-
moveWithSound
private static FluidStack moveWithSound(ResourceHandler<FluidResource> from, ResourceHandler<FluidResource> to, Level level, @Nullable @Nullable BlockPos pos, @Nullable @Nullable Player player, boolean pickup) -
playSoundAndGameEvent
private static void playSoundAndGameEvent(FluidStack stack, Level level, @Nullable @Nullable BlockPos blockPos, @Nullable @Nullable Player player, boolean pickup) -
tryPickupFluid
public static FluidStack tryPickupFluid(@Nullable @Nullable ResourceHandler<FluidResource> destination, @Nullable @Nullable Player player, Level level, BlockPos pos, @Nullable @Nullable Direction side) Attempts to pick up a fluid in the level and put it into a fluid handler, first from aBucketPickupblock (such as fluid sources and waterlogged blocks), or second from aCapabilities.Fluid.BLOCKcapability instance.- Parameters:
destination- The destination for the picked up fluid. May be null.player- The player filling the container. Optional.level- The level the fluid is in.pos- The position of the fluid in the level.side- The side of the fluid that is being drained.- Returns:
- a
FluidStackholding a copy of the fluid stack that was picked up, orFluidStack.EMPTYif nothing was picked up
-
tryPlaceFluid
public static FluidStack tryPlaceFluid(@Nullable @Nullable ResourceHandler<FluidResource> source, @Nullable @Nullable Player player, Level level, InteractionHand hand, BlockPos pos) Tries to extract one bucket of a fluid resource from a resource handler and place it into the level as a block. UnliketryPlaceFluid(FluidResource, Player, Level, InteractionHand, BlockPos), this function will modify the source handler directly and return what was placed.Makes a fluid emptying or vaporization sound when successful. Honors the amount of fluid contained by the used container. Checks if water-like fluids should vaporize like in the nether.
- Parameters:
source- The source for the placed fluid. May be null.player- Player who places the fluid. May be null for blocks like dispensers.level- Level to place the fluid inhand- Hand of the player to place the fluid withpos- The position in the level to place the fluid block- Returns:
- a
FluidStackholding a copy of the fluid stack that was placed, orFluidStack.EMPTYif nothing was placed
-
tryPlaceFluid
public static boolean tryPlaceFluid(FluidResource resource, @Nullable @Nullable Player player, Level level, InteractionHand hand, BlockPos pos) Tries to place one bucket of a fluid resource into the level as a block. Note that e.g. extracting it from a handler on successful placement is the responsibility of the caller. See alsotryPlaceFluid(ResourceHandler, Player, Level, InteractionHand, BlockPos)to modify a source handler directly.Makes a fluid emptying or vaporization sound when successful. Honors the amount of fluid contained by the used container. Checks if water-like fluids should vaporize like in the nether.
Modeled after
BucketItem.emptyContents(LivingEntity, Level, BlockPos, BlockHitResult, ItemStack).- Parameters:
resource- The fluid resource to placeplayer- Player who places the fluid. May be null for blocks like dispensers.level- Level to place the fluid inhand- Hand of the player to place the fluid withpos- The position in the level to place the fluid block- Returns:
- true if the placement was successful, false otherwise
-