Пример #1
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;
    }
  }
Пример #2
0
  public int fill(
      ForgeDirection from, FluidStack resource, boolean doFill, boolean doPush, int pushToken) {
    if (resource == null || resource.amount <= 0) {
      return 0;
    }

    if (!canFill(from, resource.getFluid())) {
      return 0;
    }

    if (network == null) {
      return 0;
    }
    if (network.canAcceptLiquid(resource)) {
      network.setFluidType(resource);
    } else {
      return 0;
    }
    resource = resource.copy();
    resource.amount = Math.min(MAX_IO_PER_TICK, resource.amount);

    if (doPush) {
      return pushLiquid(from, resource, doFill, pushToken);
    } else {
      return tank.fill(resource, doFill);
    }
  }
Пример #3
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;
            }
          }
        }
      }
    }
  }
Пример #4
0
 @Override
 public boolean canConnectToConduit(ForgeDirection direction, IConduit con) {
   if (!super.canConnectToConduit(direction, con)) {
     return false;
   }
   if (!(con instanceof LiquidConduit)) {
     return false;
   }
   if (getFluidType() != null && ((LiquidConduit) con).getFluidType() == null) {
     return false;
   }
   return LiquidConduitNetwork.areFluidsCompatable(
       getFluidType(), ((LiquidConduit) con).getFluidType());
 }
Пример #5
0
  private int pushLiquid(ForgeDirection from, FluidStack pushStack, boolean doPush, int token) {
    if (token == currentPushToken
        || pushStack == null
        || pushStack.amount <= 0
        || network == null) {
      return 0;
    }
    currentPushToken = token;
    int pushed = 0;
    int total = pushStack.amount;

    ForgeDirection dir = startPushDir;
    FluidStack toPush = pushStack.copy();

    int filledLocal = tank.fill(toPush, doPush);
    toPush.amount -= filledLocal;
    pushed += filledLocal;

    do {
      if (dir != from && canOutputToDir(dir)) {
        if (getConduitConnections().contains(dir)) {
          ILiquidConduit conduitCon = getFluidConduit(dir);
          if (conduitCon != null) {
            int toCon =
                ((LiquidConduit) conduitCon).pushLiquid(dir.getOpposite(), toPush, doPush, token);
            toPush.amount -= toCon;
            pushed += toCon;
          }
        } else if (getExternalConnections().contains(dir)) {
          IFluidHandler con = getTankContainer(getLocation().getLocation(dir));
          if (con != null) {
            int toExt = con.fill(dir.getOpposite(), toPush, doPush);
            toPush.amount -= toExt;
            pushed += toExt;
            if (doPush) {
              network.outputedToExternal(toExt);
            }
          }
        }
      }
      dir = getNextDir(dir);
    } while (dir != startPushDir && pushed < total);

    return pushed;
  }