示例#1
0
  public void pushFluidOut() {
    int tanks = 0;
    boolean[] sides = new boolean[ForgeDirection.VALID_DIRECTIONS.length];
    for (int i = 0; i < sides.length; i++) {
      ForgeDirection side = ForgeDirection.VALID_DIRECTIONS[i];
      TileEntity tile =
          worldObj.getTileEntity(
              xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
      if (tile != null && tile instanceof IFluidHandler) {
        tanks++;
        sides[i] = true;
      }
    }

    int amountPerSide = lava.getFluidAmount();
    for (int i = 0; i < sides.length; i++) {
      if (sides[i]) {
        ForgeDirection side = ForgeDirection.getOrientation(i);
        TileEntity tile =
            worldObj.getTileEntity(
                xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
        if (tile != null
            && tile instanceof IFluidHandler
            && !(tile instanceof Heater)
            && !(tile instanceof Melter)) {
          IFluidHandler fluid = (IFluidHandler) tile;
          if (fluid.fill(side.getOpposite(), lava.drain(amountPerSide, false), false)
              == amountPerSide) {
            amountPerSide -= fluid.fill(side.getOpposite(), lava.drain(amountPerSide, true), true);
          }
        }
      }
    }
  }
  public ItemStack getFilledItem(ItemStack empty, boolean drainTank) {
    if (empty == null || tank.getFluid() == null) return null;
    BottlingMachineRecipe recipe = BottlingMachineRecipe.findRecipe(empty, tank.getFluid());
    if (recipe != null && recipe.output != null) {
      if (drainTank) tank.drain(recipe.fluidInput.amount, true);
      return recipe.output;
    }

    ItemStack filled =
        FluidContainerRegistry.fillFluidContainer(
            new FluidStack(tank.getFluid(), Integer.MAX_VALUE), empty);
    FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(filled);
    if (filled != null && fs.amount <= tank.getFluidAmount()) {
      if (drainTank) tank.drain(fs.amount, true);
      return filled;
    }

    if (empty.getItem() instanceof IFluidContainerItem) {
      int accepted = ((IFluidContainerItem) empty.getItem()).fill(empty, tank.getFluid(), false);
      if (accepted > 0) {
        filled = empty.copy();
        ((IFluidContainerItem) filled.getItem())
            .fill(filled, new FluidStack(tank.getFluid(), accepted), true);
        if (drainTank) tank.drain(accepted, true);
        return filled;
      }
    }
    return null;
  }
示例#3
0
 public static ItemStack fillFluidContainer(FluidTank tank, ItemStack emptyFluidContainer) {
   if (tank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME) {
     FluidStack fluidStack = tank.drain(FluidContainerRegistry.BUCKET_VOLUME, false);
     ItemStack filledFluidContainer =
         FluidContainerRegistry.fillFluidContainer(fluidStack, emptyFluidContainer);
     if (filledFluidContainer != null) {
       tank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
     }
     return filledFluidContainer;
   } else {
     return null;
   }
 }
示例#4
0
  @Override
  public FluidStack drain(ForgeDirection from, int maxEmpty, boolean doDrain) {
    markDirty();
    FluidStack output = tank.drain(maxEmpty, doDrain);

    return output;
  }
 @Override
 public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
   if (resource != null)
     for (FluidTank _tank : (FluidTank[]) getTanks())
       if (resource.isFluidEqual(_tank.getFluid())) return _tank.drain(resource.amount, doDrain);
   return null;
 }
  @Override
  public void workFunction(ForgeDirection from) {
    if (!from.equals(ForgeDirection.UP)) return;

    if (!getRedstonePowered()) {
      isRunning = false;
      getHandler().updateBlock();
      return;
    }
    // This function gets called every tick.
    boolean needsUpdate = false;
    if (!worldObj.isRemote) {
      needsUpdate = true;
      if (Float.compare(getGenerating(ForgeDirection.UP), 0.0F) > 0) {
        getHandler()
            .setPressure(getPressure(getFacing()) + getGenerating(ForgeDirection.UP), getFacing());
        tank.drain(Constants.MAX_LAVA_USAGE[getTier()], true);
        isRunning = true;
      } else {
        isRunning = false;
      }
    }

    if (needsUpdate) {
      worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
    }
  }
  @Override
  public void updateEntity() {
    super.updateEntity();

    boolean powered = getWorldObj().getStrongestIndirectPower(xCoord, yCoord, zCoord) > 0;
    if (!powered
        && _steamTank.getFluid() != null
        && _steamTank.getFluid().getFluid() != null
        && _steamTank.getFluid().getFluid().getName() != null) {
      String fluidName = _steamTank.getFluid().getFluid().getName();
      PowerSteam.SteamType steamType = powerSteam.getSteamType(fluidName);
      if (steamType != null && _steamTank.getFluidAmount() > 0) {
        lastSubtype = powerSteam.getSteamSubtype(steamType);
        int amount = Math.min(_steamTank.getFluidAmount(), powerSteam.getThrottleConsumer());
        float energy = amount * steamType.energyPerInput;
        energy = (int) storeEnergy(energy, false);
        int toDrain;
        try {
          toDrain =
              (int) (amount - (energy / powerSteam.getInternalEnergyPerInput(this.blockMetadata)));
        } catch (ArithmeticException e) {
          toDrain = 0;
        }
        _steamTank.drain(toDrain, true);
        _mBLastTick = toDrain;
      } else {
        _mBLastTick = 0;
      }
    } else {
      _mBLastTick = 0;
    }
  }
  private void doPlenish() {
    if (usedNodes.size() >= MAX_NODES) {
      finishedCalc = true;
      return;
    }

    if (activeNodes.isEmpty()) {
      if (usedNodes.isEmpty()) {
        Coord4D below = Coord4D.get(this).getFromSide(ForgeDirection.DOWN);

        if (!canReplace(below, true, true)) {
          finishedCalc = true;
          return;
        }

        activeNodes.add(below);
      } else {
        finishedCalc = true;
        return;
      }
    }

    Set<Coord4D> toRemove = new HashSet<Coord4D>();

    for (Coord4D coord : activeNodes) {
      if (coord.exists(worldObj)) {
        if (canReplace(coord, true, false)) {
          worldObj.setBlock(
              coord.xCoord,
              coord.yCoord,
              coord.zCoord,
              MekanismUtils.getFlowingBlock(fluidTank.getFluid().getFluid()),
              0,
              3);

          setEnergy(getEnergy() - usage.fluidicPlenisherUsage);
          fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
        }

        for (ForgeDirection dir : dirs) {
          Coord4D sideCoord = coord.getFromSide(dir);

          if (sideCoord.exists(worldObj) && canReplace(sideCoord, true, true)) {
            activeNodes.add(sideCoord);
          }
        }

        toRemove.add(coord);
        break;
      } else {
        toRemove.add(coord);
      }
    }

    for (Coord4D coord : toRemove) {
      activeNodes.remove(coord);
      usedNodes.add(coord);
    }
  }
 @Override
 public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
   FluidStack drained = tank.drain(maxDrain, doDrain);
   if (tank.getFluidAmount() == 0 && doDrain) {
     tank.setFluid(null);
   }
   return drained;
 }
  @Override
  public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
    if (from == ForgeDirection.getOrientation(1)) {
      return fluidTank.drain(maxDrain, doDrain);
    }

    return null;
  }
