Search in sources :

Example 1 with LogisticsItemOrder

use of logisticspipes.routing.order.LogisticsItemOrder in project LogisticsPipes by RS485.

the class ModuleCrafter method cacheAreAllOrderesToBuffer.

public void cacheAreAllOrderesToBuffer() {
    boolean result = true;
    for (LogisticsItemOrder order : _service.getItemOrderManager()) {
        if (order.getDestination() instanceof IItemSpaceControl) {
            SinkReply reply = LogisticsManager.canSink(order.getDestination().getRouter(), null, true, order.getResource().getItem(), null, true, false);
            if (reply != null && reply.bufferMode == BufferMode.NONE && reply.maxNumberOfItems >= 1) {
                result = false;
                break;
            }
        } else {
            // No Space control
            result = false;
            break;
        }
    }
    cachedAreAllOrderesToBuffer = result;
}
Also used : IItemSpaceControl(logisticspipes.interfaces.routing.IItemSpaceControl) SinkReply(logisticspipes.utils.SinkReply) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder)

Example 2 with LogisticsItemOrder

use of logisticspipes.routing.order.LogisticsItemOrder in project LogisticsPipes by RS485.

the class ModuleProvider method tick.

@Override
public void tick() {
    currentTick = 0;
    checkUpdate(null);
    int itemsleft = itemsToExtract();
    int stacksleft = stacksToExtract();
    LogisticsItemOrder firstOrder = null;
    LogisticsItemOrder order = null;
    while (itemsleft > 0 && stacksleft > 0 && _service.getItemOrderManager().hasOrders(ResourceType.PROVIDER) && (firstOrder == null || firstOrder != order)) {
        if (firstOrder == null) {
            firstOrder = order;
        }
        order = _service.getItemOrderManager().peekAtTopRequest(ResourceType.PROVIDER);
        int sent = sendStack(order.getResource().stack, itemsleft, order.getDestination().getRouter().getSimpleID(), order.getInformation());
        if (sent < 0) {
            break;
        }
        _service.spawnParticle(Particles.VioletParticle, 3);
        stacksleft -= 1;
        itemsleft -= sent;
    }
}
Also used : LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder)

Example 3 with LogisticsItemOrder

use of logisticspipes.routing.order.LogisticsItemOrder in project LogisticsPipes by RS485.

the class ModuleCrafter method enabledUpdateEntity.

