Search in sources :

Example 1 with DictResource

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

the class ModuleCrafter method extractFromIInventory.

private ItemStack extractFromIInventory(IInventory inv, IResource wanteditem, int count, ForgeDirection dir) {
    IInventoryUtil invUtil = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv, dir);
    ItemIdentifier itemToExtract = null;
    if (wanteditem instanceof ItemResource) {
        itemToExtract = ((ItemResource) wanteditem).getItem();
    } else if (wanteditem instanceof DictResource) {
        int max = Integer.MIN_VALUE;
        ItemIdentifier toExtract = null;
        for (Map.Entry<ItemIdentifier, Integer> content : invUtil.getItemsAndCount().entrySet()) {
            if (wanteditem.matches(content.getKey(), IResource.MatchSettings.NORMAL)) {
                if (content.getValue() > max) {
                    max = content.getValue();
                    toExtract = content.getKey();
                }
            }
        }
        if (toExtract == null) {
            return null;
        }
        itemToExtract = toExtract;
    }
    int available = invUtil.itemCount(itemToExtract);
    if (available == 0) {
        return null;
    }
    if (!_service.useEnergy(neededEnergy() * Math.min(count, available))) {
        return null;
    }
    return invUtil.getMultipleItems(itemToExtract, Math.min(count, available));
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) DictResource(logisticspipes.request.resources.DictResource) ItemResource(logisticspipes.request.resources.ItemResource)

Example 2 with DictResource

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

the class PipeItemsRequestLogistics method simulateRequest.

