Package net.minecraftforge.fluids

Examples of net.minecraftforge.fluids.IFluidHandler


  @Override
  protected boolean doPull(ForgeDirection dir) {
    boolean res = super.doPull(dir);
    BlockCoord loc = getLocation().getLocation(dir);
    IFluidHandler target = FluidUtil.getFluidHandler(worldObj, loc);
    if(target != null) {
      FluidTankInfo[] infos = target.getTankInfo(dir.getOpposite());
      if(infos != null) {
        for (FluidTankInfo info : infos) {
          if(info.fluid != null && info.fluid.amount > 0) {
            if(canFill(dir, info.fluid.getFluid())) {
              FluidStack canPull = info.fluid.copy();
              canPull.amount = Math.min(IO_MB_TICK, canPull.amount);
              FluidStack drained = target.drain(dir.getOpposite(), canPull, false);
              if(drained != null && drained.amount > 0) {
                int filled = fill(dir, drained, false);
                if(filled > 0) {
                  drained = target.drain(dir.getOpposite(), filled, true);
                  fill(dir, drained, true);
                  return res;
                }
              }
            }
View Full Code Here


      BlockCoord myLoc = new BlockCoord(this);
      for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        BlockCoord checkLoc = myLoc.getLocation(dir);
        TileEntity te = worldObj.getTileEntity(checkLoc.x, checkLoc.y, checkLoc.z);
        if(te instanceof IFluidHandler && !(te instanceof TileHyperCube)) {
          IFluidHandler fh = (IFluidHandler) te;
          fluidHandlers.add(new NetworkFluidHandler(this, fh, dir));
        }
      }
      fluidHandlersDirty = false;
    }
View Full Code Here

    boolean res = super.doPush(dir);
    if(outputTank.getFluidAmount() > 0) {

      BlockCoord loc = getLocation().getLocation(dir);
      IFluidHandler target = FluidUtil.getFluidHandler(worldObj, loc);
      if(target != null) {
        if(target.canFill(dir.getOpposite(), outputTank.getFluid().getFluid())) {
          FluidStack push = outputTank.getFluid().copy();
          push.amount = Math.min(push.amount, IO_MB_TICK);
          int filled = target.fill(dir.getOpposite(), push, true);
          if(filled > 0) {
            outputTank.drain(filled, true);
            tanksDirty = true;
            return res;
          }
View Full Code Here

    }

    boolean res = super.doPull(dir);
    if(inputTank.getFluidAmount() < inputTank.getCapacity()) {
      BlockCoord loc = getLocation().getLocation(dir);
      IFluidHandler target = FluidUtil.getFluidHandler(worldObj, loc);
      if(target != null) {

        if(inputTank.getFluidAmount() > 0) {
          FluidStack canPull = inputTank.getFluid().copy();
          canPull.amount = inputTank.getCapacity() - inputTank.getFluidAmount();
          canPull.amount = Math.min(canPull.amount, IO_MB_TICK);
          FluidStack drained = target.drain(dir.getOpposite(), canPull, true);
          if(drained != null && drained.amount > 0) {
            inputTank.fill(drained, true);
            tanksDirty = true;
            return res;
          }
        } else {
          //empty input tank
          FluidTankInfo[] infos = target.getTankInfo(dir.getOpposite());
          if(infos != null) {
            for (FluidTankInfo info : infos) {
              if(info.fluid != null && info.fluid.amount > 0) {
                if(canFill(dir, info.fluid.getFluid())) {
                  FluidStack canPull = info.fluid.copy();
                  canPull.amount = Math.min(IO_MB_TICK, canPull.amount);
                  FluidStack drained = target.drain(dir.getOpposite(), canPull, true);
                  if(drained != null && drained.amount > 0) {
                    inputTank.fill(drained, true);
                    tanksDirty = true;
                    return res;
                  }
View Full Code Here

  @Override
  protected boolean doPull(ForgeDirection dir) {
    boolean res = super.doPull(dir);
    BlockCoord loc = getLocation().getLocation(dir);
    IFluidHandler target = FluidUtil.getFluidHandler(worldObj, loc);
    if(target != null) {
      FluidTankInfo[] infos = target.getTankInfo(dir.getOpposite());
      if(infos != null) {
        for (FluidTankInfo info : infos) {
          if(info.fluid != null && info.fluid.amount > 0) {
            if(canFill(dir, info.fluid.getFluid())) {
              FluidStack canPull = info.fluid.copy();
              canPull.amount = Math.min(IO_MB_TICK, canPull.amount);
              FluidStack drained = target.drain(dir.getOpposite(), canPull, false);
              if(drained != null && drained.amount > 0) {
                int filled = fill(dir, drained, false);
                if(filled > 0) {
                  drained = target.drain(dir.getOpposite(), filled, true);
                  fill(dir, drained, true);
                  return res;
                }
              }
            }
View Full Code Here

      if(!outputIterator.hasNext()) {
        outputIterator = outputs.iterator();
      }
      LiquidOutput output = outputIterator.next();
      if(output != null) {
        IFluidHandler cont = getTankContainer(output.location);
        if(cont != null) {
          FluidStack offer = tank.getFluid().copy();
          int filled = cont.fill(output.dir, offer, true);
          if(filled > 0) {
            tank.addAmount(-filled);

          }
        }
View Full Code Here

    if(tank.isFull()) {
      return false;
    }

    IFluidHandler extTank = getTankContainer(advancedLiquidConduit, dir);
    if(extTank != null) {
      int maxExtract = Math.min(maxExtractPerTick, tank.getAvailableSpace());

      if(liquidType == null || !tank.containsValidLiquid()) {
        FluidStack drained = extTank.drain(dir.getOpposite(), maxExtract, true);
        if(drained == null || drained.amount <= 0) {
          return false;
        }
        setFluidType(drained);
        tank.setLiquid(drained.copy());
        return true;
      }

      FluidStack couldDrain = liquidType.copy();
      couldDrain.amount = maxExtract;

      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 false;
      }

      //      FluidStack drained = extTank.drain(dir.getOpposite(), couldDrain, true);
      //      if(drained == null || drained.amount <= 0) {
      //        return false;
      //      }
      //      tank.addAmount(drained.amount);    

      //Have to use this 'double handle' approach to work around an issue with TiC
      FluidStack drained = extTank.drain(dir.getOpposite(), maxExtract, false);
      if(drained == null || drained.amount == 0) {
        return false;
      } else {
        if(drained.isFluidEqual(getFluidType())) {
          drained = extTank.drain(dir.getOpposite(), maxExtract, true);
          tank.addAmount(drained.amount);
        }
      }
      return true;
    }
View Full Code Here

    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;
View Full Code Here

            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);
            }
View Full Code Here

    for (AbstractTankConduit con : conduits) {
      Set<ForgeDirection> extCons = con.getExternalConnections();

      for (ForgeDirection dir : extCons) {
        if(con.canOutputToDir(dir)) {
          IFluidHandler externalTank = con.getExternalHandler(dir);
          if(externalTank != null) {
            externals.add(new LocatedFluidHandler(externalTank, con.getLocation().getLocation(dir), dir.getOpposite()));
          }
        }
      }
View Full Code Here

TOP

Related Classes of net.minecraftforge.fluids.IFluidHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.