Esempio n. 1
0
 @Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   if (resource.isFluidEqual(this.src1)) {
     int ret = Math.min(this.buf - this.src1.amount, resource.amount);
     if (doFill) this.src1.amount += ret;
     return ret;
   } else if (resource.isFluidEqual(this.src2)) {
     int ret = Math.min(this.buf - this.src2.amount, resource.amount);
     if (doFill) this.src2.amount += ret;
     return ret;
   } else if (this.src1 == null) {
     int ret = Math.min(this.buf, resource.amount);
     if (doFill) {
       this.src1 = resource.copy();
       this.src1.amount = ret;
     }
     return ret;
   } else if (this.src2 == null) {
     int ret = Math.min(this.buf, resource.amount);
     if (doFill) {
       this.src2 = resource.copy();
       this.src2.amount = ret;
     }
     return ret;
   }
   return 0;
 }
Esempio n. 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);
    }
  }
Esempio n. 3
0
  public int addFluid(FluidStack stack) {
    if (stack == null || stack.amount == 0) {
      return 0;
    }
    // TODO: Caching. Later.
    recalculateFillLevel();

    int current = fillLevel;
    int free = capacity - current;

    if (free < 1) {
      return 0;
    }
    int insert = Math.min(stack.amount, free);

    for (FluidStack contentStack : content) {
      if (contentStack.isFluidEqual(stack)) {
        contentStack.amount += insert;
        return insert;
      }
    }
    FluidStack copy = stack.copy();
    copy.amount = insert;
    content.add(copy);

    return insert;
  }
Esempio n. 4
0
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
    if (resource == null) {
      return 0;
    }

    FluidStack resourceCopy = resource.copy();
    int totalUsed = 0;

    FluidStack liquid = tank.getFluid();
    if (liquid != null && liquid.amount > 0 && !liquid.isFluidEqual(resourceCopy)) {
      return 0;
    }

    while (resourceCopy.amount > 0) {
      int used = tank.fill(resourceCopy, doFill);
      resourceCopy.amount -= used;
      if (used > 0) {
        markDirty();
      }

      totalUsed += used;
    }

    return totalUsed;
  }
Esempio n. 5
0
  /* ITANKCONTAINER */
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
    if (resource == null) {
      return 0;
    }

    resource = resource.copy();
    int totalUsed = 0;
    TileTank tankToFill = getBottomTank();

    FluidStack liquid = tankToFill.tank.getFluid();
    if (liquid != null && liquid.amount > 0 && !liquid.isFluidEqual(resource)) {
      return 0;
    }

    while (tankToFill != null && resource.amount > 0) {
      int used = tankToFill.tank.fill(resource, doFill);
      resource.amount -= used;
      if (used > 0) {
        tankToFill.hasUpdate = true;
      }

      totalUsed += used;
      tankToFill = getTankAbove(tankToFill);
    }
    return totalUsed;
  }
