Ejemplo n.º 1
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;
  }
  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);
          }
        }
      }
    }
  }
Ejemplo n.º 3
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);
        }
      }
    }
  }
Ejemplo n.º 4
0
  public int fill_(ItemStack container, FluidStack resource, boolean doFill) {
    if (resource == null) {
      return 0;
    }

    if (!doFill) {
      if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) {
        return Math.min(fluidCapacity, resource.amount);
      }

      FluidStack stack =
          FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid"));

      if (stack == null) {
        return Math.min(fluidCapacity, resource.amount);
      }

      if (!stack.isFluidEqual(resource)) {
        return 0;
      }

      return Math.min(fluidCapacity - stack.amount, resource.amount);
    }

    if (container.stackTagCompound == null) {
      container.stackTagCompound = new NBTTagCompound();
    }

    if (!container.stackTagCompound.hasKey("Fluid")) {
      NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound());

      if (fluidCapacity < resource.amount) {
        fluidTag.setInteger("Amount", fluidCapacity);
        container.stackTagCompound.setTag("Fluid", fluidTag);
        return fluidCapacity;
      }

      container.stackTagCompound.setTag("Fluid", fluidTag);
      return resource.amount;
    }

    NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid");
    FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag);

    if (!stack.isFluidEqual(resource)) {
      return 0;
    }

    int filled = fluidCapacity - stack.amount;
    if (resource.amount < filled) {
      stack.amount += resource.amount;
      filled = resource.amount;
    } else {
      stack.amount = fluidCapacity;
    }

    container.stackTagCompound.setTag("Fluid", stack.writeToNBT(fluidTag));
    return filled;
  }
Ejemplo n.º 5
0
  public void ProcessItems() {
    if (this.getInvCount() == 0) {
      if (getFluidStack() != null) {
        recipe =
            BarrelManager.getInstance()
                .findMatchingRecipe(getInputStack(), getFluidStack(), this.sealed);
        if (recipe != null && !worldObj.isRemote) {
          int time = 0;
          if (sealtime > 0) time = (int) TFC_Time.getTotalHours() - sealtime;
          else if (unsealtime > 0) time = (int) TFC_Time.getTotalHours() - unsealtime;

          // Make sure that the recipe meets the time requirements
          if (recipe.isSealedRecipe() && time < recipe.sealTime) return;

          ItemStack origIS = getInputStack().copy();
          FluidStack origFS = getFluidStack().copy();
          if (fluid.isFluidEqual(recipe.getResultFluid(origIS, origFS, time))) {
            fluid.amount -= recipe.getResultFluid(origIS, origFS, time).amount;
          } else {
            this.fluid = recipe.getResultFluid(origIS, origFS, time);
            this.fluid.amount = origFS.amount;
          }
          this.setInventorySlotContents(0, recipe.getResult(origIS, origFS, time));
        }
      }
    }
  }
Ejemplo n.º 6
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;
  }
Ejemplo n.º 7
0
  @Override
  public void onNetworksCreated(List<FluidNetwork> networks) {
    if (fluidStored != null && FMLCommonHandler.instance().getEffectiveSide().isServer()) {
      int[] caps = new int[networks.size()];
      int cap = 0;

      for (FluidNetwork network : networks) {
        caps[networks.indexOf(network)] = network.getCapacity();
        cap += network.getCapacity();
      }

      fluidStored.amount = Math.min(cap, fluidStored.amount);

      int[] values = ListUtils.calcPercentInt(ListUtils.percent(caps), fluidStored.amount);

      for (FluidNetwork network : networks) {
        int index = networks.indexOf(network);

        if (values[index] > 0) {
          network.fluidStored = new FluidStack(fluidStored.getFluid(), values[index]);
          network.fluidScale = network.getScale();
          network.refFluid = fluidStored.getFluid();
        }
      }
    }

    fluidScale = 0;
    fluidStored = null;
    refFluid = null;
  }
