Search in sources :

Example 6 with IFilter

use of logisticspipes.interfaces.routing.IFilter in project LogisticsPipes by RS485.

the class ModuleProvider method canProvide.

@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filters) {
    List<ItemIdentifier> possible = new ArrayList<>();
    if (tree.getRequestType() instanceof ItemResource) {
        possible.add(((ItemResource) tree.getRequestType()).getItem());
    } else if (tree.getRequestType() instanceof DictResource) {
        IInventoryUtil inv = _service.getPointedInventory(_extractionMode, true);
        if (inv != null) {
            Map<ItemIdentifier, Integer> currentInv = inv.getItemsAndCount();
            possible.addAll(currentInv.keySet().stream().filter(item -> tree.getRequestType().matches(item, IResource.MatchSettings.NORMAL)).collect(Collectors.toList()));
        }
    }
    for (ItemIdentifier item : possible) {
        int canProvide = getAvailableItemCount(item);
        canProvide -= root.getAllPromissesFor((IProvideItems) _service, item);
        canProvide = Math.min(canProvide, tree.getMissingAmount());
        if (canProvide < 1) {
            return;
        }
        LogisticsPromise promise = new LogisticsPromise(item, canProvide, (IProvideItems) _service, ResourceType.PROVIDER);
        tree.addPromise(promise);
    }
}
Also used : ModuleInHandGuiProvider(logisticspipes.network.abstractguis.ModuleInHandGuiProvider) IRouter(logisticspipes.routing.IRouter) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Particles(logisticspipes.pipefxhandlers.Particles) CCType(logisticspipes.proxy.computers.interfaces.CCType) MainProxy(logisticspipes.proxy.MainProxy) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) SinkReply(logisticspipes.utils.SinkReply) HUDStopModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStopModuleWatchingPacket) Map(java.util.Map) CCCommand(logisticspipes.proxy.computers.interfaces.CCCommand) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) IIconRegister(net.minecraft.client.renderer.texture.IIconRegister) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) NewGuiHandler(logisticspipes.network.NewGuiHandler) Side(cpw.mods.fml.relauncher.Side) SideOnly(cpw.mods.fml.relauncher.SideOnly) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) LogisticsManager(logisticspipes.logistics.LogisticsManager) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) IModuleInventoryReceive(logisticspipes.interfaces.IModuleInventoryReceive) PacketHandler(logisticspipes.network.PacketHandler) RequestTreeNode(logisticspipes.request.RequestTreeNode) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) ProviderModuleInHand(logisticspipes.network.guis.module.inhand.ProviderModuleInHand) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Entry(java.util.Map.Entry) IHUDModuleHandler(logisticspipes.interfaces.IHUDModuleHandler) LogisticsSneakyDirectionModule(logisticspipes.modules.abstractmodules.LogisticsSneakyDirectionModule) ItemResource(logisticspipes.request.resources.ItemResource) ModuleCoordinatesGuiProvider(logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider) LogisticsOrder(logisticspipes.routing.order.LogisticsOrder) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IClientInformationProvider(logisticspipes.interfaces.IClientInformationProvider) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) ProviderModuleGuiProvider(logisticspipes.network.guis.module.inpipe.ProviderModuleGuiProvider) IModuleWatchReciver(logisticspipes.interfaces.IModuleWatchReciver) ExtractionMode(logisticspipes.logisticspipes.ExtractionMode) ExtractorModuleMode(logisticspipes.network.packets.modules.ExtractorModuleMode) IHUDModuleRenderer(logisticspipes.interfaces.IHUDModuleRenderer) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) LogisticsPromise(logisticspipes.routing.LogisticsPromise) ItemSendMode(logisticspipes.pipes.basic.CoreRoutedPipe.ItemSendMode) RequestTree(logisticspipes.request.RequestTree) HUDProviderModule(logisticspipes.gui.hud.modules.HUDProviderModule) IIcon(net.minecraft.util.IIcon) HUDStartModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStartModuleWatchingPacket) IResource(logisticspipes.request.resources.IResource) ModuleInventory(logisticspipes.network.packets.module.ModuleInventory) TreeMap(java.util.TreeMap) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) IInventory(net.minecraft.inventory.IInventory) ILegacyActiveModule(logisticspipes.interfaces.ILegacyActiveModule) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ArrayList(java.util.ArrayList) DictResource(logisticspipes.request.resources.DictResource) LogisticsPromise(logisticspipes.routing.LogisticsPromise) ItemResource(logisticspipes.request.resources.ItemResource) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 7 with IFilter