Esempio n. 6
0
  public void autoOutputToSides(
      IOpenModsProxy proxy, int amountPerTick, TileEntity currentTile, SyncableFlags sides) {

    if (currentTile.worldObj == null) return;
    // every 10 ticks refresh the surrounding tanks
    if (proxy.getTicks(currentTile.worldObj) % 10 == 0) {
      refreshSurroundingTanks(currentTile, sides);
    }

    if (getFluidAmount() > 0 && surroundingTanks.size() > 0) {
      FluidStack drainedFluid = drain(Math.min(getFluidAmount(), amountPerTick), true);
      if (drainedFluid != null) {
        Collections.shuffle(surroundingTanks);
        // for each surrounding tank
        for (ForgeDirection side : surroundingTanks) {
          TileEntity otherTank = BlockUtils.getTileInDirection(currentTile, side);
          if (drainedFluid.amount > 0) {
            drainedFluid = drainedFluid.copy();
            if (otherTank instanceof IFluidHandler) {
              drainedFluid.amount -=
                  ((IFluidHandler) otherTank).fill(side.getOpposite(), drainedFluid, true);
            } else {
              drainedFluid.amount -=
                  ModuleBuildCraft.tryAcceptIntoPipe(otherTank, drainedFluid, side.getOpposite());
            }
          }
        }
        // fill any remainder
        if (drainedFluid.amount > 0) {
          fill(drainedFluid, true);
        }
      }
    }
  }
  private void outputActiveLava() {
    FluidStack fluid = tank[1].getFluid();
    if (fluid != null) {
      if (itemStacks[2] != null && itemStacks[2].stackSize == 1) {
        ItemStack itemStack = itemStacks[2];
        if (FluidContainerRegistry.isEmptyContainer(itemStack)) {
          if (fluid.amount >= FluidContainerRegistry.BUCKET_VOLUME) {
            FluidStack oneBucketOfFluid =
                new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME);
            ItemStack filledBucket =
                FluidContainerRegistry.fillFluidContainer(
                    oneBucketOfFluid, FluidContainerRegistry.EMPTY_BUCKET);
            itemStacks[2] = filledBucket;
            fluid.amount -= FluidContainerRegistry.BUCKET_VOLUME;
          }
        } else if (itemStack.getItem() instanceof IFluidContainerItem && (workingTick % 20) == 10) {
          if (fluid.amount >= FluidContainerRegistry.BUCKET_VOLUME) {

            IFluidContainerItem fluidContainerItem = (IFluidContainerItem) itemStack.getItem();
            FluidStack fluidStack = fluid.copy();

            if (fluidStack.amount > FluidContainerRegistry.BUCKET_VOLUME)
              fluidStack.amount = FluidContainerRegistry.BUCKET_VOLUME;

            int amount = fluidContainerItem.fill(itemStack, fluidStack, true);
            if (amount > 0) {
              fluid.amount -= amount;
            }
            if (fluid.amount == 0) tank[1].setFluid(null);
          }
        }
      }
    }
  }
Esempio n. 8
0
  public boolean addLiquid(FluidStack inFS) {
    if (inFS != null) {
      // We dont want very hot liquids stored here so if they are much hotter than boiling water, we
      // prevent it.
      if (inFS.getFluid() != null && inFS.getFluid().getTemperature(inFS) > 385) return false;

      if (fluid == null) {
        fluid = inFS.copy();
        if (fluid.amount > this.getMaxLiquid()) {
          fluid.amount = getMaxLiquid();
          inFS.amount = inFS.amount - this.getMaxLiquid();

        } else inFS.amount = 0;
      } else {
        // check if the barrel is full or if the fluid being added does not match the barrel liquid
        if (fluid.amount == getMaxLiquid() || !fluid.isFluidEqual(inFS)) return false;

        int a = fluid.amount + inFS.amount - getMaxLiquid();
        fluid.amount = Math.min(fluid.amount + inFS.amount, getMaxLiquid());
        if (a > 0) inFS.amount = a;
        else inFS.amount = 0;
      }
      worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
      return true;
    }

    return false;
  }
 public static void registerAsContainer(Fluid fluid) {
   FluidStack stack =
       FluidRegistry.getFluidStack(fluid.getName(), FluidContainerRegistry.BUCKET_VOLUME);
   stack = stack.copy();
   stack.amount = cell.volume;
   FluidContainerRegistry.registerFluidContainer(
       new FluidContainerData(
           stack, new ItemStack(cell, 1, LiquidRegistry.getID(stack)), new ItemStack(cell, 1, 0)));
 }
Esempio n. 10
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;
  }
Esempio n. 11
0
  public synchronized int emit(FluidStack fluidToSend, boolean doTransfer) {
    if (fluidToSend == null
        || (fluidStored != null && fluidStored.getFluid() != fluidToSend.getFluid())) {
      return 0;
    }

    int toUse = Math.min(getFluidNeeded(), fluidToSend.amount);

    if (doTransfer) {
      if (fluidStored == null) {
        fluidStored = fluidToSend.copy();
        fluidStored.amount = toUse;
      } else {
        fluidStored.amount += toUse;
      }
    }

    return toUse;
  }