Ejemplo n.º 8
0
  public FluidNetwork(Set<FluidNetwork> networks) {
    for (FluidNetwork net : networks) {
      if (net != null) {
        if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
          if (net.refFluid != null && net.fluidScale > fluidScale) {
            refFluid = net.refFluid;
            fluidScale = net.fluidScale;
            fluidStored = net.fluidStored;

            net.fluidScale = 0;
            net.refFluid = null;
            net.fluidStored = null;
          }
        } else {
          if (net.fluidStored != null) {
            if (fluidStored == null) {
              fluidStored = net.fluidStored;
            } else {
              fluidStored.amount += net.fluidStored.amount;
            }

            net.fluidStored = null;
          }
        }

        addAllTransmitters(net.transmitters);
        net.deregister();
      }
    }

    fluidScale = getScale();

    refresh();
    register();
  }
  private WrappedStack(Object object, int stackSize) {
    if (object instanceof Item) {
      object = new ItemStack((Item) object);
    } else if (object instanceof Block) {
      object = new ItemStack((Block) object);
    } else if (object instanceof Fluid) {
      object = new FluidStack((Fluid) object, 1000);
    }

    if (object instanceof ItemStack) {
      ItemStack itemStack = ((ItemStack) object).copy();
      objectType = "itemstack";
      this.stackSize = stackSize;
      itemStack.stackSize = 1;
      wrappedStack = itemStack;
    } else if (object instanceof OreStack) {
      OreStack oreStack = (OreStack) object;
      objectType = "orestack";
      this.stackSize = stackSize;
      oreStack.stackSize = 1;
      wrappedStack = oreStack;
    } else if (object instanceof ArrayList) {
      ArrayList<?> objectList = (ArrayList<?>) object;

      OreStack possibleOreStack = OreStack.getOreStackFromList(objectList);

      if (possibleOreStack != null) {
        objectType = "orestack";
        this.stackSize = stackSize;
        possibleOreStack.stackSize = 1;
        wrappedStack = possibleOreStack;
      } else {
        objectType = null;
        this.stackSize = -1;
        wrappedStack = null;
      }
    } else if (object instanceof FluidStack) {
      FluidStack fluidStack = (FluidStack) object;
      objectType = "fluidstack";
      this.stackSize = stackSize;
      fluidStack.amount = 1;
      wrappedStack = fluidStack;
    } else if (object instanceof WrappedStack) {
      WrappedStack wrappedStackObject = (WrappedStack) object;

      if (wrappedStackObject.getWrappedObject() != null) {
        this.objectType = wrappedStackObject.objectType;
        this.stackSize = stackSize;
        this.wrappedStack = wrappedStackObject.wrappedStack;
      } else {
        objectType = null;
        this.stackSize = -1;
        wrappedStack = null;
      }
    } else {
      objectType = null;
      this.stackSize = -1;
      wrappedStack = null;
    }
  }
Ejemplo n.º 10
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);
    }
  }
Ejemplo n.º 11
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;
  }
Ejemplo n.º 12
0
  public FluidStack drain_(ItemStack container, int maxDrain, boolean doDrain) {
    if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) {
      return null;
    }

    FluidStack stack =
        FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid"));
    if (stack == null) {
      return null;
    }

    int currentAmount = stack.amount;
    stack.amount = Math.min(stack.amount, maxDrain);
    if (doDrain) {
      if (currentAmount == stack.amount) {
        container.stackTagCompound.removeTag("Fluid");

        if (container.stackTagCompound.hasNoTags()) {
          container.stackTagCompound = null;
        }
        return stack;
      }

      NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid");
      fluidTag.setInteger("Amount", currentAmount - stack.amount);
      container.stackTagCompound.setTag("Fluid", fluidTag);
    }
    return stack;
  }
