private void manageInventory() {
    if (FluidContainerUtils.isFluidContainer(inventory[0])) {
      FluidStack ret =
          FluidContainerUtils.handleContainerItem(
              this, inventory, editMode, fluidTank.getFluid(), getCurrentNeeded(), 0, 1, null);

      if (ret != null) {
        fluidTank.setFluid(PipeUtils.copy(ret, Math.min(fluidTank.getCapacity(), ret.amount)));

        int rejects = Math.max(0, ret.amount - fluidTank.getCapacity());

        if (rejects > 0) {
          pushUp(PipeUtils.copy(ret, rejects), true);
        }
      }
    }
  }
  public int pushUp(FluidStack fluid, boolean doFill) {
    Coord4D up = Coord4D.get(this).offset(EnumFacing.UP);

    if (up.getTileEntity(worldObj) instanceof TileEntityFluidTank) {
      IFluidHandler handler =
          CapabilityUtils.getCapability(
              up.getTileEntity(worldObj),
              CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
              EnumFacing.DOWN);

      if (PipeUtils.canFill(handler, fluid)) {
        return handler.fill(fluid, doFill);
      }
    }

    return 0;
  }
示例#3
0
  @Override
  public void update() {
    if (!world().isRemote) {
      if (cacheFluid != null) {
        if (getTransmitterNetwork().fluidStored == null) {
          getTransmitterNetwork().fluidStored = cacheFluid;
        } else {
          getTransmitterNetwork().fluidStored.amount += cacheFluid.amount;
        }

        cacheFluid = null;
      }

      if (getTransmitterNetwork(false) != null && getTransmitterNetwork(false).getSize() > 0) {
        int last = lastWrite != null ? lastWrite.amount : 0;

        if (last != getSaveShare()) {
          MekanismUtils.saveChunk(tile());
        }
      }

      IFluidHandler[] connectedAcceptors = PipeUtils.getConnectedAcceptors(tile());

      for (ForgeDirection side : getConnections(ConnectionType.PULL)) {
        if (connectedAcceptors[side.ordinal()] != null) {
          IFluidHandler container = connectedAcceptors[side.ordinal()];

          if (container != null) {
            FluidStack received = container.drain(side.getOpposite(), 100, false);

            if (received != null && received.amount != 0) {
              container.drain(
                  side.getOpposite(), getTransmitterNetwork().emit(received, true), true);
            }
          }
        }
      }
    }

    super.update();
  }
示例#4
0
  @Override
  public synchronized void refresh() {
    Set<IGridTransmitter<FluidNetwork>> iterPipes =
        (Set<IGridTransmitter<FluidNetwork>>) transmitters.clone();
    Iterator it = iterPipes.iterator();

    possibleAcceptors.clear();
    acceptorDirections.clear();

    while (it.hasNext()) {
      IGridTransmitter<FluidNetwork> conductor = (IGridTransmitter<FluidNetwork>) it.next();

      if (conductor == null || ((TileEntity) conductor).isInvalid()) {
        it.remove();
        transmitters.remove(conductor);
      } else {
        conductor.setTransmitterNetwork(this);
      }
    }

    for (IGridTransmitter<FluidNetwork> transmitter : iterPipes) {
      IFluidHandler[] acceptors = PipeUtils.getConnectedAcceptors((TileEntity) transmitter);

      for (IFluidHandler acceptor : acceptors) {
        ForgeDirection side =
            ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor));

        if (side != null
            && acceptor != null
            && !(acceptor instanceof IGridTransmitter)
            && transmitter.canConnectToAcceptor(side, true)) {
          possibleAcceptors.add(acceptor);
          acceptorDirections.put(
              acceptor, ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor)));
        }
      }
    }
  }
  @Override
  public int fill(EnumFacing from, FluidStack resource, boolean doFill) {
    if (resource != null && canFill(from, resource.getFluid())) {
      int filled = fluidTank.fill(resource, doFill);

      if (filled < resource.amount && !isActive) {
        filled += pushUp(PipeUtils.copy(resource, resource.amount - filled), doFill);
      }

      if (filled > 0 && from == EnumFacing.UP) {
        if (valve == 0) {
          needsPacket = true;
        }

        valve = 20;
        valveFluid = resource.getFluid();
      }

      return filled;
    }

    return 0;
  }
示例#6
0
 @Override
 public boolean isValidAcceptor(TileEntity tile, ForgeDirection side) {
   return PipeUtils.getConnections(tile())[side.ordinal()];
 }