Esempio n. 12
0
  public static FluidStack consumePartialFiniteFluidBlock(
      BlockPos fluidBlockPos, FluidStack fullFluidStack, int maxAmount) {
    if (fluidBlockPos.world.isRemote) return null;

    int deltaMeta = -(maxAmount / FINITE_FLUID_MB_PER_META);
    int newMeta = fluidBlockPos.getMeta() + deltaMeta;

    if (deltaMeta == 0) return null;

    FluidStack fluidConsumed = fullFluidStack.copy();
    fluidConsumed.amount = Math.abs(deltaMeta) * FINITE_FLUID_MB_PER_META;

    if (newMeta >= 0)
      fluidBlockPos.world.setBlockMetadataWithNotify(
          fluidBlockPos.x, fluidBlockPos.y, fluidBlockPos.z, newMeta, 2);
    else fluidBlockPos.world.setBlockToAir(fluidBlockPos.x, fluidBlockPos.y, fluidBlockPos.z);

    return fluidConsumed;
  }
Esempio n. 13
0
  @Override
  public void updateEntity() {
    if (!worldObj.isRemote) {
      careForInventorySlot();
      if (worldObj.isRaining()
          && !this.getSealed()
          && worldObj.canBlockSeeTheSky(xCoord, yCoord, zCoord)) {
        if (this.fluid == null) fluid = new FluidStack(TFCFluid.FRESHWATER, 1);
        else if (this.fluid != null && fluid.getFluid() == TFCFluid.FRESHWATER)
          fluid.amount = Math.min(fluid.amount + 1, 10000);
      }

      processTimer++;

      if (processTimer > 100) {
        ProcessItems();
        processTimer = 0;
      }

      if (fluid != null && fluid.amount == 0) fluid = null;

      if (mode == MODE_IN) {
        FluidStack inLiquid = FluidContainerRegistry.getFluidForFilledItem(getInputStack());
        if (inLiquid != null) {
          if (this.fluid == null) {
            this.fluid = inLiquid.copy();
            this.setInventorySlotContents(
                0, getInputStack().getItem().getContainerItem(getInputStack()));
          } else if (inLiquid.isFluidEqual(this.fluid)) {
            if (addLiquid(inLiquid.amount)) {
              this.setInventorySlotContents(
                  0, getInputStack().getItem().getContainerItem(getInputStack()));
            }
          }
        }
      } else if (mode == MODE_OUT) {
        if (FluidContainerRegistry.isEmptyContainer(getInputStack())) {
          this.setInventorySlotContents(0, this.removeLiquid(getInputStack()));
        }
      }
    }
  }
Esempio n. 14
0
  @Override
  public int fill(ItemStack container, FluidStack resource, boolean doFill) {
    if (resource == null) return 0;

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

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

    final int amountPerTank = resource.amount / count;
    if (amountPerTank == 0) return 0;

    FluidStack resourcePerTank = resource.copy();
    resourcePerTank.amount = amountPerTank;

    int filledPerTank = tank.fill(resourcePerTank, doFill);
    if (doFill) saveTank(container, tank);
    return filledPerTank * count;
  }
  private void inputLava() {

    if (itemStacks[0] != null) {
      Item item = itemStacks[0].getItem();

      if (item != null) {
        if (item == Items.lava_bucket || item == ModItems.itemActiveLavaBucket) {

          if (tank[0].getCapacity() - tank[0].getFluidAmount()
              >= FluidContainerRegistry.BUCKET_VOLUME) {
            FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(itemStacks[0]);

            int result = tank[0].fill(fluidStack, false);

            if (result == FluidContainerRegistry.BUCKET_VOLUME) {
              itemStacks[0] = new ItemStack(Items.bucket, 1);
              tank[0].fill(fluidStack, true);
            }
          }

        } else if (item instanceof IFluidContainerItem && (workingTick % 20) == 5) {
          IFluidContainerItem fluidContainerItem = (IFluidContainerItem) item;
          FluidStack fluidStack = fluidContainerItem.getFluid(itemStacks[0]);

          if (fluidStack != null) {
            fluidStack = fluidStack.copy();

            if (fluidStack.amount > FluidContainerRegistry.BUCKET_VOLUME)
              fluidStack.amount = FluidContainerRegistry.BUCKET_VOLUME;

            int result = tank[0].fill(fluidStack, true);
            if (result > 0) {
              fluidContainerItem.drain(itemStacks[0], result, true);
            }
          }
        }
      }
    }
  }
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
    Stack<PartP2PLiquids> stack = this.getDepth();

    for (PartP2PLiquids t : stack) {
      if (t == this) {
        return 0;
      }
    }

    stack.push(this);

    List<PartP2PLiquids> list = this.getOutputs(resource.getFluid());
    int requestTotal = 0;

    Iterator<PartP2PLiquids> i = list.iterator();
    while (i.hasNext()) {
      PartP2PLiquids l = i.next();
      IFluidHandler tank = l.getTarget();
      if (tank != null) {
        l.tmpUsed = tank.fill(l.side.getOpposite(), resource.copy(), false);
      } else {
        l.tmpUsed = 0;
      }

      if (l.tmpUsed <= 0) {
        i.remove();
      } else {
        requestTotal += l.tmpUsed;
      }
    }

    if (requestTotal <= 0) {
      if (stack.pop() != this) {
        throw new IllegalStateException("Invalid Recursion detected.");
      }

      return 0;
    }

    if (!doFill) {
      if (stack.pop() != this) {
        throw new IllegalStateException("Invalid Recursion detected.");
      }

      return Math.min(resource.amount, requestTotal);
    }

    int available = resource.amount;
    int used = 0;

    i = list.iterator();
    while (i.hasNext()) {
      PartP2PLiquids l = i.next();

      FluidStack insert = resource.copy();
      insert.amount = (int) Math.ceil(insert.amount * ((double) l.tmpUsed / (double) requestTotal));
      if (insert.amount > available) {
        insert.amount = available;
      }

      IFluidHandler tank = l.getTarget();
      if (tank != null) {
        l.tmpUsed = tank.fill(l.side.getOpposite(), insert.copy(), true);
      } else {
        l.tmpUsed = 0;
      }

      available -= insert.amount;
      used += insert.amount;
    }

    if (stack.pop() != this) {
      throw new IllegalStateException("Invalid Recursion detected.");
    }

    return used;
  }