use of logisticspipes.interfaces.routing.IFilter in project LogisticsPipes by RS485.

the class LogisticsManager method getBestReply.

private Triplet<Integer, SinkReply, List<IFilter>> getBestReply(ItemIdentifier stack, IRouter sourceRouter, List<ExitRoute> validDestinations, boolean excludeSource, List<Integer> jamList, Triplet<Integer, SinkReply, List<IFilter>> result, boolean allowDefault) {
    if (result == null) {
        result = new Triplet<>(null, null, null);
    }
    outer: for (ExitRoute candidateRouter : validDestinations) {
        if (excludeSource) {
            if (candidateRouter.destination.getId().equals(sourceRouter.getId())) {
                continue;
            }
        }
        if (jamList.contains(candidateRouter.destination.getSimpleID())) {
            continue;
        }
        if (!candidateRouter.containsFlag(PipeRoutingConnectionType.canRouteTo)) {
            continue;
        }
        for (IFilter filter : candidateRouter.filters) {
            if (filter.blockRouting() || (filter.isBlocked() == filter.isFilteredItem(stack))) {
                continue outer;
            }
        }
        SinkReply reply = LogisticsManager.canSink(candidateRouter.destination, sourceRouter, excludeSource, stack, result.getValue2(), false, allowDefault);
        if (reply == null) {
            continue;
        }
        if (result.getValue1() == null) {
            result.setValue1(candidateRouter.destination.getSimpleID());
            result.setValue2(reply);
            List<IFilter> list = new LinkedList<>();
            result.setValue3(list);
            continue;
        }
        if (reply.fixedPriority.ordinal() > result.getValue2().fixedPriority.ordinal()) {
            result.setValue1(candidateRouter.destination.getSimpleID());
            result.setValue2(reply);
            List<IFilter> list = new LinkedList<>();
            result.setValue3(list);
            continue;
        }
        if (reply.fixedPriority == result.getValue2().fixedPriority && reply.customPriority > result.getValue2().customPriority) {
            result.setValue1(candidateRouter.destination.getSimpleID());
            result.setValue2(reply);
            List<IFilter> list = new LinkedList<>();
            result.setValue3(list);
            continue;
        }
    }
    if (result.getValue1() != null) {
        CoreRoutedPipe pipe = SimpleServiceLocator.routerManager.getRouterUnsafe(result.getValue1(), false).getPipe();
        pipe.useEnergy(result.getValue2().energyUse);
        pipe.spawnParticle(Particles.BlueParticle, 10);
    }
    return result;
}
Also used : IFilter(logisticspipes.interfaces.routing.IFilter) SinkReply(logisticspipes.utils.SinkReply) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExitRoute(logisticspipes.routing.ExitRoute)

Example 8 with IFilter

use of logisticspipes.interfaces.routing.IFilter in project LogisticsPipes by RS485.

the class LogisticsManager method getCraftableItems.

/**
	 * @param validDestinations
	 *            a List of ExitRoute of valid destinations.
	 * @return LinkedList with ItemIdentifier
	 */
@Override
public LinkedList<ItemIdentifier> getCraftableItems(List<ExitRoute> validDestinations) {
    LinkedList<ItemIdentifier> craftableItems = new LinkedList<>();
    BitSet used = new BitSet(ServerRouter.getBiggestSimpleID());
    outer: for (ExitRoute r : validDestinations) {
        if (r == null) {
            continue;
        }
        if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
            continue;
        }
        if (used.get(r.destination.getSimpleID())) {
            continue;
        }
        if (!(r.destination.getPipe() instanceof ICraftItems)) {
            continue;
        }
        for (IFilter filter : r.filters) {
            if (filter.blockCrafting()) {
                continue outer;
            }
        }
        ICraftItems crafter = (ICraftItems) r.destination.getPipe();
        List<ItemIdentifierStack> craftedItems = crafter.getCraftedItems();
        if (craftedItems != null) {
            outer2: for (ItemIdentifierStack craftedItem : craftedItems) {
                if (craftedItem != null && !craftableItems.contains(craftedItem.getItem())) {
                    for (IFilter filter : r.filters) {
                        if (filter.isBlocked() == filter.isFilteredItem(craftedItem.getItem())) {
                            continue outer2;
                        }
                    }
                    craftableItems.add(craftedItem.getItem());
                }
            }
        }
        used.set(r.destination.getSimpleID(), true);
    }
    return craftableItems;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IFilter(logisticspipes.interfaces.routing.IFilter) BitSet(java.util.BitSet) ICraftItems(logisticspipes.interfaces.routing.ICraftItems) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExitRoute(logisticspipes.routing.ExitRoute) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) LinkedList(java.util.LinkedList)