示例#11
0
  @Override
  public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain) {
    if (resource != null && canDrain(from, resource.getFluid())) {
      return fluidTank.drain(resource.amount, doDrain);
    }

    return null;
  }
示例#12
0
  @Override
  public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain) {
    if (canDrain(from, null)) {
      return fluidTank.drain(maxDrain, doDrain);
    }

    return null;
  }
示例#13
0
 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;
 }
示例#14
0
 public boolean use(
     ItemStack[] inventory, int index, FluidTank fluidTank, GasTank gasTank, boolean deplete) {
   if (meets(new PressurizedInput(inventory[index], fluidTank.getFluid(), gasTank.getGas()))) {
     if (deplete) {
       inventory[index] = StackUtils.subtract(inventory[index], theSolid);
       fluidTank.drain(theFluid.amount, true);
       gasTank.draw(theGas.amount, true);
     }
     return true;
   }
   return false;
 }
 @Override
 public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
   if (!formed) return null;
   if (master() != null) {
     if (pos != 2) return null;
     return master().drain(from, maxDrain, doDrain);
   } else {
     FluidStack drain = tank2.drain(maxDrain, doDrain);
     markDirty();
     worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
     return drain;
   }
 }
 @Override
 public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
   if (!canDrain(from, null)) return null;
   if (master() != null) return master().drain(from, maxDrain, doDrain);
   updateComparatorValuesPart1();
   FluidStack fs = tank.drain(maxDrain, doDrain);
   if (fs != null && fs.amount > 0 && doDrain) {
     markDirty();
     worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
     // Block updates for comparators
     updateComparatorValuesPart2();
   }
   return fs;
 }