@Override
public SimulationResult simulateRequest(ItemStack wanted) {
    final List<IResource> used = new ArrayList<>();
    final List<IResource> missing = new ArrayList<>();
    RequestTree.simulate(ItemIdentifier.get(wanted).makeStack(wanted.stackSize), this, new RequestLog() {

        @Override
        public void handleMissingItems(List<IResource> items) {
            missing.addAll(items);
        }

        @Override
        public void handleSucessfullRequestOf(IResource item, LinkedLogisticsOrderList parts) {
        }

        @Override
        public void handleSucessfullRequestOfList(List<IResource> items, LinkedLogisticsOrderList parts) {
            used.addAll(items);
        }
    });
    List<ItemStack> usedList = new ArrayList<>(used.size());
    List<ItemStack> missingList = new ArrayList<>(missing.size());
    for (IResource e : used) {
        if (e instanceof ItemResource) {
            usedList.add(((ItemResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
        } else if (e instanceof DictResource) {
            usedList.add(((DictResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
        }
    }
    for (IResource e : missing) {
        if (e instanceof ItemResource) {
            missingList.add(((ItemResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
        } else if (e instanceof DictResource) {
            missingList.add(((DictResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
        }
    }
    SimulationResult r = new SimulationResult();
    r.used = usedList;
    r.missing = missingList;
    return r;
}
Also used : LinkedLogisticsOrderList(logisticspipes.routing.order.LinkedLogisticsOrderList) RequestLog(logisticspipes.request.RequestLog) ArrayList(java.util.ArrayList) DictResource(logisticspipes.request.resources.DictResource) ItemStack(net.minecraft.item.ItemStack) ItemResource(logisticspipes.request.resources.ItemResource) IResource(logisticspipes.request.resources.IResource)

Example 3 with DictResource

use of logisticspipes.request.resources.DictResource 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 4 with DictResource

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

the class ModuleCrafter method addCrafting.

@Override
public ICraftingTemplate addCrafting(IResource toCraft) {
    List<ItemIdentifierStack> stack = getCraftedItems();
    if (stack == null) {
        return null;
    }
    IReqCraftingTemplate template = null;
    if (getUpgradeManager().isFuzzyUpgrade() && outputFuzzy().nextSetBit(0) != -1) {
        for (ItemIdentifierStack craftable : stack) {
            DictResource dict = new DictResource(craftable, null);
            dict.loadFromBitSet(outputFuzzy().copyValue());
            if (toCraft.matches(dict, IResource.MatchSettings.NORMAL)) {
                template = new DictCraftingTemplate(dict, this, priority.getValue());
                break;
            }
        }
    } else {
        for (ItemIdentifierStack craftable : stack) {
            if (toCraft.matches(craftable.getItem(), IResource.MatchSettings.NORMAL)) {
                template = new ItemCraftingTemplate(craftable, this, priority.getValue());
                break;
            }
        }
    }
    if (template == null) {
        return null;
    }
    IRequestItems[] target = new IRequestItems[9];
    for (int i = 0; i < 9; i++) {
        target[i] = this;
    }
    if (!isSatelliteConnected()) {
        // has a satellite configured and that one is unreachable
        return null;
    }
    if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
        IRouter r = getSatelliteRouter(-1);
        if (r != null) {
            IRequestItems sat = r.getPipe();
            for (int i = 6; i < 9; i++) {
                target[i] = sat;
            }
        }
    } else {
        for (int i = 0; i < 9; i++) {
            IRouter r = getSatelliteRouter(i);
            if (r != null) {
                target[i] = r.getPipe();
            }
        }
    }
    // Check all materials
    for (int i = 0; i < 9; i++) {
        ItemIdentifierStack resourceStack = dummyInventory.getIDStackInSlot(i);
        if (resourceStack == null || resourceStack.getStackSize() == 0) {
            continue;
        }
        IResource req;
        if (getUpgradeManager().isFuzzyUpgrade() && inputFuzzy(i).nextSetBit(0) != -1) {
            DictResource dict;
            req = dict = new DictResource(resourceStack, target[i]);
            dict.loadFromBitSet(inputFuzzy(i).copyValue());
        } else {
            req = new ItemResource(resourceStack, target[i]);
        }
        template.addRequirement(req, new CraftingChassisInformation(i, getPositionInt()));
    }
    int liquidCrafter = getUpgradeManager().getFluidCrafter();
    IRequestFluid[] liquidTarget = new IRequestFluid[liquidCrafter];
    if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
        IRouter r = getFluidSatelliteRouter(-1);
        if (r != null) {
            IRequestFluid sat = (IRequestFluid) r.getPipe();
            for (int i = 0; i < liquidCrafter; i++) {
                liquidTarget[i] = sat;
            }
        }
    } else {
        for (int i = 0; i < liquidCrafter; i++) {
            IRouter r = getFluidSatelliteRouter(i);
            if (r != null) {
                liquidTarget[i] = (IRequestFluid) r.getPipe();
            }
        }
    }
    for (int i = 0; i < liquidCrafter; i++) {
        FluidIdentifier liquid = getFluidMaterial(i);
        int amount = liquidAmounts.get(i);
        if (liquid == null || amount <= 0 || liquidTarget[i] == null) {
            continue;
        }
        template.addRequirement(new FluidResource(liquid, amount, liquidTarget[i]), null);
    }
    if (getUpgradeManager().hasByproductExtractor() && getByproductItem() != null) {
        template.addByproduct(getByproductItem());
    }
    return template;
}
Also used : DictResource(logisticspipes.request.resources.DictResource) DictCraftingTemplate(logisticspipes.request.DictCraftingTemplate) IReqCraftingTemplate(logisticspipes.request.IReqCraftingTemplate) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ItemResource(logisticspipes.request.resources.ItemResource) FluidResource(logisticspipes.request.resources.FluidResource) IRouter(logisticspipes.routing.IRouter) IRequestFluid(logisticspipes.interfaces.routing.IRequestFluid) ItemCraftingTemplate(logisticspipes.request.ItemCraftingTemplate) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) IResource(logisticspipes.request.resources.IResource)

Example 5 with DictResource

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

the class ModuleCrafter method extractFromInventory.

@Nonnull
private ItemStack extractFromInventory(@Nonnull IInventoryUtil invUtil, IResource wanteditem, int count) {
    final IPipeServiceProvider service = _service;
    if (service == null)
        return ItemStack.EMPTY;
    ItemIdentifier itemToExtract = null;
    if (wanteditem instanceof ItemResource) {
        itemToExtract = ((ItemResource) wanteditem).getItem();
    } else if (wanteditem instanceof DictResource) {
        int max = Integer.MIN_VALUE;
        ItemIdentifier toExtract = null;
        for (Map.Entry<ItemIdentifier, Integer> content : invUtil.getItemsAndCount().entrySet()) {
            if (wanteditem.matches(content.getKey(), IResource.MatchSettings.NORMAL)) {
                if (content.getValue() > max) {
                    max = content.getValue();
                    toExtract = content.getKey();
                }
            }
        }
        if (toExtract == null) {
            return ItemStack.EMPTY;
        }
        itemToExtract = toExtract;
    }
    if (itemToExtract == null)
        return ItemStack.EMPTY;
    int available = invUtil.itemCount(itemToExtract);
    if (available == 0 || !service.canUseEnergy(neededEnergy() * Math.min(count, available))) {
        return ItemStack.EMPTY;
    }
    ItemStack extracted = invUtil.getMultipleItems(itemToExtract, Math.min(count, available));
    service.useEnergy(neededEnergy() * extracted.getCount());
    return extracted;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) DictResource(logisticspipes.request.resources.DictResource) ItemStack(net.minecraft.item.ItemStack) ItemResource(logisticspipes.request.resources.ItemResource) Nonnull(javax.annotation.Nonnull)

Aggregations

DictResource (logisticspipes.request.resources.DictResource)14 ItemResource (logisticspipes.request.resources.ItemResource)8 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)7 IResource (logisticspipes.request.resources.IResource)6 IPipeServiceProvider (logisticspipes.interfaces.IPipeServiceProvider)5 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)5 ArrayList (java.util.ArrayList)4 IFilter (logisticspipes.interfaces.routing.IFilter)4 LogisticsPromise (logisticspipes.routing.LogisticsPromise)4 LogisticsItemOrder (logisticspipes.routing.order.LogisticsItemOrder)4 ItemStack (net.minecraft.item.ItemStack)4 Nonnull (javax.annotation.Nonnull)3 HashMap (java.util.HashMap)2 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