Package net.neoforged.neoforge.fluids
Class FluidUtil
java.lang.Object
net.neoforged.neoforge.fluids.FluidUtil
Deprecated, for removal: This API element is subject to removal in a future version.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDeprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddestroyBlockOnFluidPlacement(Level level, BlockPos pos) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated with no equivalent.static ItemStackgetFilledBucket(FluidStack fluidStack) Deprecated, for removal: This API element is subject to removal in a future version.private static IFluidHandlergetFluidBlockHandler(Fluid fluid, Level level, BlockPos pos) Deprecated, for removal: This API element is subject to removal in a future version.Internal method for getting a fluid block handler for placing a fluid.static Optional<FluidStack> getFluidContained(ItemStack container) Deprecated, for removal: This API element is subject to removal in a future version.static Optional<IFluidHandlerItem> getFluidHandler(ItemStack itemStack) Deprecated, for removal: This API element is subject to removal in a future version.Obtain anItemAccess, and find a handler by callingItemAccess.getCapability(net.neoforged.neoforge.capabilities.ItemCapability<T, net.neoforged.neoforge.transfer.access.ItemAccess>)withCapabilities.Fluid.ITEM.static Optional<IFluidHandler> getFluidHandler(Level level, BlockPos blockPos, @Nullable Direction side) Deprecated, for removal: This API element is subject to removal in a future version.Use theCapabilities.Fluid.BLOCKcapability directly.static booleaninteractWithFluidHandler(Player player, InteractionHand hand, Level level, BlockPos pos, @Nullable Direction side) Deprecated, for removal: This API element is subject to removal in a future version.static booleaninteractWithFluidHandler(Player player, InteractionHand hand, IFluidHandler handler) Deprecated, for removal: This API element is subject to removal in a future version.static FluidActionResulttryEmptyContainer(ItemStack container, IFluidHandler fluidDestination, int maxAmount, @Nullable Player player, boolean doDrain) Deprecated, for removal: This API element is subject to removal in a future version.static FluidActionResulttryEmptyContainerAndStow(ItemStack container, IFluidHandler fluidDestination, IItemHandler inventory, int maxAmount, @Nullable Player player, boolean doDrain) Deprecated, for removal: This API element is subject to removal in a future version.static FluidActionResulttryFillContainer(ItemStack container, IFluidHandler fluidSource, int maxAmount, @Nullable Player player, boolean doFill) Deprecated, for removal: This API element is subject to removal in a future version.static FluidActionResulttryFillContainerAndStow(ItemStack container, IFluidHandler fluidSource, IItemHandler inventory, int maxAmount, @Nullable Player player, boolean doFill) Deprecated, for removal: This API element is subject to removal in a future version.static FluidStacktryFluidTransfer(IFluidHandler fluidDestination, IFluidHandler fluidSource, int maxAmount, boolean doTransfer) Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandlerUtil.move(net.neoforged.neoforge.transfer.ResourceHandler<T>, net.neoforged.neoforge.transfer.ResourceHandler<T>, java.util.function.Predicate<T>, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)orResourceHandlerUtil.moveFirst(net.neoforged.neoforge.transfer.ResourceHandler<T>, net.neoforged.neoforge.transfer.ResourceHandler<T>, java.util.function.Predicate<T>, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)instead.static FluidStacktryFluidTransfer(IFluidHandler fluidDestination, IFluidHandler fluidSource, FluidStack resource, boolean doTransfer) Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandlerUtil.move(net.neoforged.neoforge.transfer.ResourceHandler<T>, net.neoforged.neoforge.transfer.ResourceHandler<T>, java.util.function.Predicate<T>, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)orResourceHandlerUtil.moveFirst(net.neoforged.neoforge.transfer.ResourceHandler<T>, net.neoforged.neoforge.transfer.ResourceHandler<T>, java.util.function.Predicate<T>, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)instead.private static FluidStacktryFluidTransfer_Internal(IFluidHandler fluidDestination, IFluidHandler fluidSource, FluidStack drainable, boolean doTransfer) Deprecated, for removal: This API element is subject to removal in a future version.Internal method for filling a destination fluid handler from a source fluid handler using a specific fluid.static FluidActionResulttryPickUpFluid(ItemStack emptyContainer, @Nullable Player playerIn, Level level, BlockPos pos, Direction side) Deprecated, for removal: This API element is subject to removal in a future version.static FluidActionResulttryPlaceFluid(@Nullable Player player, Level level, InteractionHand hand, BlockPos pos, ItemStack container, FluidStack resource) Deprecated, for removal: This API element is subject to removal in a future version.static booleantryPlaceFluid(@Nullable Player player, Level level, InteractionHand hand, BlockPos pos, IFluidHandler fluidSource, FluidStack resource) Deprecated, for removal: This API element is subject to removal in a future version.
-
Constructor Details
-
FluidUtil
private FluidUtil()Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Method Details
-
interactWithFluidHandler
@Deprecated(since="1.21.9", forRemoval=true) public static boolean interactWithFluidHandler(Player player, InteractionHand hand, Level level, BlockPos pos, @Nullable @Nullable Direction side) Deprecated, for removal: This API element is subject to removal in a future version.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 and updated the item held by the player, false otherwise.
-
interactWithFluidHandler
@Deprecated(since="1.21.9", forRemoval=true) public static boolean interactWithFluidHandler(Player player, InteractionHand hand, IFluidHandler handler) Deprecated, for removal: This API element is subject to removal in a future version.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.handler- The fluid handler.- Returns:
- true if the interaction succeeded and updated the item held by the player, false otherwise.
-
tryFillContainer
@Deprecated(since="1.21.9", forRemoval=true) public static FluidActionResult tryFillContainer(ItemStack container, IFluidHandler fluidSource, int maxAmount, @Nullable @Nullable Player player, boolean doFill) Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandlerUtil.move(net.neoforged.neoforge.transfer.ResourceHandler<T>, net.neoforged.neoforge.transfer.ResourceHandler<T>, java.util.function.Predicate<T>, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)with anItemAccess-backed handler as the destination. Note that the item access will take care of "stowing" any extra items.Fill a container from the given fluidSource.- Parameters:
container- The container to be filled. Will not be modified. Separate handling must be done to reduce the stack size, stow containers, etc, on success. SeetryFillContainerAndStow(ItemStack, IFluidHandler, IItemHandler, int, Player, boolean).fluidSource- The fluid handler to be drained.maxAmount- The largest amount of fluid that should be transferred.player- The player to make the filling noise. Pass null for no noise.doFill- true if the container should actually be filled, false if it should be simulated.- Returns:
- a
FluidActionResultholding the filled container if successful.
-
tryEmptyContainer
@Deprecated(since="1.21.9", forRemoval=true) public static FluidActionResult tryEmptyContainer(ItemStack container, IFluidHandler fluidDestination, int maxAmount, @Nullable @Nullable Player player, boolean doDrain) Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandlerUtil.move(net.neoforged.neoforge.transfer.ResourceHandler<T>, net.neoforged.neoforge.transfer.ResourceHandler<T>, java.util.function.Predicate<T>, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)with anItemAccess-backed handler as the source. Note that the item access will take care of "stowing" any extra items.Takes a filled container and tries to empty it into the given tank.- Parameters:
container- The filled container. Will not be modified. Separate handling must be done to reduce the stack size, stow containers, etc, on success. SeetryEmptyContainerAndStow(ItemStack, IFluidHandler, IItemHandler, int, Player, boolean).fluidDestination- The fluid handler to be filled by the container.maxAmount- The largest amount of fluid that should be transferred.player- Player for making the bucket drained sound. Pass null for no noise.doDrain- true if the container should actually be drained, false if it should be simulated.- Returns:
- a
FluidActionResultholding the empty container if the fluid handler was filled. NOTE If the container is consumable, the empty container will be null on success.
-
tryFillContainerAndStow
@Deprecated(since="1.21.9", forRemoval=true) public static FluidActionResult tryFillContainerAndStow(ItemStack container, IFluidHandler fluidSource, IItemHandler inventory, int maxAmount, @Nullable @Nullable Player player, boolean doFill) Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandlerUtil.move(net.neoforged.neoforge.transfer.ResourceHandler<T>, net.neoforged.neoforge.transfer.ResourceHandler<T>, java.util.function.Predicate<T>, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)with anItemAccess-backed handler as the destination. Note that the item access will take care of "stowing" any extra items.Takes an Fluid Container Item and tries to fill it from the given tank. If the player is in creative mode, the container will not be modified on success, and no additional items created. If the input itemstack has a stacksize > 1 it will stow the filled container in the given inventory. If the inventory does not accept it, it will be given to the player or dropped at the players feet. If player is null in this case, the action will be aborted.- Parameters:
container- The Fluid Container ItemStack to fill. Will not be modified directly, if modifications are necessary a modified copy is returned in the result.fluidSource- The fluid source to fill frominventory- An inventory where any additionally created item (filled container if multiple empty are present) are putmaxAmount- Maximum amount of fluid to take from the tank.player- The player that gets the items the inventory can't take. Can be null, only used if the inventory cannot take the filled stack.doFill- true if the container should actually be filled, false if it should be simulated.- Returns:
- a
FluidActionResultholding the result and the resulting container. The resulting container is empty on failure.
-
tryEmptyContainerAndStow
@Deprecated(since="1.21.9", forRemoval=true) public static FluidActionResult tryEmptyContainerAndStow(ItemStack container, IFluidHandler fluidDestination, IItemHandler inventory, int maxAmount, @Nullable @Nullable Player player, boolean doDrain) Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandlerUtil.move(net.neoforged.neoforge.transfer.ResourceHandler<T>, net.neoforged.neoforge.transfer.ResourceHandler<T>, java.util.function.Predicate<T>, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)with anItemAccess-backed handler as the source. Note that the item access will take care of "stowing" any extra items.Takes an Fluid Container Item, tries to empty it into the fluid handler, and stows it in the given inventory. If the player is in creative mode, the container will not be modified on success, and no additional items created. If the input itemstack has a stacksize > 1 it will stow the emptied container in the given inventory. If the inventory does not accept the emptied container, it will be given to the player or dropped at the players feet. If player is null in this case, the action will be aborted.- Parameters:
container- The filled Fluid Container Itemstack to empty. Will not be modified directly, if modifications are necessary a modified copy is returned in the result.fluidDestination- The fluid destination to fill from the fluid container.inventory- An inventory where any additionally created item (filled container if multiple empty are present) are putmaxAmount- Maximum amount of fluid to take from the tank.player- The player that gets the items the inventory can't take. Can be null, only used if the inventory cannot take the filled stack.doDrain- true if the container should actually be drained, false if it should be simulated.- Returns:
- a
FluidActionResultholding the result and the resulting container. The resulting container is empty on failure.
-
tryFluidTransfer
@Deprecated(since="1.21.9", forRemoval=true) public static FluidStack tryFluidTransfer(IFluidHandler fluidDestination, IFluidHandler fluidSource, int maxAmount, boolean doTransfer) Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandlerUtil.move(net.neoforged.neoforge.transfer.ResourceHandler<T>, net.neoforged.neoforge.transfer.ResourceHandler<T>, java.util.function.Predicate<T>, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)orResourceHandlerUtil.moveFirst(net.neoforged.neoforge.transfer.ResourceHandler<T>, net.neoforged.neoforge.transfer.ResourceHandler<T>, java.util.function.Predicate<T>, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)instead.Fill a destination fluid handler from a source fluid handler with a max amount. To specify a fluid to transfer instead of max amount, usetryFluidTransfer(IFluidHandler, IFluidHandler, FluidStack, boolean)To transfer as much as possible, useInteger.MAX_VALUEfor maxAmount.- Parameters:
fluidDestination- The fluid handler to be filled.fluidSource- The fluid handler to be drained.maxAmount- The largest amount of fluid that should be transferred.doTransfer- True if the transfer should actually be done, false if it should be simulated.- Returns:
- the fluidStack that was transferred from the source to the destination. null on failure.
-
tryFluidTransfer
@Deprecated(since="1.21.9", forRemoval=true) public static FluidStack tryFluidTransfer(IFluidHandler fluidDestination, IFluidHandler fluidSource, FluidStack resource, boolean doTransfer) Deprecated, for removal: This API element is subject to removal in a future version.UseResourceHandlerUtil.move(net.neoforged.neoforge.transfer.ResourceHandler<T>, net.neoforged.neoforge.transfer.ResourceHandler<T>, java.util.function.Predicate<T>, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)orResourceHandlerUtil.moveFirst(net.neoforged.neoforge.transfer.ResourceHandler<T>, net.neoforged.neoforge.transfer.ResourceHandler<T>, java.util.function.Predicate<T>, int, net.neoforged.neoforge.transfer.transaction.TransactionContext)instead.Fill a destination fluid handler from a source fluid handler using a specific fluid. To specify a max amount to transfer instead of specific fluid, usetryFluidTransfer(IFluidHandler, IFluidHandler, int, boolean)To transfer as much as possible, useInteger.MAX_VALUEfor resource.amount.- Parameters:
fluidDestination- The fluid handler to be filled.fluidSource- The fluid handler to be drained.resource- The fluid that should be transferred. Amount represents the maximum amount to transfer.doTransfer- True if the transfer should actually be done, false if it should be simulated.- Returns:
- the fluidStack that was transferred from the source to the destination. null on failure.
-
tryFluidTransfer_Internal
private static FluidStack tryFluidTransfer_Internal(IFluidHandler fluidDestination, IFluidHandler fluidSource, FluidStack drainable, boolean doTransfer) Deprecated, for removal: This API element is subject to removal in a future version.Internal method for filling a destination fluid handler from a source fluid handler using a specific fluid. Assumes that "drainable" can be drained from "fluidSource". Modders: Instead of this method, usetryFluidTransfer(IFluidHandler, IFluidHandler, FluidStack, boolean)ortryFluidTransfer(IFluidHandler, IFluidHandler, int, boolean). -
getFluidHandler
@Deprecated(since="1.21.9", forRemoval=true) public static Optional<IFluidHandlerItem> getFluidHandler(ItemStack itemStack) Deprecated, for removal: This API element is subject to removal in a future version.Obtain anItemAccess, and find a handler by callingItemAccess.getCapability(net.neoforged.neoforge.capabilities.ItemCapability<T, net.neoforged.neoforge.transfer.access.ItemAccess>)withCapabilities.Fluid.ITEM. To ease migration, this method currently queries aCapabilities.Fluid.ITEMcapability, and wraps it in a legacyadapter.Helper method to get anIFluidHandlerItemfor an itemStack. The itemStack passed in here WILL be modified, theIFluidHandlerItemacts on it directly. SomeIFluidHandlerItemwill change the item entirely, always useIFluidHandlerItem.getContainer()after using the fluid handler to get the resulting item back. Note that the itemStack MUST have a stackSize of 1 if you want to fill or drain it. You can't fill or drain multiple items at once, if you do then liquid is multiplied or destroyed. Vanilla buckets will be converted to universal buckets if they are enabled. -
getFluidContained
@Deprecated(since="1.21.9", forRemoval=true) public static Optional<FluidStack> getFluidContained(ItemStack container) Deprecated, for removal: This API element is subject to removal in a future version.Helper method to get the fluid contained in an itemStack -
getFluidHandler
@Deprecated(since="1.21.9", forRemoval=true) public static Optional<IFluidHandler> getFluidHandler(Level level, BlockPos blockPos, @Nullable @Nullable Direction side) Deprecated, for removal: This API element is subject to removal in a future version.Use theCapabilities.Fluid.BLOCKcapability directly.Helper method to get an IFluidHandler for at a block position. -
tryPickUpFluid
@Deprecated(since="1.21.9", forRemoval=true) public static FluidActionResult tryPickUpFluid(ItemStack emptyContainer, @Nullable @Nullable Player playerIn, Level level, BlockPos pos, Direction side) Deprecated, for removal: This API element is subject to removal in a future version.Attempts to pick up a fluid in the level and put it in an empty container item.- Parameters:
emptyContainer- The empty container to fill. Will not be modified directly, if modifications are necessary a modified copy is returned in the result.playerIn- 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
FluidActionResultholding the result and the resulting container.
-
tryPlaceFluid
@Deprecated(since="1.21.9", forRemoval=true) public static FluidActionResult tryPlaceFluid(@Nullable @Nullable Player player, Level level, InteractionHand hand, BlockPos pos, ItemStack container, FluidStack resource) Deprecated, for removal: This API element is subject to removal in a future version.ItemStack version oftryPlaceFluid(Player, Level, InteractionHand, BlockPos, IFluidHandler, FluidStack). Use the returnedFluidActionResultto update the container ItemStack.- Parameters:
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 blockcontainer- The fluid container holding the fluidStack to placeresource- The fluidStack to place- Returns:
- the container's ItemStack with the remaining amount of fluid if the placement was successful, null otherwise
-
tryPlaceFluid
@Deprecated(since="1.21.9", forRemoval=true) public static boolean tryPlaceFluid(@Nullable @Nullable Player player, Level level, InteractionHand hand, BlockPos pos, IFluidHandler fluidSource, FluidStack resource) Deprecated, for removal: This API element is subject to removal in a future version.Tries to place a fluid resource into the level as a block and drains the fluidSource. 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 afterBucketItem.emptyContents(Player, Level, BlockPos, BlockHitResult)- Parameters:
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 blockfluidSource- The fluid source holding the fluidStack to placeresource- The fluidStack to place.- Returns:
- true if the placement was successful, false otherwise
-
getFluidBlockHandler
Deprecated, for removal: This API element is subject to removal in a future version.Internal method for getting a fluid block handler for placing a fluid. Modders: Instead of this method, usetryPlaceFluid(Player, Level, InteractionHand, BlockPos, ItemStack, FluidStack)ortryPlaceFluid(Player, Level, InteractionHand, BlockPos, IFluidHandler, FluidStack) -
destroyBlockOnFluidPlacement
@Deprecated(since="1.21.9", forRemoval=true) public static void destroyBlockOnFluidPlacement(Level level, BlockPos pos) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated with no equivalent. Please open an issue on GitHub if you have a use for an equivalent of this method.Destroys a block when a fluid is placed in the same position. Modeled afterBucketItem.emptyContents(Player, Level, BlockPos, BlockHitResult)- Parameters:
level- the level that the fluid will be placed inpos- the location that the fluid will be placed
-
getFilledBucket
@Deprecated(since="1.21.9", forRemoval=true) public static ItemStack getFilledBucket(FluidStack fluidStack) Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
fluidStack- contents used to fill the bucket. FluidStack is used instead of Fluid to preserve fluid NBT, the amount is ignored.- Returns:
- a filled vanilla bucket or filled universal bucket. Returns empty itemStack if none of the enabled buckets can hold the fluid.
-
ResourceHandlerwith aFluidResourceinstead ofIFluidHandler. For available utils, seeResourceHandlerUtilas well as the newFluidUtil.