@Override
  public void update() {
    if (--remainingDelay > 0) return;

    IInventory real = inventoryProvider().getInventory();
    int side = inventoryProvider().getInterfacedSide();
    if (real == null || side < 0) return;

    InventoryWrapper inv = InventoryWrapper.wrapInventory(real).setSlotsFromSide(side);
    InventoryWrapper filt = InventoryWrapper.wrapInventory(filter).setSlotsAll();

    List<ItemKey> checked = new ArrayList<ItemKey>(9);

    boolean requestAttempted = false;
    boolean requestedSomething = false;

    for (int i = 0; i < filter.getSizeInventory(); i++) {
      ItemKeyStack keyStack = ItemKeyStack.get(filter.getStackInSlot(i));

      if (keyStack == null || checked.contains(keyStack.key())) continue;

      int toRequest = filt.getItemCount(keyStack.key());
      int inInventory = inv.getItemCount(keyStack.key()) + getEnroute(keyStack.key());
      int missing = toRequest - inInventory;

      if (missing <= 0 || (requestWhenEmpty && inInventory > 0)) continue;

      RequestConsole req = new RequestConsole().setDestination(routeLayer().getRequester());
      req.setCrafting(true).setPulling(true).setPartials(true);
      ItemKeyStack request = ItemKeyStack.get(keyStack.key(), missing);
      req.makeRequest(request);

      requestAttempted = true;

      if (req.requested() > 0) {
        addToRequestList(request.key(), req.requested());
        requestedSomething = true;
      }
    }
    if (requestAttempted)
      RouteFX.spawnType1(
          RouteFX.color_request, 8, routeLayer().getCoords(), routeLayer().getWorld());

    if (requestAttempted && requestedSomething) operationsWithoutRequest = 0;
    else operationsWithoutRequest++;

    remainingDelay = operationDelay() + throttleDelay();
  }
Пример #2
0
  public CollectionPathFinder collect() {
    Map<ItemKey, Integer> collected = new HashMap<ItemKey, Integer>();
    for (StartEndPath l : requester.getRouter().getRoutesByCost()) {
      Router r = l.end;
      IWorldRouter wr = r.getParent();
      if (wr instanceof IWorldCrafter && collectCrafts) {
        IWorldCrafter c = (IWorldCrafter) wr;
        c.getBroadcastedItems(collected);
        List<ItemKeyStack> list = c.getCraftedItems();
        if (list != null)
          for (ItemKeyStack stack : list)
            if (!collected.containsKey(stack.key())) collected.put(stack.key(), null);
      } else if (wr instanceof IWorldBroadcaster && collectBroadcasts) {
        IWorldBroadcaster b = (IWorldBroadcaster) wr;
        b.getBroadcastedItems(collected);
      }
    }

    this.collected = collected;
    return this;
  }
 @Override
 public void trackedItemReceived(ItemKeyStack s) {
   removeFromRequestList(s.key(), s.stackSize);
 }