public void enabledUpdateEntity() {
    if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
        if (_service.isNthTick(6)) {
            cacheAreAllOrderesToBuffer();
        }
        if (_service.getItemOrderManager().isFirstOrderWatched()) {
            TileEntity tile = lastAccessedCrafter.get();
            if (tile != null) {
                _service.getItemOrderManager().setMachineProgress(SimpleServiceLocator.machineProgressProvider.getProgressForTile(tile));
            } else {
                _service.getItemOrderManager().setMachineProgress((byte) 0);
            }
        }
    } else {
        cachedAreAllOrderesToBuffer = false;
    }
    if (!_service.isNthTick(6)) {
        return;
    }
    waitingForCraft = false;
    if ((!_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA))) {
        if (getUpgradeManager().getCrafterCleanup() > 0) {
            List<AdjacentTileEntity> crafters = locateCrafters();
            ItemStack extracted = null;
            for (AdjacentTileEntity adjacentCrafter : crafters) {
                extracted = extractFiltered(adjacentCrafter, _cleanupInventory, cleanupModeIsExclude, getUpgradeManager().getCrafterCleanup() * 3);
                if (extracted != null && extracted.stackSize > 0) {
                    break;
                }
            }
            if (extracted != null && extracted.stackSize > 0) {
                _service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(extracted), ForgeDirection.UP);
                _service.getCacheHolder().trigger(CacheTypes.Inventory);
            }
        }
        return;
    }
    waitingForCraft = true;
    List<AdjacentTileEntity> adjacentCrafters = locateCrafters();
    if (adjacentCrafters.size() < 1) {
        if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
            _service.getItemOrderManager().sendFailed();
        }
        return;
    }
    List<ItemIdentifierStack> wanteditem = getCraftedItems();
    if (wanteditem == null || wanteditem.isEmpty()) {
        return;
    }
    _service.spawnParticle(Particles.VioletParticle, 2);
    int itemsleft = itemsToExtract();
    int stacksleft = stacksToExtract();
    while (itemsleft > 0 && stacksleft > 0 && (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA))) {
        // fetch but not remove.
        LogisticsItemOrder nextOrder = _service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
        int maxtosend = Math.min(itemsleft, nextOrder.getResource().stack.getStackSize());
        maxtosend = Math.min(nextOrder.getResource().getItem().getMaxStackSize(), maxtosend);
        // retrieve the new crafted items
        ItemStack extracted = null;
        AdjacentTileEntity adjacent = null;
        for (AdjacentTileEntity adjacentCrafter : adjacentCrafters) {
            adjacent = adjacentCrafter;
            extracted = extract(adjacent, nextOrder.getResource(), maxtosend);
            if (extracted != null && extracted.stackSize > 0) {
                break;
            }
        }
        if (extracted == null || extracted.stackSize == 0) {
            _service.getItemOrderManager().deferSend();
            break;
        }
        _service.getCacheHolder().trigger(CacheTypes.Inventory);
        lastAccessedCrafter = new WeakReference<>(adjacent.tileEntity);
        // send the new crafted items to the destination
        ItemIdentifier extractedID = ItemIdentifier.get(extracted);
        while (extracted.stackSize > 0) {
            if (!doesExtractionMatch(nextOrder, extractedID)) {
                LogisticsItemOrder startOrder = nextOrder;
                if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
                    do {
                        _service.getItemOrderManager().deferSend();
                        nextOrder = _service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
                    } while (!doesExtractionMatch(nextOrder, extractedID) && startOrder != nextOrder);
                }
                if (startOrder == nextOrder) {
                    int numtosend = Math.min(extracted.stackSize, extractedID.getMaxStackSize());
                    if (numtosend == 0) {
                        break;
                    }
                    stacksleft -= 1;
                    itemsleft -= numtosend;
                    ItemStack stackToSend = extracted.splitStack(numtosend);
                    //Route the unhandled item
                    _service.sendStack(stackToSend, -1, ItemSendMode.Normal, null);
                    continue;
                }
            }
            int numtosend = Math.min(extracted.stackSize, extractedID.getMaxStackSize());
            numtosend = Math.min(numtosend, nextOrder.getResource().stack.getStackSize());
            if (numtosend == 0) {
                break;
            }
            stacksleft -= 1;
            itemsleft -= numtosend;
            ItemStack stackToSend = extracted.splitStack(numtosend);
            if (nextOrder.getDestination() != null) {
                SinkReply reply = LogisticsManager.canSink(nextOrder.getDestination().getRouter(), null, true, ItemIdentifier.get(stackToSend), null, true, false);
                boolean defersend = false;
                if (reply == null || reply.bufferMode != BufferMode.NONE || reply.maxNumberOfItems < 1) {
                    defersend = true;
                }
                IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stackToSend);
                item.setDestination(nextOrder.getDestination().getRouter().getSimpleID());
                item.setTransportMode(TransportMode.Active);
                item.setAdditionalTargetInformation(nextOrder.getInformation());
                _service.queueRoutedItem(item, adjacent.direction);
                _service.getItemOrderManager().sendSuccessfull(stackToSend.stackSize, defersend, item);
            } else {
                _service.sendStack(stackToSend, -1, ItemSendMode.Normal, nextOrder.getInformation());
                _service.getItemOrderManager().sendSuccessfull(stackToSend.stackSize, false, null);
            }
            if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
                // fetch but not remove.
                nextOrder = _service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
            }
        }
    }
}
Also used : LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) SinkReply(logisticspipes.utils.SinkReply) ItemStack(net.minecraft.item.ItemStack) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 4 with LogisticsItemOrder

