Search in sources :

Example 1 with RequestLog

use of logisticspipes.request.RequestLog 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 2 with RequestLog

use of logisticspipes.request.RequestLog in project LogisticsPipes by RS485.

the class PipeItemsRequestLogistics method performRequest.

@Override
public List<ItemStack> performRequest(ItemStack wanted) {
    final List<IResource> missing = new ArrayList<>();
    RequestTree.request(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) {
        }
    }, null);
    List<ItemStack> missingList = new ArrayList<>(missing.size());
    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()));
        }
    }
    return missingList;
}
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)

Aggregations

ArrayList (java.util.ArrayList)2 RequestLog (logisticspipes.request.RequestLog)2 DictResource (logisticspipes.request.resources.DictResource)2 IResource (logisticspipes.request.resources.IResource)2 ItemResource (logisticspipes.request.resources.ItemResource)2 LinkedLogisticsOrderList (logisticspipes.routing.order.LinkedLogisticsOrderList)2 ItemStack (net.minecraft.item.ItemStack)2