public class FluidUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static FluidStack |
getFluidContained(ItemStack container)
Helper method to get the fluid contained in an itemStack
|
static IFluidHandlerItem |
getFluidHandler(ItemStack itemStack)
Helper method to get an
IFluidHandlerItem for an itemStack. |
static IFluidHandler |
getFluidHandler(World world,
BlockPos blockPos,
EnumFacing side)
Helper method to get an IFluidHandler for at a block position.
|
static FluidActionResult |
interactWithFluidHandler(ItemStack stack,
IFluidHandler fluidHandler,
EntityPlayer player)
Used to handle the common case of a player holding a fluid item and right-clicking on a fluid handler.
|
static FluidActionResult |
tryEmptyContainer(ItemStack container,
IFluidHandler fluidDestination,
int maxAmount,
EntityPlayer player,
boolean doDrain)
Takes a filled container and tries to empty it into the given tank.
|
static FluidActionResult |
tryEmptyContainerAndStow(ItemStack container,
IFluidHandler fluidDestination,
IItemHandler inventory,
int maxAmount,
EntityPlayer player)
Takes an Fluid Container Item, tries to empty it into the fluid handler, and stows it in the given inventory.
|
static FluidActionResult |
tryFillContainer(ItemStack container,
IFluidHandler fluidSource,
int maxAmount,
EntityPlayer player,
boolean doFill)
Fill a container from the given fluidSource.
|
static FluidActionResult |
tryFillContainerAndStow(ItemStack container,
IFluidHandler fluidSource,
IItemHandler inventory,
int maxAmount,
EntityPlayer player)
Takes an Fluid Container Item and tries to fill it from the given tank.
|
static FluidStack |
tryFluidTransfer(IFluidHandler fluidDestination,
IFluidHandler fluidSource,
int maxAmount,
boolean doTransfer)
Fill a destination fluid handler from a source fluid handler.
|
static FluidActionResult |
tryPickUpFluid(ItemStack emptyContainer,
EntityPlayer playerIn,
World worldIn,
BlockPos pos,
EnumFacing side)
Attempts to pick up a fluid in the world and put it in an empty container item.
|
static FluidActionResult |
tryPlaceFluid(EntityPlayer player,
World world,
BlockPos pos,
ItemStack container,
FluidStack resource)
Tries to place a fluid in the world in block form and drains the container.
|
@Nonnull public static FluidActionResult interactWithFluidHandler(@Nonnull ItemStack stack, IFluidHandler fluidHandler, EntityPlayer player)
stack
- The filled or empty fluid container.
Will not be modified directly, if modifications are necessary a modified copy is returned in the result.fluidHandler
- The fluid handler to interact with.player
- The player doing the interaction between the item and fluid handler.FluidActionResult
holding the result and resulting container.@Nonnull public static FluidActionResult tryFillContainer(@Nonnull ItemStack container, IFluidHandler fluidSource, int maxAmount, @Nullable EntityPlayer player, boolean doFill)
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.
See tryFillContainerAndStow(ItemStack, IFluidHandler, IItemHandler, int, EntityPlayer)
.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.FluidActionResult
holding the filled container if successful.@Nonnull public static FluidActionResult tryEmptyContainer(@Nonnull ItemStack container, IFluidHandler fluidDestination, int maxAmount, @Nullable EntityPlayer player, boolean doDrain)
container
- The filled container. Will not be modified.
Separate handling must be done to reduce the stack size, stow containers, etc, on success.
See tryEmptyContainerAndStow(ItemStack, IFluidHandler, IItemHandler, int, EntityPlayer)
.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.FluidActionResult
holding the empty container if the fluid handler was filled.
NOTE If the container is consumable, the empty container will be null on success.@Nonnull public static FluidActionResult tryFillContainerAndStow(@Nonnull ItemStack container, IFluidHandler fluidSource, IItemHandler inventory, int maxAmount, @Nullable EntityPlayer player)
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.FluidActionResult
holding the result and the resulting container. The resulting container is empty on failure.@Nonnull public static FluidActionResult tryEmptyContainerAndStow(@Nonnull ItemStack container, IFluidHandler fluidDestination, IItemHandler inventory, int maxAmount, @Nullable EntityPlayer player)
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.FluidActionResult
holding the result and the resulting container. The resulting container is empty on failure.@Nullable public static FluidStack tryFluidTransfer(IFluidHandler fluidDestination, IFluidHandler fluidSource, int maxAmount, boolean doTransfer)
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.@Nullable public static IFluidHandlerItem getFluidHandler(@Nonnull ItemStack itemStack)
IFluidHandlerItem
for an itemStack.
The itemStack passed in here WILL be modified, the IFluidHandlerItem
acts on it directly.
Some IFluidHandlerItem
will change the item entirely, always use IFluidHandlerItem.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.
Returns null if the itemStack passed in does not have a fluid handler.@Nullable public static FluidStack getFluidContained(@Nonnull ItemStack container)
@Nullable public static IFluidHandler getFluidHandler(World world, BlockPos blockPos, @Nullable EnumFacing side)
@Nonnull public static FluidActionResult tryPickUpFluid(@Nonnull ItemStack emptyContainer, @Nullable EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side)
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.worldIn
- The world the fluid is in.pos
- The position of the fluid in the world.side
- The side of the fluid that is being drained.FluidActionResult
holding the result and the resulting container.@Nonnull public static FluidActionResult tryPlaceFluid(@Nullable EntityPlayer player, World world, BlockPos pos, @Nonnull ItemStack container, FluidStack resource)
ItemBucket.tryPlaceContainedLiquid(EntityPlayer, World, BlockPos)
player
- Player who places the fluid. May be null for blocks like dispensers.world
- World to place the fluid inpos
- The position in the world to place the fluid blockcontainer
- The fluid container holding the fluidStack to placeresource
- The fluidStack to place