Search in sources :

Example 11 with ItemResource

use of logisticspipes.request.resources.ItemResource in project LogisticsPipes by RS485.

the class RequestTree method request.

public static int request(ItemIdentifierStack item, IRequestItems requester, RequestLog log, boolean acceptPartial, boolean simulateOnly, boolean logMissing, boolean logUsed, EnumSet<ActiveRequestType> requestFlags, IAdditionalTargetInformation info) {
    ItemResource req = new ItemResource(item, requester);
    RequestTree tree = new RequestTree(req, null, requestFlags, info);
    if (!simulateOnly && (tree.isDone() || ((tree.getPromiseAmount() > 0) && acceptPartial))) {
        LinkedLogisticsOrderList list = tree.fullFillAll();
        if (log != null) {
            log.handleSucessfullRequestOf(req.copyForDisplayWith(item.getStackSize()), list);
        }
        return tree.getPromiseAmount();
    } else {
        if (log != null) {
            if (!tree.isDone()) {
                tree.recurseFailedRequestTree();
            }
            if (logMissing) {
                tree.sendMissingMessage(log);
            }
            if (logUsed) {
                tree.sendUsedMessage(log);
            }
        }
        return tree.getPromiseAmount();
    }
}
Also used : LinkedLogisticsOrderList(logisticspipes.routing.order.LinkedLogisticsOrderList) ItemResource(logisticspipes.request.resources.ItemResource)

Example 12 with ItemResource

use of logisticspipes.request.resources.ItemResource in project LogisticsPipes by RS485.

the class ModuleCrafter method extractFromLogisticsCraftingTable.

@Nonnull
private ItemStack extractFromLogisticsCraftingTable(NeighborTileEntity<LogisticsCraftingTableTileEntity> adjacentCraftingTable, IResource wanteditem, int count) {
    final IPipeServiceProvider service = _service;
    if (service == null)
        return ItemStack.EMPTY;
    ItemStack extracted = extractFromInventory(Objects.requireNonNull(LPNeighborTileEntityKt.getInventoryUtil(adjacentCraftingTable)), wanteditem, count);
    if (!extracted.isEmpty()) {
        return extracted;
    }
    ItemStack retstack = ItemStack.EMPTY;
    while (count > 0) {
        ItemStack stack = adjacentCraftingTable.getTileEntity().getOutput(wanteditem, service);
        if (stack.isEmpty()) {
            break;
        }
        if (retstack.isEmpty()) {
            if (!wanteditem.matches(ItemIdentifier.get(stack), wanteditem instanceof ItemResource ? IResource.MatchSettings.WITHOUT_NBT : IResource.MatchSettings.NORMAL)) {
                break;
            }
        } else {
            if (!retstack.isItemEqual(stack)) {
                break;
            }
            if (!ItemStack.areItemStackTagsEqual(retstack, stack)) {
                break;
            }
        }
        if (!service.useEnergy(neededEnergy() * stack.getCount())) {
            break;
        }
        if (retstack.isEmpty()) {
            retstack = stack;
        } else {
            retstack.grow(stack.getCount());
        }
        count -= stack.getCount();
        if (Objects.requireNonNull(getUpgradeManager()).isFuzzyUpgrade()) {
            break;
        }
    }
    return retstack;
}
Also used : IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) ItemStack(net.minecraft.item.ItemStack) ItemResource(logisticspipes.request.resources.ItemResource) Nonnull(javax.annotation.Nonnull)

Aggregations

ItemResource (logisticspipes.request.resources.ItemResource)12 DictResource (logisticspipes.request.resources.DictResource)8 IResource (logisticspipes.request.resources.IResource)6 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)6 ItemStack (net.minecraft.item.ItemStack)6 ArrayList (java.util.ArrayList)4 Nonnull (javax.annotation.Nonnull)4 LinkedLogisticsOrderList (logisticspipes.routing.order.LinkedLogisticsOrderList)4 HashMap (java.util.HashMap)3 IPipeServiceProvider (logisticspipes.interfaces.IPipeServiceProvider)3 IFilter (logisticspipes.interfaces.routing.IFilter)3 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)3 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)2 IRequestItems (logisticspipes.interfaces.routing.IRequestItems)2 Particles (logisticspipes.pipefxhandlers.Particles)2