示例#17
0
  @Override
  public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain) {
    FluidStack amount = tank.drain(maxDrain, doDrain);
    if (amount != null && doDrain) {
      renderOffset = -maxDrain;
      // if we're empty after the drain we reset the recipe
      if (!worldObj.isRemote && worldObj instanceof WorldServer) {
        TinkerNetwork.sendToClients(
            (WorldServer) worldObj, pos, new FluidUpdatePacket(pos, tank.getFluid()));
      }
      reset();
    }

    return amount;
  }
  public static ItemStack fillFluidContainer(FluidTank tank, ItemStack containerIn) {
    if (tank.getFluidAmount() > 0)
      if (FluidContainerRegistry.isEmptyContainer(containerIn)) {
        ItemStack filledContainer =
            FluidContainerRegistry.fillFluidContainer(tank.getFluid(), containerIn);
        if (filledContainer != null) {
          FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(filledContainer);
          if (fs.amount <= tank.getFluidAmount()) {
            tank.drain(fs.amount, true);

            return filledContainer;
          }
        }
      }
    return null;
  }
示例#19
0
  private void activeEmit() {
    if (fluidTank.getFluid() != null) {
      TileEntity tileEntity = Coord4D.get(this).offset(EnumFacing.DOWN).getTileEntity(worldObj);

      if (tileEntity != null
          && CapabilityUtils.hasCapability(
              tileEntity, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.UP)) {
        IFluidHandler handler =
            CapabilityUtils.getCapability(
                tileEntity, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.UP);
        FluidStack toDrain =
            new FluidStack(fluidTank.getFluid(), Math.min(tier.output, fluidTank.getFluidAmount()));
        fluidTank.drain(handler.fill(toDrain, true), true);
      }
    }
  }
  @Override
  public void updateEntity() {
    super.updateEntity();

    if (_steamTank.getFluidAmount() > 0) {
      int amount = Math.min(_steamTank.getFluidAmount(), PowerConverterCore.throttleSteamConsumer);
      float energy = amount * PowerConverterCore.powerSystemSteam.getInternalEnergyPerInput();
      energy = (int) storeEnergy(energy, false);
      int toDrain =
          (int)
              (amount - (energy / PowerConverterCore.powerSystemSteam.getInternalEnergyPerInput()));
      _steamTank.drain(toDrain, true);
      _mBLastTick = toDrain;
    } else {
      _mBLastTick = 0;
    }
  }
	public int drain(FluidTank _tank, int maxDrain, boolean doDrain)
	{
		if (_tank.getFluidAmount() > 0)
		{
			FluidStack drained = _tank.drain(maxDrain, doDrain);
			if (drained != null)
			{
				if (doDrain)
				{
					internalChange = true;
					onInventoryChanged();
					internalChange = false;
				}
				return drained.amount;
			}
		}
		return 0;
	}