Ejemplo n.º 13
0
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
      if (transferDelay == 0) {
        didTransfer = false;
      } else {
        transferDelay--;
      }

      int stored = fluidStored != null ? fluidStored.amount : 0;

      if (stored != prevStored) {
        needsUpdate = true;
      }

      prevStored = stored;

      if (didTransfer != prevTransfer || needsUpdate) {
        MinecraftForge.EVENT_BUS.post(new FluidTransferEvent(this, fluidStored, didTransfer));
        needsUpdate = false;
      }

      prevTransfer = didTransfer;

      if (fluidStored != null) {
        fluidStored.amount -= tickEmit(fluidStored, true);

        if (fluidStored != null && fluidStored.amount <= 0) {
          fluidStored = null;
        }
      }
    }
  }
Ejemplo n.º 14
0
 @Override
 public FluidStack getFluid(ItemStack container) {
   FluidTank tank = readTank(container);
   if (tank == null) return null;
   FluidStack result = tank.getFluid();
   if (result != null) result.amount *= container.stackSize;
   return result;
 }
Ejemplo n.º 15
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;
  }
Ejemplo n.º 16
0
  public boolean addLiquid(FluidStack f) {
    if (fluid == null) fluid = f;
    else {
      if (fluid.amount == 10000 || !fluid.isFluidEqual(f)) return false;

      fluid.amount = Math.min(fluid.amount + f.amount, 10000);
    }
    return true;
  }
Ejemplo n.º 17
0
 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)));
 }
Ejemplo n.º 18
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;
  }
Ejemplo n.º 19
0
 @Override
 public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
   if (this.res == null) return null;
   FluidStack ret = this.res.copy();
   ret.amount = Math.min(maxDrain, ret.amount);
   if (doDrain) {
     this.res.amount -= ret.amount;
     if (this.res.amount == 0) this.res = null;
   }
   return ret;
 }
Ejemplo n.º 20
0
 @Override
 public void handleInitPacket(NBTTagCompound nbt) {
   this.rotation = nbt.getByte("rotation");
   this.sealed = nbt.getBoolean("sealed");
   if (nbt.getInteger("fluid") != -1) {
     if (fluid != null) fluid.amount = nbt.getInteger("fluidAmount");
     else fluid = new FluidStack(nbt.getInteger("fluid"), nbt.getInteger("fluidAmount"));
   } else {
     fluid = null;
   }
   this.worldObj.func_147479_m(xCoord, yCoord, zCoord);
 }
Ejemplo n.º 21
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;
  }
 @Override
 public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) {
   FluidStack fs = getFluid(container);
   if (fs == null) return null;
   int drained = Math.min(maxDrain, fs.amount);
   FluidStack stack = new FluidStack(fs, drained);
   if (doDrain) {
     fs.amount -= drained;
     if (fs.amount <= 0) ItemNBTHelper.remove(container, "fluid");
     else ItemNBTHelper.setFluidStack(container, "fluid", fs);
   }
   return stack;
 }
Ejemplo n.º 23
0
 public ItemStack setLiquid(ItemStack bucket, FluidStack liquid, EntityPlayer par3EntityPlayer) {
   CarbonContainer item = (CarbonContainer) bucket.getItem();
   if (liquid == null || liquid.amount < item.volume) return bucket;
   int id = LiquidRegistry.getID(liquid);
   if (--bucket.stackSize <= 0) {
     bucket = new ItemStack(item.filledItem, 1, id);
   } else {
     ItemStack bucket2 = new ItemStack(item.filledItem, 1, id);
     if (!par3EntityPlayer.inventory.addItemStackToInventory(bucket2))
       par3EntityPlayer.func_146097_a(bucket2, false, true);
   }
   liquid.amount -= item.volume;
   return bucket;
 }