Example 9 with IFilter

use of logisticspipes.interfaces.routing.IFilter in project LogisticsPipes by RS485.

the class ModuleCCBasedQuickSort method handle.

private boolean handle(IInventoryUtil invUtil, int slot, List<CCSinkResponder> list) {
    if (list.isEmpty()) {
        return false;
    }
    ItemIdentifier ident = list.get(0).getStack().getItem();
    ItemStack stack = invUtil.getStackInSlot(slot);
    if (stack == null || !ItemIdentifier.get(stack).equals(ident)) {
        return false;
    }
    final IRouter source = _service.getRouter();
    List<Triplet<Integer, Double, CCSinkResponder>> posibilities = new ArrayList<>();
    for (CCSinkResponder sink : list) {
        if (!sink.isDone()) {
            continue;
        }
        if (sink.getCanSink() < 1) {
            continue;
        }
        IRouter r = SimpleServiceLocator.routerManager.getRouter(sink.getRouterId());
        if (r == null) {
            continue;
        }
        List<ExitRoute> ways = source.getDistanceTo(r);
        double minDistance = Double.MAX_VALUE;
        outer: for (ExitRoute route : ways) {
            for (IFilter filter : route.filters) {
                if (filter.blockRouting() || filter.isFilteredItem(ident) == filter.isBlocked()) {
                    continue outer;
                }
            }
            minDistance = Math.min(route.distanceToDestination, minDistance);
        }
        if (minDistance != Integer.MAX_VALUE) {
            posibilities.add(new Triplet<>(sink.getPriority(), minDistance, sink));
        }
    }
    if (posibilities.isEmpty()) {
        return false;
    }
    Collections.sort(posibilities, (o1, o2) -> {
        int c = o2.getValue1() - o1.getValue1();
        if (c != 0) {
            return c;
        }
        double e = o1.getValue2() - o2.getValue2();
        return e < 0 ? -1 : 1;
    });
    boolean sended = false;
    for (Triplet<Integer, Double, CCSinkResponder> triple : posibilities) {
        CCSinkResponder sink = triple.getValue3();
        if (sink.getCanSink() < 0) {
            continue;
        }
        stack = invUtil.getStackInSlot(slot);
        if (stack == null || stack.stackSize <= 0) {
            continue;
        }
        int amount = Math.min(stack.stackSize, sink.getCanSink());
        ItemStack extracted = invUtil.decrStackSize(slot, amount);
        _service.sendStack(extracted, sink.getRouterId(), ItemSendMode.Fast, null);
        sended = true;
    }
    return sended;
}
Also used : Triplet(logisticspipes.utils.tuples.Triplet) ArrayList(java.util.ArrayList) CCSinkResponder(logisticspipes.proxy.computers.objects.CCSinkResponder) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) ItemStack(net.minecraft.item.ItemStack) ExitRoute(logisticspipes.routing.ExitRoute)

Example 10 with IFilter

use of logisticspipes.interfaces.routing.IFilter in project LogisticsPipes by RS485.

the class PipeItemsProviderLogistics method getAllItems.

