Пример #1
0
  private void doExtract() {

    BlockCoord loc = getLocation();
    if (!hasConnectionMode(ConnectionMode.INPUT)) {
      return;
    }

    // assume failure, reset to 0 if we do extract
    ticksSinceFailedExtract++;
    if (ticksSinceFailedExtract > 9 && ticksSinceFailedExtract % 10 != 0) {
      // after 10 ticks of failing, only check every 10 ticks
      return;
    }

    Fluid f = tank.getFluid() == null ? null : tank.getFluid().getFluid();
    int token = network == null ? -1 : network.getNextPushToken();
    for (ForgeDirection dir : externalConnections) {
      if (autoExtractForDir(dir)) {

        IFluidHandler extTank = getTankContainer(getLocation().getLocation(dir));
        if (extTank != null) {

          boolean foundFluid = false;
          FluidTankInfo[] info = extTank.getTankInfo(dir.getOpposite());
          if (info != null) {
            for (FluidTankInfo inf : info) {
              if (inf != null && inf.fluid != null && inf.fluid.amount > 0) {
                foundFluid = true;
              }
            }
          }
          if (!foundFluid) {
            return;
          }

          FluidStack couldDrain = extTank.drain(dir.getOpposite(), MAX_EXTRACT_PER_TICK, false);
          if (couldDrain != null && couldDrain.amount > 0 && canFill(dir, couldDrain.getFluid())) {
            int used =
                pushLiquid(
                    dir, couldDrain, true, network == null ? -1 : network.getNextPushToken());
            extTank.drain(dir.getOpposite(), used, true);
            if (used > 0 && network != null && network.getFluidType() == null) {
              network.setFluidType(couldDrain);
            }
            if (used > 0) {
              ticksSinceFailedExtract = 0;
            }
          }
        }
      }
    }
  }
Пример #2
0
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {

    if (network == null || resource == null) {
      return 0;
    }
    if (!canFill(from, resource.getFluid())) {
      return 0;
    }

    // Note: This is just a guard against mekansims pipes that will continuously
    // call
    // fill on us if we push liquid to them.
    if (filledFromThisTick.contains(getLocation().getLocation(from))) {
      return 0;
    }

    if (network.lockNetworkForFill()) {
      if (doFill) {
        filledFromThisTick.add(getLocation().getLocation(from));
      }
      try {
        int res =
            fill(from, resource, doFill, true, network == null ? -1 : network.getNextPushToken());
        if (doFill && externalConnections.contains(from) && network != null) {
          network.addedFromExternal(res);
        }
        return res;
      } finally {
        network.unlockNetworkFromFill();
      }
    } else {
      return 0;
    }
  }