Search in sources :

Example 6 with IResource

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

Example 7 with IResource

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

the class RequestTreeNode method getProviders.

private static List<Pair<IProvide, List<IFilter>>> getProviders(IRouter destination, IResource item) {
    // get all the routers
    BitSet routersIndex = ServerRouter.getRoutersInterestedIn(item);
    // get the routing table
    List<ExitRoute> validSources = new ArrayList<>();
    for (int i = routersIndex.nextSetBit(0); i >= 0; i = routersIndex.nextSetBit(i + 1)) {
        IRouter r = SimpleServiceLocator.routerManager.getServerRouter(i);
        if (r.isCacheInvalid()) {
            // Skip Routers without a valid pipe
            continue;
        }
        List<ExitRoute> e = destination.getDistanceTo(r);
        if (e != null) {
            validSources.addAll(e);
        }
    }
    // closer providers are good
    validSources.sort(new workWeightedSorter(1.0));
    List<Pair<IProvide, List<IFilter>>> providers = new LinkedList<>();
    validSources.stream().filter(r -> r.containsFlag(PipeRoutingConnectionType.canRequestFrom)).forEach(r -> {
        CoreRoutedPipe pipe = r.destination.getPipe();
        if (pipe instanceof IProvide) {
            List<IFilter> list = new LinkedList<>(r.filters);
            providers.add(new Pair<>((IProvide) pipe, list));
        }
    });
    return providers;
}
Also used : SortedSet(java.util.SortedSet) Getter(lombok.Getter) IRouter(logisticspipes.routing.IRouter) IOrderInfoProvider(logisticspipes.routing.order.IOrderInfoProvider) PriorityQueue(java.util.PriorityQueue) IProvide(logisticspipes.interfaces.routing.IProvide) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) ActiveRequestType(logisticspipes.request.RequestTree.ActiveRequestType) RequestTree.workWeightedSorter(logisticspipes.request.RequestTree.workWeightedSorter) LinkedList(java.util.LinkedList) EnumSet(java.util.EnumSet) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) LinkedLogisticsOrderList(logisticspipes.routing.order.LinkedLogisticsOrderList) Iterator(java.util.Iterator) LogisticsOrderManager(logisticspipes.routing.order.LogisticsOrderManager) Set(java.util.Set) ExitRoute(logisticspipes.routing.ExitRoute) ServerRouter(logisticspipes.routing.ServerRouter) IResource(logisticspipes.request.resources.IResource) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) BitSet(java.util.BitSet) Collections(java.util.Collections) ICraft(logisticspipes.interfaces.routing.ICraft) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) LinkedList(java.util.LinkedList) IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) RequestTree.workWeightedSorter(logisticspipes.request.RequestTree.workWeightedSorter) ExitRoute(logisticspipes.routing.ExitRoute) IProvide(logisticspipes.interfaces.routing.IProvide) Pair(logisticspipes.utils.tuples.Pair)

Example 8 with IResource

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

the class RequestHandler method requestMacrolist.

public static void requestMacrolist(NBTTagCompound itemlist, final CoreRoutedPipe requester, final EntityPlayer player) {
    if (!requester.useEnergy(5)) {
        player.sendMessage(new TextComponentTranslation("lp.misc.noenergy"));
        return;
    }
    NBTTagList list = itemlist.getTagList("inventar", 10);
    final List<ItemIdentifierStack> transaction = new ArrayList<>(list.tagCount());
    for (int i = 0; i < list.tagCount(); i++) {
        NBTTagCompound itemnbt = list.getCompoundTagAt(i);
        NBTTagCompound itemNBTContent = itemnbt.getCompoundTag("nbt");
        if (!itemnbt.hasKey("nbt")) {
            itemNBTContent = null;
        }
        ItemIdentifierStack stack = ItemIdentifier.get(Item.getItemById(itemnbt.getInteger("id")), itemnbt.getInteger("data"), itemNBTContent).makeStack(itemnbt.getInteger("amount"));
        transaction.add(stack);
    }
    RequestTree.request(transaction, requester, new RequestLog() {

        @Override
        public void handleMissingItems(List<IResource> resources) {
            MainProxy.sendPacketToPlayer(PacketHandler.getPacket(MissingItems.class).setItems(resources).setFlag(true), player);
        }

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

        @Override
        public void handleSucessfullRequestOfList(List<IResource> resources, LinkedLogisticsOrderList parts) {
            MainProxy.sendPacketToPlayer(PacketHandler.getPacket(MissingItems.class).setItems(resources).setFlag(false), player);
            if (requester instanceof IRequestWatcher) {
                ((IRequestWatcher) requester).handleOrderList(null, parts);
            }
        }
    }, RequestTree.defaultRequestFlags, null);
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IRequestWatcher(logisticspipes.interfaces.IRequestWatcher) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagList(net.minecraft.nbt.NBTTagList) LinkedLogisticsOrderList(logisticspipes.routing.order.LinkedLogisticsOrderList) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) IResource(logisticspipes.request.resources.IResource)

Example 9 with IResource

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

the class RequestHandler method simulate.

public static void simulate(final EntityPlayer player, final ItemIdentifierStack stack, CoreRoutedPipe pipe) {
    final List<IResource> usedList = new ArrayList<>();
    final List<IResource> missingList = new ArrayList<>();
    RequestTree.simulate(new ItemIdentifierStack(stack), pipe, new RequestLog() {

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

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

        @Override
        public void handleSucessfullRequestOfList(List<IResource> resources, LinkedLogisticsOrderList parts) {
            usedList.addAll(resources);
        }
    });
    MainProxy.sendPacketToPlayer(PacketHandler.getPacket(ComponentList.class).setUsed(usedList).setMissing(missingList), player);
}
Also used : LinkedLogisticsOrderList(logisticspipes.routing.order.LinkedLogisticsOrderList) ArrayList(java.util.ArrayList) ComponentList(logisticspipes.network.packets.orderer.ComponentList) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) IResource(logisticspipes.request.resources.IResource)

Example 10 with IResource

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

the class RequestTree method sendUsedMessage.

public void sendUsedMessage(RequestLog log) {
    Map<IResource, Integer> used = new HashMap<>();
    Map<IResource, Integer> missing = new HashMap<>();
    buildUsedMap(used, missing);
    log.handleSucessfullRequestOfList(RequestTreeNode.shrinkToList(used), new LinkedLogisticsOrderList());
    log.handleMissingItems(RequestTreeNode.shrinkToList(missing));
}
Also used : LinkedLogisticsOrderList(logisticspipes.routing.order.LinkedLogisticsOrderList) HashMap(java.util.HashMap) IResource(logisticspipes.request.resources.IResource)

Aggregations

IResource (logisticspipes.request.resources.IResource)11 LinkedLogisticsOrderList (logisticspipes.routing.order.LinkedLogisticsOrderList)8 ArrayList (java.util.ArrayList)7 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)6 HashMap (java.util.HashMap)5 DictResource (logisticspipes.request.resources.DictResource)5 ItemResource (logisticspipes.request.resources.ItemResource)5 BitSet (java.util.BitSet)3 List (java.util.List)3 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)3 Collections (java.util.Collections)2 EnumSet (java.util.EnumSet)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 PriorityQueue (java.util.PriorityQueue)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 Collectors (java.util.stream.Collectors)2