Search in sources :

Example 1 with DictCraftingTemplate

use of logisticspipes.request.DictCraftingTemplate 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)

Aggregations

IRequestFluid (logisticspipes.interfaces.routing.IRequestFluid)1 IRequestItems (logisticspipes.interfaces.routing.IRequestItems)1 DictCraftingTemplate (logisticspipes.request.DictCraftingTemplate)1 IReqCraftingTemplate (logisticspipes.request.IReqCraftingTemplate)1 ItemCraftingTemplate (logisticspipes.request.ItemCraftingTemplate)1 DictResource (logisticspipes.request.resources.DictResource)1 FluidResource (logisticspipes.request.resources.FluidResource)1 IResource (logisticspipes.request.resources.IResource)1 ItemResource (logisticspipes.request.resources.ItemResource)1 IRouter (logisticspipes.routing.IRouter)1 FluidIdentifier (logisticspipes.utils.FluidIdentifier)1 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)1