示例#22
0
  @Override
  public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) {
    if (maxDrain <= 0) return null;

    FluidTank tank = readTank(container);
    if (tank == null) return null;

    final int count = container.stackSize;
    if (count == 0) return null;

    final int amountPerTank = maxDrain / count;
    if (amountPerTank == 0) return null;

    FluidStack drained = tank.drain(amountPerTank, doDrain);
    if (doDrain) saveTank(container, tank);

    if (drained != null) drained.amount *= count;

    return drained;
  }
  @Override
  public float getGenerating(ForgeDirection from) {
    if (!getRedstonePowered()
        || getFluidInNetwork(from) == 0
        || tank == null
        || tank.getFluid() == null) {
      lavaUsage = 0;
      return 0f;
    }

    if (tank.getFluidAmount() > Constants.MAX_LAVA_USAGE[getTier()] * 2) {
      FluidStack drained = tank.drain(Constants.MAX_LAVA_USAGE[getTier()], false);
      if (drained == null) return 0F;
      lavaUsage = drained.amount;

      float gen =
          lavaUsage
              * HCConfig.INSTANCE.getInt("conversionRatioLavaHydraulic")
              * (getHandler().isOilStored() ? 1.0F : Constants.WATER_CONVERSION_RATIO);
      gen = gen * ((float) getFluidInNetwork(from) / (float) getFluidCapacity(from));

      if (Float.compare(gen + getPressure(from), getMaxPressure(getHandler().isOilStored(), from))
          > 0) {
        // This means the pressure we are generating is too much!
        gen = getMaxPressure(getHandler().isOilStored(), from) - getPressure(from);
      }
      if (Float.compare(gen, getMaxGenerating(from)) > 0) {
        gen = getMaxGenerating(from);
      }

      lavaUsage =
          (int)
              (gen
                  * ((float) getFluidInNetwork(from) / (float) getFluidCapacity(from))
                  / HCConfig.INSTANCE.getInt("conversionRatioLavaHydraulic")
                  * (getHandler().isOilStored() ? 1.0F : Constants.WATER_CONVERSION_RATIO));
      return gen;
    } else {
      return 0;
    }
  }
  @Override
  public void updateEntity() {
    if (!formed || pos != 17) return;

    if (!worldObj.isRemote) {
      boolean update = false;
      int prevAmount = tank2.getFluidAmount();
      boolean enabled;
      if (computerControlled) enabled = computerOn;
      else
        enabled =
            !worldObj.isBlockIndirectlyGettingPowered(
                xCoord + (facing == 4 ? -1 : facing == 5 ? 1 : facing == 2 ? -2 : 2),
                yCoord + 1,
                zCoord + (facing == 2 ? -1 : facing == 3 ? 1 : facing == 4 ? 2 : -2));
      if (enabled) {
        RefineryRecipe recipe = getRecipe(true);
        if (recipe != null) {
          int consumed = Config.getInt("refinery_consumption");
          if (energyStorage.extractEnergy(consumed, true) == consumed
              && tank2.fill(recipe.output.copy(), false) == recipe.output.amount) {
            int drain0 =
                tank0.getFluid().isFluidEqual(recipe.input0)
                    ? recipe.input0.amount
                    : recipe.input1.amount;
            int drain1 =
                tank0.getFluid().isFluidEqual(recipe.input0)
                    ? recipe.input1.amount
                    : recipe.input0.amount;
            if (tank0.getFluidAmount() >= drain0 && tank1.getFluidAmount() >= drain1) {
              energyStorage.extractEnergy(consumed, false);
              tank0.drain(drain0, true);
              tank1.drain(drain1, true);
              tank2.fill(recipe.output.copy(), true);
              update = true;
            }
          }
        }
      }
      if (tank2.getFluidAmount() > 0) {
        ItemStack filledContainer = Utils.fillFluidContainer(tank2, inventory[4], inventory[5]);
        if (filledContainer != null) {
          if (inventory[5] != null
              && OreDictionary.itemMatches(inventory[5], filledContainer, true))
            inventory[5].stackSize += filledContainer.stackSize;
          else if (inventory[5] == null) inventory[5] = filledContainer.copy();
          this.decrStackSize(4, filledContainer.stackSize);
          update = true;
        }
        if (tank2.getFluidAmount() > 0) {
          ForgeDirection f = ForgeDirection.getOrientation(facing);
          int out = Math.min(144, tank2.getFluidAmount());
          TileEntity te =
              Utils.getExistingTileEntity(
                  worldObj, xCoord + f.offsetX * 2, yCoord, zCoord + f.offsetZ * 2);
          if (te instanceof IFluidHandler
              && ((IFluidHandler) te).canFill(f.getOpposite(), tank2.getFluid().getFluid())) {
            int accepted =
                ((IFluidHandler) te)
                    .fill(f.getOpposite(), new FluidStack(tank2.getFluid().getFluid(), out), false);
            FluidStack drained = this.tank2.drain(accepted, true);
            ((IFluidHandler) te).fill(f.getOpposite(), drained, true);
          }
        }
      }
      if (tank2.getFluidAmount() != prevAmount) update = true;

      ItemStack emptyContainer = Utils.drainFluidContainer(tank0, inventory[0]);
      if (emptyContainer != null) {
        if (inventory[1] != null && OreDictionary.itemMatches(inventory[1], emptyContainer, true))
          inventory[1].stackSize += emptyContainer.stackSize;
        else if (inventory[1] == null) inventory[1] = emptyContainer.copy();
        this.decrStackSize(0, emptyContainer.stackSize);
        update = true;
      }
      emptyContainer = Utils.drainFluidContainer(tank1, inventory[2]);
      if (emptyContainer != null) {
        if (inventory[3] != null && OreDictionary.itemMatches(inventory[3], emptyContainer, true))
          inventory[3].stackSize += emptyContainer.stackSize;
        else if (inventory[3] == null) inventory[3] = emptyContainer.copy();
        this.decrStackSize(2, emptyContainer.stackSize);
        update = true;
      }

      if (update) {
        this.markDirty();
        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
      }
    }
  }
  @Override
  public void onUpdate() {
    ChargeUtils.discharge(2, this);

    if (inventory[0] != null) {
      if (fluidTank.getFluid() != null
          && fluidTank.getFluid().amount >= FluidContainerRegistry.BUCKET_VOLUME) {
        if (FluidContainerRegistry.isEmptyContainer(inventory[0])) {
          ItemStack tempStack =
              FluidContainerRegistry.fillFluidContainer(fluidTank.getFluid(), inventory[0]);

          if (tempStack != null) {
            if (inventory[1] == null) {
              fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);

              inventory[1] = tempStack;
              inventory[0].stackSize--;

              if (inventory[0].stackSize <= 0) {
                inventory[0] = null;
              }
            } else if (tempStack.isItemEqual(inventory[1])
                && tempStack.getMaxStackSize() > inventory[1].stackSize) {
              fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);

              inventory[1].stackSize++;
              inventory[0].stackSize--;

              if (inventory[0].stackSize <= 0) {
                inventory[0] = null;
              }
            }
          }
        }
      }
    }

    if (!worldObj.isRemote && worldObj.getWorldTime() % 20 == 0) {
      if (getEnergy() >= 100
          && (fluidTank.getFluid() == null
              || fluidTank.getFluid().amount + FluidContainerRegistry.BUCKET_VOLUME <= 10000)) {
        if (suck(true)) {
          PacketHandler.sendPacket(
              Transmission.CLIENTS_RANGE,
              new PacketTileEntity()
                  .setParams(Object3D.get(this), getNetworkedData(new ArrayList())),
              Object3D.get(this),
              50D);
        }

        clean(true);
      }
    }

    super.onUpdate();

    if (fluidTank.getFluid() != null) {
      for (ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS) {
        TileEntity tileEntity = Object3D.get(this).getFromSide(orientation).getTileEntity(worldObj);

        if (tileEntity instanceof IFluidHandler) {
          FluidStack toDrain =
              new FluidStack(fluidTank.getFluid(), Math.min(100, fluidTank.getFluidAmount()));
          fluidTank.drain(
              ((IFluidHandler) tileEntity).fill(orientation.getOpposite(), toDrain, true), true);

          if (fluidTank.getFluid() == null || fluidTank.getFluid().amount <= 0) {
            break;
          }
        }
      }
    }
  }
  @Override
  public void onUpdate() {
    if (!worldObj.isRemote) {
      ChargeUtils.discharge(2, this);

      if (inventory[0] != null) {
        if (inventory[0].getItem() instanceof IFluidContainerItem
            && ((IFluidContainerItem) inventory[0].getItem()).getFluid(inventory[0]) != null) {
          if (((IFluidContainerItem) inventory[0].getItem())
              .getFluid(inventory[0])
              .getFluid()
              .canBePlacedInWorld()) {
            fluidTank.fill(FluidContainerUtils.extractFluid(fluidTank, inventory[0]), true);

            if (((IFluidContainerItem) inventory[0].getItem()).getFluid(inventory[0]) == null
                || fluidTank.getFluidAmount() == fluidTank.getCapacity()) {
              if (inventory[1] == null) {
                inventory[1] = inventory[0].copy();
                inventory[0] = null;

                markDirty();
              }
            }
          }
        } else if (FluidContainerRegistry.isFilledContainer(inventory[0])) {
          FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);

          if ((fluidTank.getFluid() == null && itemFluid.amount <= fluidTank.getCapacity())
              || fluidTank.getFluid().amount + itemFluid.amount <= fluidTank.getCapacity()) {
            if ((fluidTank.getFluid() != null && !fluidTank.getFluid().isFluidEqual(itemFluid))
                || !itemFluid.getFluid().canBePlacedInWorld()) {
              return;
            }

            ItemStack containerItem = inventory[0].getItem().getContainerItem(inventory[0]);

            boolean filled = false;

            if (containerItem != null) {
              if (inventory[1] == null
                  || (inventory[1].isItemEqual(containerItem)
                      && inventory[1].stackSize + 1 <= containerItem.getMaxStackSize())) {
                inventory[0] = null;

                if (inventory[1] == null) {
                  inventory[1] = containerItem;
                } else {
                  inventory[1].stackSize++;
                }

                filled = true;
              }
            } else {
              inventory[0].stackSize--;

              if (inventory[0].stackSize == 0) {
                inventory[0] = null;
              }

              filled = true;
            }

            if (filled) {
              fluidTank.fill(itemFluid, true);
              markDirty();
            }
          }
        }
      }

      if (getEnergy() >= usage.fluidicPlenisherUsage
          && worldObj.getWorldTime() % 10 == 0
          && fluidTank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME) {
        if (fluidTank.getFluid().getFluid().canBePlacedInWorld()) {
          if (!finishedCalc) {
            doPlenish();
          } else {
            Coord4D below = Coord4D.get(this).getFromSide(ForgeDirection.DOWN);

            if (canReplace(below, false, false)
                && getEnergy() >= usage.fluidicPlenisherUsage
                && fluidTank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME) {
              if (fluidTank.getFluid().getFluid().canBePlacedInWorld()) {
                worldObj.setBlock(
                    below.xCoord,
                    below.yCoord,
                    below.zCoord,
                    MekanismUtils.getFlowingBlock(fluidTank.getFluid().getFluid()),
                    0,
                    3);

                setEnergy(getEnergy() - usage.fluidicPlenisherUsage);
                fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
              }
            }
          }
        }
      }
    }
  }
 @Override
 public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
   return tank.getFluid() != null && tank.getFluid().isFluidEqual(resource)
       ? tank.drain(resource.amount, doDrain)
       : null;
 }
 @Override
 public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
   return tank.drain(maxDrain, doDrain);
 }
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (!worldObj.isRemote) {
      ChargeUtils.charge(1, this);

      if (inventory[0] != null) {
        FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);

        if (inventory[0].getItem() instanceof IFluidContainerItem) {
          lavaTank.fill(
              FluidContainerUtils.extractFluid(
                  lavaTank, inventory[0], FluidChecker.check(FluidRegistry.LAVA)),
              true);
        } else if (fluid != null) {
          if (fluid != null && fluid.getFluidID() == FluidRegistry.LAVA.getID()) {
            if (lavaTank.getFluid() == null
                || lavaTank.getFluid().amount + fluid.amount <= lavaTank.getCapacity()) {
              lavaTank.fill(fluid, true);

              if (inventory[0].getItem().getContainerItem(inventory[0]) != null) {
                inventory[0] = inventory[0].getItem().getContainerItem(inventory[0]);
              } else {
                inventory[0].stackSize--;
              }

              if (inventory[0].stackSize == 0) {
                inventory[0] = null;
              }
            }
          }
        } else {
          int fuel = getFuel(inventory[0]);

          if (fuel > 0) {
            int fuelNeeded =
                lavaTank.getCapacity()
                    - (lavaTank.getFluid() != null ? lavaTank.getFluid().amount : 0);

            if (fuel <= fuelNeeded) {
              lavaTank.fill(new FluidStack(FluidRegistry.LAVA, fuel), true);

              if (inventory[0].getItem().getContainerItem(inventory[0]) != null) {
                inventory[0] = inventory[0].getItem().getContainerItem(inventory[0]);
              } else {
                inventory[0].stackSize--;
              }

              if (inventory[0].stackSize == 0) {
                inventory[0] = null;
              }
            }
          }
        }
      }

      double prev = getEnergy();

      transferHeatTo(getBoost());

      if (canOperate()) {
        setActive(true);

        lavaTank.drain(10, true);
        transferHeatTo(generators.heatGeneration);
      } else {
        setActive(false);
      }

      double[] loss = simulateHeat();
      applyTemperatureChange();

      lastTransferLoss = loss[0];
      lastEnvironmentLoss = loss[1];

      producingEnergy = getEnergy() - prev;
    }
  }
 @Override
 public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
   for (FluidTank _tank : (FluidTank[]) getTanks())
     if (_tank.getFluidAmount() > 0) return _tank.drain(maxDrain, doDrain);
   return null;
 }