Package net.minecraftforge.fluids

Examples of net.minecraftforge.fluids.FluidStack


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


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

    return true;
  }

  private void drainConduitToNearestExternal(LiquidConduit con, List<LocatedFluidHandler> externals) {
    BlockCoord conLoc = con.getLocation();
    FluidStack toDrain = con.getTank().getFluid();
    if(toDrain == null) {
      return;
    }
    int closestDistance = Integer.MAX_VALUE;
    LocatedFluidHandler closestTank = null;
    for (LocatedFluidHandler lh : externals) {
      int distance = lh.bc.distanceSquared(conLoc);
      if(distance < closestDistance) {
        int couldFill = lh.tank.fill(lh.dir, toDrain.copy(), false);
        if(couldFill > 0) {
          closestTank = lh;
          closestDistance = distance;
        }
      }
    }

    if(closestTank != null) {
      int filled = closestTank.tank.fill(closestTank.dir, toDrain.copy(), true);
      con.getTank().addAmount(-filled);
    }

  }
View Full Code Here

    totalAmount = tank.getFluidAmount();
    if(totalAmount <= 0) {
      return;
    }
    FluidStack available = tank.getFluid();
    int totalRequested = 0;
    int numRequests = 0;
    // Then to external connections
    for (ForgeDirection dir : con.getExternalConnections()) {
      if(con.canOutputToDir(dir)) {
        IFluidHandler extCon = con.getExternalHandler(dir);
        if(extCon != null) {
          int amount = extCon.fill(dir.getOpposite(), available.copy(), false);
          if(amount > 0) {
            totalRequested += amount;
            numRequests++;
          }
        }
      }
    }

    if(numRequests > 0) {
      int amountPerRequest = Math.min(totalAmount, totalRequested) / numRequests;
      amountPerRequest = Math.min(maxFlowVolume, amountPerRequest);

      FluidStack requestSource = available.copy();
      requestSource.amount = amountPerRequest;
      for (ForgeDirection dir : con.getExternalConnections()) {
        if(con.canOutputToDir(dir)) {
          IFluidHandler extCon = con.getExternalHandler(dir);
          if(extCon != null) {
            int amount = extCon.fill(dir.getOpposite(), requestSource.copy(), true);
            if(amount > 0) {
              outputedToExternal(amount);
              tank.addAmount(-amount);
            }
          }
View Full Code Here

  public boolean extractFrom(EnderLiquidConduit con, ForgeDirection conDir) {
    NetworkTank tank = getTank(con, conDir);
    if(tank == null || !tank.isValid()) {
      return false;
    }
    FluidStack drained = tank.externalTank.drain(conDir.getOpposite(), MAX_EXTRACT_PER_TICK, false);
    if(drained == null || drained.amount <= 0 || !matchedFilter(drained, con, conDir, true)) {
      return false;
    }
    int amountAccepted = fillFrom(tank, drained, true);
    if(amountAccepted <= 0) {
View Full Code Here

  public boolean setFluid(int index, ItemStack stack) {
    if(stack == null) {
      return setFluid(index, (Fluid) null);
    }
    FluidStack f = FluidUtil.getFluidFromItem(stack);
    if(f == null || f.getFluid() == null) {
      return false;
    }
    return setFluid(index, f);
  }
View Full Code Here

     * The Fortron Liquid
     */
    FortronHelper.FLUID_FORTRON = new Fluid("fortron");
    FortronHelper.FLUID_FORTRON.setGaseous(true);
    FluidRegistry.registerFluid(FortronHelper.FLUID_FORTRON);
    FortronHelper.FLUIDSTACK_FORTRON = new FluidStack(FortronHelper.FLUID_FORTRON, 0);

    itemModuleRepulsion = new ItemModuleRepulsion(Settings.getNextItemID());
    itemModuleApproximation = new ItemModule(Settings.getNextItemID(), "moduleApproximation").setMaxStackSize(1).setCost(1f);
    itemModuleArray = new ItemModuleArray(Settings.getNextItemID()).setCost(3f);

View Full Code Here

          if(inventory[0].getItem() instanceof IFluidContainerItem)
          {
            fluidTank.fill(FluidContainerUtils.extractFluid(fluidTank, inventory[0]), true);
          }
          else {
            FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);
 
            if(fluid != null && fluidTank.getFluid() == null || fluid.isFluidEqual(fluidTank.getFluid()) && fluidTank.getFluid().amount+fluid.amount <= fluidTank.getCapacity())
            {
              fluidTank.fill(fluid, true);
 
              if(inventory[0].getItem().hasContainerItem(inventory[0]))
              {
View Full Code Here

    if(type == 0)
    {
      if(dataStream.readBoolean())
      {
        fluidTank.setFluid(new FluidStack(FluidRegistry.getFluid(dataStream.readInt()), dataStream.readInt()));
      }
      else {
        fluidTank.setFluid(null);
      }
View Full Code Here

        }

        if(getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this) && isValidGas(gasTank.getGas()) && (fluidTank.getFluid() == null || (fluidTank.getFluid().amount < MAX_FLUID && gasEquals(gasTank.getGas(), fluidTank.getFluid()))))
        {
          setActive(true);
          fluidTank.fill(new FluidStack(gasTank.getGas().getGas().getFluid(), 1), true);
          gasTank.draw(1, true);
          setEnergy(getEnergy() - ENERGY_USAGE);
        }
        else {
          if(prevEnergy >= getEnergy())
          {
            setActive(false);
          }
        }
      }
      else if(mode == 1)
      {
        if(inventory[0] != null && gasTank.getGas() != null)
        {
          gasTank.draw(GasTransmission.addGas(inventory[0], gasTank.getGas()), true);
        }

        if(gasTank.getGas() != null)
        {
          GasStack toSend = new GasStack(gasTank.getGas().getGas(), Math.min(gasTank.getGas().amount, gasOutput));

          TileEntity tileEntity = Coord4D.get(this).getFromSide(MekanismUtils.getLeft(facing)).getTileEntity(worldObj);

          if(tileEntity instanceof IGasHandler)
          {
            if(((IGasHandler)tileEntity).canReceiveGas(MekanismUtils.getLeft(facing).getOpposite(), gasTank.getGas().getGas()))
            {
              gasTank.draw(((IGasHandler)tileEntity).receiveGas(MekanismUtils.getLeft(facing).getOpposite(), toSend), true);
            }
          }
        }

        if(inventory[2] != null)
        {
          if(inventory[2].getItem() instanceof IFluidContainerItem)
          {
            fluidTank.fill(FluidContainerUtils.extractFluid(fluidTank, inventory[2]), true);
           
            if(((IFluidContainerItem)inventory[2].getItem()).getFluid(inventory[2]) == null || fluidTank.getFluidAmount() == fluidTank.getCapacity())
            {
              if(inventory[3] == null)
              {
                inventory[3] = inventory[2].copy();
                inventory[2] = null;
               
                markDirty();
              }
            }
          }
          else if(FluidContainerRegistry.isFilledContainer(inventory[2]))
          {
            FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(inventory[2]);
 
            if((fluidTank.getFluid() == null && itemFluid.amount <= MAX_FLUID) || fluidTank.getFluid().amount+itemFluid.amount <= MAX_FLUID)
            {
              if(fluidTank.getFluid() != null && !fluidTank.getFluid().isFluidEqual(itemFluid))
              {
View Full Code Here

TOP

Related Classes of net.minecraftforge.fluids.FluidStack

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.