public static ItemStack fillFluidContainer(
     FluidTank tank, ItemStack containerIn, ItemStack containerOut) {
   if (tank.getFluidAmount() > 0 && containerIn != null) {
     if (FluidContainerRegistry.isEmptyContainer(containerIn)) {
       ItemStack filledContainer =
           FluidContainerRegistry.fillFluidContainer(tank.getFluid(), containerIn);
       if (filledContainer != null) {
         FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(filledContainer);
         if (fs.amount <= tank.getFluidAmount()
             && (containerOut == null
                 || OreDictionary.itemMatches(containerOut, filledContainer, true))) {
           tank.drain(fs.amount, true);
           return filledContainer;
         }
       }
     } else if (containerIn.getItem() instanceof IFluidContainerItem) {
       IFluidContainerItem iContainer = (IFluidContainerItem) containerIn.getItem();
       int available = tank.getFluidAmount();
       int space =
           iContainer.getCapacity(containerIn)
               - (iContainer.getFluid(containerIn) == null
                   ? 0
                   : iContainer.getFluid(containerIn).amount);
       if (available >= space
           && iContainer.fill(containerIn, tank.getFluid(), false) == space) // Fill in one go
       {
         ItemStack filledContainer = copyStackWithAmount(containerIn, 1);
         int filled = iContainer.fill(filledContainer, tank.getFluid(), true);
         if (containerOut == null
             || (OreDictionary.itemMatches(containerOut, filledContainer, true)
                 && ItemStack.areItemStackTagsEqual(filledContainer, containerOut))) {
           tank.drain(filled, true);
           return filledContainer;
         }
       } else {
         int filled = iContainer.fill(containerIn, tank.getFluid(), true);
         tank.drain(filled, true);
       }
     }
   }
   return null;
 }
  public int getProgress() {
    ItemStack stack = inventory.getStackInSlot(0);
    if (stack == null) return 0;
    Item item = stack.getItem();
    FluidStack fluidstack = null;
    int capacity = 0;
    if (item instanceof IFluidContainerItem) {
      IFluidContainerItem iFluidContainerItem = (IFluidContainerItem) stack.getItem();
      fluidstack = iFluidContainerItem.getFluid(stack);
      capacity = iFluidContainerItem.getCapacity(stack);
    } else if (FluidContainerRegistry.isContainer(stack)) {
      fluidstack = FluidContainerRegistry.getFluidForFilledItem(stack);
      capacity =
          FluidContainerRegistry.getContainerCapacity(fill ? tank.getFluid() : fluidstack, stack);
    }

    if (fluidstack == null || capacity <= 0) {
      if (fill) return 0;
      return 16;
    }
    if (fill) return (int) ((fluidstack.amount * 16D) / capacity);
    return (int) (((capacity - fluidstack.amount) * 16D) / capacity);
  }