use of net.minecraftforge.fluids.capability.wrappers.BucketPickupHandlerWrapper in project MinecraftForge by MinecraftForge.
the class FluidUtil method tryPickUpFluid.
/**
* Attempts to pick up a fluid in the world and put it in an empty container item.
*
* @param emptyContainer The empty container to fill.
* Will not be modified directly, if modifications are necessary a modified copy is returned in the result.
* @param playerIn The player filling the container. Optional.
* @param worldIn The world the fluid is in.
* @param pos The position of the fluid in the world.
* @param side The side of the fluid that is being drained.
* @return a {@link FluidActionResult} holding the result and the resulting container.
*/
@Nonnull
public static FluidActionResult tryPickUpFluid(@Nonnull ItemStack emptyContainer, @Nullable Player playerIn, Level worldIn, BlockPos pos, Direction side) {
if (emptyContainer.isEmpty() || worldIn == null || pos == null) {
return FluidActionResult.FAILURE;
}
BlockState state = worldIn.getBlockState(pos);
Block block = state.getBlock();
IFluidHandler targetFluidHandler;
if (block instanceof IFluidBlock) {
targetFluidHandler = new FluidBlockWrapper((IFluidBlock) block, worldIn, pos);
} else if (block instanceof BucketPickup) {
targetFluidHandler = new BucketPickupHandlerWrapper((BucketPickup) block, worldIn, pos);
} else {
Optional<IFluidHandler> fluidHandler = getFluidHandler(worldIn, pos, side).resolve();
if (!fluidHandler.isPresent()) {
return FluidActionResult.FAILURE;
}
targetFluidHandler = fluidHandler.get();
}
return tryFillContainer(emptyContainer, targetFluidHandler, Integer.MAX_VALUE, playerIn, true);
}
Aggregations