Ejemplo n.º 24
0
 @Override
 public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
   // if (resource == null) return null;
   if (resource.equals(this.res)) return drain(from, resource.amount, doDrain);
   if (resource.equals(this.src1)) {
     FluidStack ret = this.src1.copy();
     ret.amount = Math.min(resource.amount, ret.amount);
     if (doDrain) {
       this.src1.amount -= ret.amount;
       if (this.src1.amount == 0) this.src1 = null;
     }
     return ret;
   }
   if (resource.equals(this.src2)) {
     FluidStack ret = this.src2.copy();
     ret.amount = Math.min(resource.amount, ret.amount);
     if (doDrain) {
       this.src2.amount -= ret.amount;
       if (this.src2.amount == 0) this.src2 = null;
     }
     return ret;
   }
   return null;
 }
 @Override
 public int fill(ItemStack container, FluidStack resource, boolean doFill) {
   if (resource != null) {
     FluidStack fs = getFluid(container);
     if (fs == null || resource.isFluidEqual(fs)) {
       int space = fs == null ? getCapacity(container) : getCapacity(container) - fs.amount;
       int accepted = Math.min(space, resource.amount);
       if (fs == null) fs = Utils.copyFluidStackWithAmount(resource, accepted, false);
       else fs.amount += accepted;
       if (doFill) ItemNBTHelper.setFluidStack(container, "fluid", fs);
       return accepted;
     }
   }
   return 0;
 }
Ejemplo n.º 26
0
 /**
  * This attempts to remove a portion of the water in this container and put it into a valid
  * Container Item
  */
 public ItemStack removeLiquid(ItemStack is) {
   if (is == null || is.stackSize > 1) return is;
   if (FluidContainerRegistry.isEmptyContainer(is)) {
     ItemStack out = FluidContainerRegistry.fillFluidContainer(fluid, is);
     if (out != null) {
       FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(out);
       fluid.amount -= fs.amount;
       is = null;
       if (fluid.amount == 0) {
         fluid = null;
       }
       worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
       return out;
     }
   } else if (fluid != null && is.getItem() instanceof IFluidContainerItem) {
     FluidStack isfs = ((IFluidContainerItem) is.getItem()).getFluid(is);
     if (isfs == null || fluid.isFluidEqual(isfs)) {
       fluid.amount -= ((IFluidContainerItem) is.getItem()).fill(is, fluid, true);
       if (fluid.amount == 0) fluid = null;
       worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
     }
   }
   return is;
 }
Ejemplo n.º 27
0
 public ItemStack removeLiquid(ItemStack is) {
   if (is == null) return is;
   if (FluidContainerRegistry.isEmptyContainer(is)) {
     ItemStack out = FluidContainerRegistry.fillFluidContainer(fluid, is);
     if (out != null) {
       FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(out);
       fluid.amount -= fs.amount;
       is = null;
       if (fluid.amount == 0) {
         fluid = null;
       }
       worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
       return out;
     }
   }
   return is;
 }
Ejemplo n.º 28
0
  @Override
  protected FluidNetwork create(Collection<IGridTransmitter<FluidNetwork>> collection) {
    FluidNetwork network = new FluidNetwork(collection);
    network.refFluid = refFluid;

    if (fluidStored != null) {
      if (network.fluidStored == null) {
        network.fluidStored = fluidStored;
      } else {
        network.fluidStored.amount += fluidStored.amount;
      }
    }

    network.fluidScale = network.getScale();

    return network;
  }
Ejemplo n.º 29
0
  @Override
  public int forceOutputFluid(FluidStack stack, boolean doOutput) {
    int origAmnt = stack.amount;
    for (int i = 0; i < 6; i++) {
      ForgeDirection d = ForgeDirection.getOrientation(i);
      if (getSide(d) instanceof ModMachineOutput) {
        SideConfig mConfig = configs[i];
        if (mConfig.tank >= 0 && mConfig.tank < 3) {
          int amnt = this.fillInternal(mConfig.tank, stack, doOutput);
          if (doOutput) stack.amount -= amnt;
          getSide(d).updateSide(configs[i], this, d);
          return amnt;
        }
      }
    }

    return 0;
  }
Ejemplo n.º 30
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;
  }