use of logisticspipes.routing.order.LogisticsItemOrder in project LogisticsPipes by RS485.

the class PipeLogisticsChassi method registerExtras.

@Override
public void registerExtras(IPromise promise) {
    if (!(promise instanceof LogisticsPromise)) {
        throw new UnsupportedOperationException("Extra has to be an item for a chassis pipe");
    }
    ItemIdentifierStack stack = new ItemIdentifierStack(((LogisticsPromise) promise).item, ((LogisticsPromise) promise).numberOfItems);
    _extras.add(new LogisticsItemOrder(new DictResource(stack, null), null, ResourceType.EXTRA, null));
}
Also used : LogisticsPromise(logisticspipes.routing.LogisticsPromise) DictResource(logisticspipes.request.resources.DictResource) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 5 with LogisticsItemOrder

use of logisticspipes.routing.order.LogisticsItemOrder in project LogisticsPipes by RS485.

the class ModuleCrafter method canProvide.

@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filters) {
    if (!_service.getItemOrderManager().hasExtras() || tree.hasBeenQueried(_service.getItemOrderManager())) {
        return;
    }
    IResource requestedItem = tree.getRequestType();
    if (!canCraft(requestedItem)) {
        return;
    }
    for (IFilter filter : filters) {
        if (filter.isBlocked() == filter.isFilteredItem(requestedItem) || filter.blockProvider()) {
            return;
        }
    }
    int remaining = 0;
    for (LogisticsItemOrder extra : _service.getItemOrderManager()) {
        if (extra.getType() == ResourceType.EXTRA) {
            if (extra.getResource().getItem().equals(requestedItem)) {
                remaining += extra.getResource().stack.getStackSize();
            }
        }
    }
    remaining -= root.getAllPromissesFor(this, getCraftedItem().getItem());
    if (remaining < 1) {
        return;
    }
    if (this.getUpgradeManager().isFuzzyUpgrade() && outputFuzzyFlags.getBitSet().nextSetBit(0) != -1) {
        DictResource dict = new DictResource(getCraftedItem(), null).loadFromBitSet(outputFuzzyFlags.getBitSet());
        LogisticsExtraDictPromise promise = new LogisticsExtraDictPromise(dict, Math.min(remaining, tree.getMissingAmount()), this, true);
        tree.addPromise(promise);
    } else {
        LogisticsExtraPromise promise = new LogisticsExtraPromise(getCraftedItem().getItem(), Math.min(remaining, tree.getMissingAmount()), this, true);
        tree.addPromise(promise);
    }
    tree.setQueried(_service.getItemOrderManager());
}
Also used : IFilter(logisticspipes.interfaces.routing.IFilter) DictResource(logisticspipes.request.resources.DictResource) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) LogisticsExtraDictPromise(logisticspipes.routing.LogisticsExtraDictPromise) IResource(logisticspipes.request.resources.IResource) LogisticsExtraPromise(logisticspipes.routing.LogisticsExtraPromise)

Aggregations

LogisticsItemOrder (logisticspipes.routing.order.LogisticsItemOrder)6 DictResource (logisticspipes.request.resources.DictResource)2 SinkReply (logisticspipes.utils.SinkReply)2 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)2 LogisticsCraftingTableTileEntity (logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity)1 IFilter (logisticspipes.interfaces.routing.IFilter)1 IItemSpaceControl (logisticspipes.interfaces.routing.IItemSpaceControl)1 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)1 IResource (logisticspipes.request.resources.IResource)1 LogisticsExtraDictPromise (logisticspipes.routing.LogisticsExtraDictPromise)1 LogisticsExtraPromise (logisticspipes.routing.LogisticsExtraPromise)1 LogisticsPromise (logisticspipes.routing.LogisticsPromise)1 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 AdjacentTileEntity (network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity)1