Esempio n. 17
0
  public void autoFillFromSides(
      IOpenModsProxy proxy, int amountPerTick, TileEntity currentTile, SyncableFlags sides) {

    // every 10 ticks refresh the surrounding tanks
    if (proxy.getTicks(currentTile.worldObj) % 10 == 0) {
      refreshSurroundingTanks(currentTile, sides);
    }

    // if we've got space in the tank, and we've got at least 1 surrounding
    // tank
    if (getSpace() > 0 && surroundingTanks.size() > 0) {
      // shuffle them up
      Collections.shuffle(surroundingTanks);

      // for each surrounding tank
      for (ForgeDirection side : surroundingTanks) {
        TileEntity otherTank = BlockUtils.getTileInDirection(currentTile, side);
        if (otherTank instanceof IFluidHandler) {

          IFluidHandler handler = (IFluidHandler) otherTank;

          // get the fluid inside that tank. If the fluid is one of
          // our acceptable fluids
          // (or we dont have any acceptable fluids), and it matches
          // what we have in the tank
          // or the tank is currently empty...
          FluidStack currentFluid = getFluid();
          if (currentFluid == null) {
            FluidTankInfo[] infos = handler.getTankInfo(side.getOpposite());
            for (FluidTankInfo info : infos) {
              if (acceptableFluids.length == 0 && info.fluid != null) {
                currentFluid = info.fluid;
              } else {
                for (FluidStack acceptFluid : acceptableFluids) {
                  if (info.fluid != null && info.fluid.isFluidEqual(acceptFluid)) {
                    currentFluid = info.fluid;
                    break;
                  }
                }
              }
              if (currentFluid != null) {
                break;
              }
            }
          }
          if (currentFluid != null) {
            // copy the fluid and set the amount to the amount we
            // want to drain
            FluidStack drainStack = currentFluid.copy();
            drainStack.amount = Math.min(amountPerTick, getSpace());
            // drain it out and fill our own tank
            FluidStack drained = handler.drain(side.getOpposite(), drainStack, true);
            fill(drained, true);
            // if it's full, chillax.
            if (getCapacity() == getFluidAmount()) {
              break;
            }
          }
        }
      }
    }
  }
Esempio n. 18
0
 @Override
 public PressurizedInput copy() {
   return new PressurizedInput(theSolid.copy(), theFluid.copy(), theGas.copy());
 }
Esempio n. 19
0
 public CeramicFurnaceOutletRecipe(FluidStack aStack, ItemStack aOutput) {
   stack = aStack.copy();
   output = aOutput.copy();
 }