private void outputActiveLava() {
    FluidStack fluid = tank[1].getFluid();
    if (fluid != null) {
      if (itemStacks[2] != null && itemStacks[2].stackSize == 1) {
        ItemStack itemStack = itemStacks[2];
        if (FluidContainerRegistry.isEmptyContainer(itemStack)) {
          if (fluid.amount >= FluidContainerRegistry.BUCKET_VOLUME) {
            FluidStack oneBucketOfFluid =
                new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME);
            ItemStack filledBucket =
                FluidContainerRegistry.fillFluidContainer(
                    oneBucketOfFluid, FluidContainerRegistry.EMPTY_BUCKET);
            itemStacks[2] = filledBucket;
            fluid.amount -= FluidContainerRegistry.BUCKET_VOLUME;
          }
        } else if (itemStack.getItem() instanceof IFluidContainerItem && (workingTick % 20) == 10) {
          if (fluid.amount >= FluidContainerRegistry.BUCKET_VOLUME) {

            IFluidContainerItem fluidContainerItem = (IFluidContainerItem) itemStack.getItem();
            FluidStack fluidStack = fluid.copy();

            if (fluidStack.amount > FluidContainerRegistry.BUCKET_VOLUME)
              fluidStack.amount = FluidContainerRegistry.BUCKET_VOLUME;

            int amount = fluidContainerItem.fill(itemStack, fluidStack, true);
            if (amount > 0) {
              fluid.amount -= amount;
            }
            if (fluid.amount == 0) tank[1].setFluid(null);
          }
        }
      }
    }
  }
  public static boolean fillFluidHandlerWithPlayerItem(
      World world, IFluidHandler handler, EntityPlayer player, ItemStack equipped) {
    if (equipped == null) return false;

    FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(equipped);
    if (fluid != null) {
      if (handler.fill(null, fluid, false) == fluid.amount || player.capabilities.isCreativeMode) {
        if (world.isRemote) return true;

        ItemStack filledStack = FluidContainerRegistry.drainFluidContainer(equipped);
        if (!player.capabilities.isCreativeMode) {
          if (equipped.stackSize == 1) {
            player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
            player.inventory.addItemStackToInventory(filledStack);
          } else {
            equipped.stackSize -= 1;
            if (filledStack != null && !player.inventory.addItemStackToInventory(filledStack))
              player.dropItem(filledStack, false, true);
          }
          player.openContainer.detectAndSendChanges();
          if (player instanceof EntityPlayerMP)
            ((EntityPlayerMP) player)
                .updateCraftingInventory(player.openContainer, player.openContainer.getInventory());
        }
        handler.fill(null, fluid, true);
        return true;
      }
    } else if (equipped.getItem() instanceof IFluidContainerItem) {
      IFluidContainerItem container = (IFluidContainerItem) equipped.getItem();
      fluid = container.getFluid(equipped);
      if (handler.fill(null, fluid, false) > 0) {
        if (world.isRemote) return true;

        int fill = handler.fill(null, fluid, true);
        if (equipped.stackSize > 1) {
          ItemStack emptied = ItemStackUtils.copyStackWithAmount(equipped, 1);
          equipped.stackSize -= 1;
          container.drain(emptied, fill, true);
          if (!player.inventory.addItemStackToInventory(emptied))
            player.dropItem(emptied, false, true);
        } else container.drain(equipped, fill, true);
        player.openContainer.detectAndSendChanges();
        if (player instanceof EntityPlayerMP)
          ((EntityPlayerMP) player)
              .updateCraftingInventory(player.openContainer, player.openContainer.getInventory());
        return true;
      }
    }
    return false;
  }
  @Override
  public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {

    Item item = stack.getItem();
    FluidStack fluid = null;
    if (item instanceof IFluidContainerItem) {
      IFluidContainerItem fluidItem = (IFluidContainerItem) item;
      fluid = fluidItem.getFluid(stack);
    } else if (item instanceof IFluidOverlayItem) {
      if (item.getRenderPasses(ItemHelper.getItemDamage(stack)) == 2) {
        fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
      }
    }
    doRenderItem(type, stack, item, fluid);
  }
 public static boolean fillPlayerItemFromFluidHandler(
     World world, IFluidHandler handler, EntityPlayer player, FluidStack tankFluid) {
   ItemStack equipped = player.getCurrentEquippedItem();
   if (equipped == null) return false;
   if (FluidContainerRegistry.isEmptyContainer(equipped)) {
     ItemStack filledStack = FluidContainerRegistry.fillFluidContainer(tankFluid, equipped);
     FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(filledStack);
     if (fluid == null || filledStack == null) return false;
     if (!player.capabilities.isCreativeMode)
       if (equipped.stackSize == 1) {
         player.inventory.setInventorySlotContents(player.inventory.currentItem, filledStack);
         equipped.stackSize -= 1;
         if (equipped.stackSize <= 0) equipped = null;
       } else {
         if (equipped.stackSize == 1) {
           player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
           player.inventory.addItemStackToInventory(filledStack);
         } else {
           equipped.stackSize -= 1;
           if (filledStack != null && !player.inventory.addItemStackToInventory(filledStack))
             player.func_146097_a(filledStack, false, true);
         }
         player.openContainer.detectAndSendChanges();
         ((EntityPlayerMP) player)
             .sendContainerAndContentsToPlayer(
                 player.openContainer, player.openContainer.getInventory());
       }
     handler.drain(ForgeDirection.UNKNOWN, fluid.amount, true);
     return true;
   } else if (equipped.getItem() instanceof IFluidContainerItem) {
     IFluidContainerItem container = (IFluidContainerItem) equipped.getItem();
     if (container.fill(equipped, tankFluid, false) > 0) {
       int fill = container.fill(equipped, tankFluid, true);
       handler.drain(ForgeDirection.UNKNOWN, fill, true);
       player.openContainer.detectAndSendChanges();
       ((EntityPlayerMP) player)
           .sendContainerAndContentsToPlayer(
               player.openContainer, player.openContainer.getInventory());
       return true;
     }
   }
   return false;
 }
  private void inputLava() {

    if (itemStacks[0] != null) {
      Item item = itemStacks[0].getItem();

      if (item != null) {
        if (item == Items.lava_bucket || item == ModItems.itemActiveLavaBucket) {

          if (tank[0].getCapacity() - tank[0].getFluidAmount()
              >= FluidContainerRegistry.BUCKET_VOLUME) {
            FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(itemStacks[0]);

            int result = tank[0].fill(fluidStack, false);

            if (result == FluidContainerRegistry.BUCKET_VOLUME) {
              itemStacks[0] = new ItemStack(Items.bucket, 1);
              tank[0].fill(fluidStack, true);
            }
          }

        } else if (item instanceof IFluidContainerItem && (workingTick % 20) == 5) {
          IFluidContainerItem fluidContainerItem = (IFluidContainerItem) item;
          FluidStack fluidStack = fluidContainerItem.getFluid(itemStacks[0]);

          if (fluidStack != null) {
            fluidStack = fluidStack.copy();

            if (fluidStack.amount > FluidContainerRegistry.BUCKET_VOLUME)
              fluidStack.amount = FluidContainerRegistry.BUCKET_VOLUME;

            int result = tank[0].fill(fluidStack, true);
            if (result > 0) {
              fluidContainerItem.drain(itemStacks[0], result, true);
            }
          }
        }
      }
    }
  }
  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);
  }
 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;
 }
  @Override
  public void updateEntity() {
    super.updateEntity();
    if (worldObj.isRemote) return;
    ItemStack stack = inventory.getStackInSlot(0);
    if (stack != null) {
      Item stackItem = stack.getItem();
      if (stackItem instanceof IFluidContainerItem) {
        IFluidContainerItem iFluidContainerItem = (IFluidContainerItem) stackItem;
        if (fill) {
          if (!tank.isEmpty()) {
            int amount = 128;
            if (tank.getFluidAmount() < amount) amount = tank.getFluidAmount();
            if (energy >= amount) {
              drain(
                  ForgeDirection.UNKNOWN,
                  iFluidContainerItem.fill(stack, new FluidStack(tank.getFluid(), amount), true),
                  true);
              energy -= amount;
            }
          }
        } else {
          FluidStack contained = iFluidContainerItem.getFluid(stack);
          if (!fill && !tank.isFull() && contained != null && contained.amount > 0) {
            int amount = 64;
            if (tank.getFreeSpace() < amount) amount = tank.getFreeSpace();
            if (amount > contained.amount) amount = contained.amount;
            iFluidContainerItem.drain(
                stack, fill(ForgeDirection.UNKNOWN, new FluidStack(contained, amount), true), true);
          }
        }
      } else if (FluidContainerRegistry.isContainer(stack)) {
        if (fill) {
          if (!tank.isEmpty()) {
            int amount = FluidContainerRegistry.getContainerCapacity(tank.getFluid(), stack);
            if (amount > 0 && energy >= amount && tank.getFluidAmount() >= amount) {
              ItemStack filledContainer =
                  FluidContainerRegistry.fillFluidContainer(
                      new FluidStack(tank.getFluid(), amount), stack);
              if (filledContainer != null
                  && filledContainer.getItem() != null
                  && filledContainer.stackSize > 0) {
                energy -= amount;
                drain(ForgeDirection.UNKNOWN, amount, true);
                inventory.setInventorySlotContents(0, filledContainer.copy());
              }
            }
          }
        } else {
          FluidStack contained = FluidContainerRegistry.getFluidForFilledItem(stack);
          if (contained != null
              && contained.amount > 0
              && tank.getFreeSpace() >= contained.amount) {
            if (fill(ForgeDirection.UNKNOWN, contained, false) == contained.amount) {
              fill(ForgeDirection.UNKNOWN, contained, true);
              ItemStack drainedContainer = FluidContainerRegistry.drainFluidContainer(stack);
              if (drainedContainer != null
                  && drainedContainer.getItem() != null
                  && drainedContainer.stackSize > 0)
                inventory.setInventorySlotContents(0, drainedContainer.copy());
            }
          }
        }
      }

      if (getProgress() >= 16) {
        stack = getStackInSlot(0);
        if (stack != null) {
          ItemStack outputStack = getStackInSlot(1);
          if (outputStack == null || outputStack.getItem() == null || outputStack.stackSize <= 0) {
            ItemStack copyStack = stack.copy();
            copyStack.stackSize = 1;
            inventory.setInventorySlotContents(1, copyStack);
            inventory.decrStackSize(0, 1);
          }
        }
      }
    }
  }