@Override
public void getAllItems(Map<ItemIdentifier, Integer> items, List<IFilter> filters) {
    if (!isEnabled()) {
        return;
    }
    HashMap<ItemIdentifier, Integer> addedItems = new HashMap<>();
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
    //@formatter:off
    Iterator<Map<ItemIdentifier, Integer>> iterator = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).filter(adjacent -> !SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> getAdaptedInventoryUtil(adjacent).getItemsAndCount()).iterator();
    outer: while (iterator.hasNext()) {
        Iterator<Entry<ItemIdentifier, Integer>> entryIterator = iterator.next().entrySet().stream().filter(currentItem -> !items.containsKey(currentItem.getKey())).filter(currentItem -> !hasFilter() || (!isExcludeFilter() || !itemIsFiltered(currentItem.getKey())) && (isExcludeFilter() || itemIsFiltered(currentItem.getKey()))).iterator();
        while (entryIterator.hasNext()) {
            Entry<ItemIdentifier, Integer> next = entryIterator.next();
            for (IFilter filter : filters) {
                if (filter.isBlocked() == filter.isFilteredItem(next.getKey().getUndamaged()) || filter.blockProvider()) {
                    continue outer;
                }
            }
            Integer addedAmount = addedItems.get(next.getKey());
            if (addedAmount == null) {
                addedItems.put(next.getKey(), next.getValue());
            } else {
                addedItems.put(next.getKey(), addedAmount + next.getValue());
            }
        }
    }
    // reduce what has been reserved, add.
    for (Entry<ItemIdentifier, Integer> item : addedItems.entrySet()) {
        int remaining = item.getValue() - _orderManager.totalItemsCountInOrders(item.getKey());
        if (remaining < 1) {
            continue;
        }
        items.put(item.getKey(), remaining);
    }
}
Also used : IRouter(logisticspipes.routing.IRouter) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Textures(logisticspipes.textures.Textures) Item(net.minecraft.item.Item) LogisticsPipes(logisticspipes.LogisticsPipes) ProviderPipeInclude(logisticspipes.network.packets.modules.ProviderPipeInclude) Particles(logisticspipes.pipefxhandlers.Particles) ChestContent(logisticspipes.network.packets.hud.ChestContent) MainProxy(logisticspipes.proxy.MainProxy) IHeadUpDisplayRenderer(logisticspipes.interfaces.IHeadUpDisplayRenderer) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) HUDStartWatchingPacket(logisticspipes.network.packets.hud.HUDStartWatchingPacket) SinkReply(logisticspipes.utils.SinkReply) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) Map(java.util.Map) ModuleProvider(logisticspipes.modules.ModuleProvider) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChangeListener(logisticspipes.interfaces.IChangeListener) HUDStopWatchingPacket(logisticspipes.network.packets.hud.HUDStopWatchingPacket) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) LogisticsManager(logisticspipes.logistics.LogisticsManager) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) Set(java.util.Set) PacketHandler(logisticspipes.network.PacketHandler) RequestTreeNode(logisticspipes.request.RequestTreeNode) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IChestContentReceiver(logisticspipes.interfaces.IChestContentReceiver) IFilter(logisticspipes.interfaces.routing.IFilter) OrdererManagerContent(logisticspipes.network.packets.orderer.OrdererManagerContent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) GuiIDs(logisticspipes.network.GuiIDs) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ItemResource(logisticspipes.request.resources.ItemResource) LogisticsOrder(logisticspipes.routing.order.LogisticsOrder) HashMap(java.util.HashMap) HUDProvider(logisticspipes.gui.hud.HUDProvider) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) ExtractionMode(logisticspipes.logisticspipes.ExtractionMode) LogisticsItemOrderManager(logisticspipes.routing.order.LogisticsItemOrderManager) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) LogisticsPromise(logisticspipes.routing.LogisticsPromise) TextureType(logisticspipes.textures.Textures.TextureType) RequestTree(logisticspipes.request.RequestTree) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) IResource(logisticspipes.request.resources.IResource) TreeMap(java.util.TreeMap) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ProviderPipeMode(logisticspipes.network.packets.modules.ProviderPipeMode) IInventory(net.minecraft.inventory.IInventory) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IOrderManagerContentReceiver(logisticspipes.interfaces.IOrderManagerContentReceiver) IInventory(net.minecraft.inventory.IInventory) HashMap(java.util.HashMap) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) Entry(java.util.Map.Entry) IFilter(logisticspipes.interfaces.routing.IFilter) Iterator(java.util.Iterator) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

IFilter (logisticspipes.interfaces.routing.IFilter)21 ArrayList (java.util.ArrayList)13 ExitRoute (logisticspipes.routing.ExitRoute)12 LinkedList (java.util.LinkedList)9 IRouter (logisticspipes.routing.IRouter)9 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)9 List (java.util.List)8 BitSet (java.util.BitSet)7 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Entry (java.util.Map.Entry)6 Pair (logisticspipes.utils.tuples.Pair)6 DictResource (logisticspipes.request.resources.DictResource)5 IResource (logisticspipes.request.resources.IResource)5 Iterator (java.util.Iterator)4 Collectors (java.util.stream.Collectors)4 IProvideItems (logisticspipes.interfaces.routing.IProvideItems)4 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)4 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)4