Search in sources :

Example 1 with IProvideItems

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

the class LogisticsManager method getAmountFor.

@Override
public int getAmountFor(ItemIdentifier itemType, List<ExitRoute> validDestinations) {
    // TODO: Replace this entire function wiht a fetch from the pre-built arrays (path incoming later)
    List<Map<ItemIdentifier, Integer>> items = new ArrayList<>(ServerRouter.getBiggestSimpleID());
    for (int i = 0; i < ServerRouter.getBiggestSimpleID(); i++) {
        items.add(new HashMap<>());
    }
    BitSet used = new BitSet(ServerRouter.getBiggestSimpleID());
    outer: for (ExitRoute r : validDestinations) {
        if (r == null) {
            continue;
        }
        if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
            continue;
        }
        if (!(r.destination.getPipe() instanceof IProvideItems)) {
            continue;
        }
        for (IFilter filter : r.filters) {
            if (filter.blockProvider()) {
                continue outer;
            }
        }
        IProvideItems provider = (IProvideItems) r.destination.getPipe();
        provider.getAllItems(items.get(r.destination.getSimpleID()), r.filters);
        used.set(r.destination.getSimpleID(), true);
    }
    // TODO: Fix this doubly nested list
    int amount = 0;
    for (Map<ItemIdentifier, Integer> allItems : items) {
        for (Entry<ItemIdentifier, Integer> item : allItems.entrySet()) {
            if (item.getKey().equals(itemType)) {
                amount += item.getValue();
            }
        }
    }
    return amount;
}
Also used : ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IFilter(logisticspipes.interfaces.routing.IFilter) ExitRoute(logisticspipes.routing.ExitRoute) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with IProvideItems

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

the class LogisticsManager method getAvailableItems.

/**
 * @param validDestinations
 *            a list of ExitRoute of valid destinations.
 * @return HashMap with ItemIdentifier and Integer item count of available
 *         items.
 */
@Override
public HashMap<ItemIdentifier, Integer> getAvailableItems(List<ExitRoute> validDestinations) {
    // TODO: Replace this entire function wiht a fetch from the pre-built arrays (path incoming later)
    List<Map<ItemIdentifier, Integer>> items = new ArrayList<>(ServerRouter.getBiggestSimpleID());
    for (int i = 0; i < ServerRouter.getBiggestSimpleID(); i++) {
        items.add(new HashMap<>());
    }
    BitSet used = new BitSet(ServerRouter.getBiggestSimpleID());
    outer: for (ExitRoute r : validDestinations) {
        if (r == null) {
            continue;
        }
        if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
            continue;
        }
        if (!(r.destination.getPipe() instanceof IProvideItems)) {
            continue;
        }
        for (IFilter filter : r.filters) {
            if (filter.blockProvider()) {
                continue outer;
            }
        }
        IProvideItems provider = (IProvideItems) r.destination.getPipe();
        provider.getAllItems(items.get(r.destination.getSimpleID()), r.filters);
        used.set(r.destination.getSimpleID(), true);
    }
    // TODO: Fix this doubly nested list
    HashMap<ItemIdentifier, Integer> allAvailableItems = new HashMap<>();
    for (Map<ItemIdentifier, Integer> allItems : items) {
        for (Entry<ItemIdentifier, Integer> item : allItems.entrySet()) {
            allAvailableItems.merge(item.getKey(), item.getValue(), Integer::sum);
        }
    }
    return allAvailableItems;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IFilter(logisticspipes.interfaces.routing.IFilter) ExitRoute(logisticspipes.routing.ExitRoute) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with IProvideItems

use of logisticspipes.interfaces.routing.IProvideItems 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) {
        possible.addAll(inventoriesWithMode().map(IInventoryUtil::getItemsAndCount).flatMap(inventory -> inventory.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) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) SneakyModuleDirectionUpdate(logisticspipes.network.packets.modules.SneakyModuleDirectionUpdate) 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) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) NewGuiHandler(logisticspipes.network.NewGuiHandler) 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) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) SneakyDirection(network.rs485.logisticspipes.module.SneakyDirection) ProviderModuleInHand(logisticspipes.network.guis.module.inhand.ProviderModuleInHand) Objects(java.util.Objects) NullableEnumProperty(network.rs485.logisticspipes.property.NullableEnumProperty) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) Stream(java.util.stream.Stream) IFilter(logisticspipes.interfaces.routing.IFilter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BooleanProperty(network.rs485.logisticspipes.property.BooleanProperty) Pair(logisticspipes.utils.tuples.Pair) IHUDModuleHandler(logisticspipes.interfaces.IHUDModuleHandler) Gui(network.rs485.logisticspipes.module.Gui) EnumProperty(network.rs485.logisticspipes.property.EnumProperty) Property(network.rs485.logisticspipes.property.Property) ProviderMode(network.rs485.logisticspipes.inventory.ProviderMode) ItemResource(logisticspipes.request.resources.ItemResource) IItemIdentifierInventory(network.rs485.logisticspipes.inventory.IItemIdentifierInventory) ModuleCoordinatesGuiProvider(logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider) LogisticsOrder(logisticspipes.routing.order.LogisticsOrder) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IClientInformationProvider(logisticspipes.interfaces.IClientInformationProvider) InventoryProperty(network.rs485.logisticspipes.property.InventoryProperty) ImmutableList(com.google.common.collect.ImmutableList) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) ProviderModuleGuiProvider(logisticspipes.network.guis.module.inpipe.ProviderModuleGuiProvider) IModuleWatchReciver(logisticspipes.interfaces.IModuleWatchReciver) Nonnull(javax.annotation.Nonnull) Iterator(java.util.Iterator) IHUDModuleRenderer(logisticspipes.interfaces.IHUDModuleRenderer) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) EnumFacing(net.minecraft.util.EnumFacing) LogisticsPromise(logisticspipes.routing.LogisticsPromise) ItemSendMode(logisticspipes.pipes.basic.CoreRoutedPipe.ItemSendMode) RequestTree(logisticspipes.request.RequestTree) HUDProviderModule(logisticspipes.gui.hud.modules.HUDProviderModule) 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) ILegacyActiveModule(logisticspipes.interfaces.ILegacyActiveModule) TileEntity(net.minecraft.tileentity.TileEntity) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) ArrayList(java.util.ArrayList) DictResource(logisticspipes.request.resources.DictResource) LogisticsPromise(logisticspipes.routing.LogisticsPromise) ItemResource(logisticspipes.request.resources.ItemResource)

Aggregations

ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 IFilter (logisticspipes.interfaces.routing.IFilter)3 IProvideItems (logisticspipes.interfaces.routing.IProvideItems)3 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)3 BitSet (java.util.BitSet)2 HashMap (java.util.HashMap)2 ExitRoute (logisticspipes.routing.ExitRoute)2 ImmutableList (com.google.common.collect.ImmutableList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Objects (java.util.Objects)1 TreeMap (java.util.TreeMap)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Nonnull (javax.annotation.Nonnull)1 HUDProviderModule (logisticspipes.gui.hud.modules.HUDProviderModule)1 IClientInformationProvider (logisticspipes.interfaces.IClientInformationProvider)1 IHUDModuleHandler (logisticspipes.interfaces.IHUDModuleHandler)1