Search in sources :

Example 1 with LogisticsPromise

use of logisticspipes.routing.LogisticsPromise 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 2 with LogisticsPromise

use of logisticspipes.routing.LogisticsPromise in project LogisticsPipes by RS485.

the class PipeLogisticsChassi method registerExtras.

@Override
public void registerExtras(IPromise promise) {
    if (!(promise instanceof LogisticsPromise)) {
        throw new UnsupportedOperationException("Extra has to be an item for a chassis pipe");
    }
    ItemIdentifierStack stack = new ItemIdentifierStack(((LogisticsPromise) promise).item, ((LogisticsPromise) promise).numberOfItems);
    _extras.add(new LogisticsItemOrder(new DictResource(stack, null), null, ResourceType.EXTRA, null));
}
Also used : LogisticsPromise(logisticspipes.routing.LogisticsPromise) DictResource(logisticspipes.request.resources.DictResource) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 3 with LogisticsPromise

use of logisticspipes.routing.LogisticsPromise in project LogisticsPipes by RS485.

the class PipeItemsProviderLogistics method canProvide.

@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filters) {
    if (!isEnabled()) {
        return;
    }
    if (tree.getRequestType() instanceof ItemResource) {
        ItemIdentifier item = ((ItemResource) tree.getRequestType()).getItem();
        for (IFilter filter : filters) {
            if (filter.isBlocked() == filter.isFilteredItem(item.getUndamaged()) || filter.blockProvider()) {
                return;
            }
        }
        // Check the transaction and see if we have helped already
        int canProvide = getAvailableItemCount(item);
        canProvide -= root.getAllPromissesFor(this, item);
        if (canProvide < 1) {
            return;
        }
        LogisticsPromise promise = new LogisticsPromise(item, Math.min(canProvide, tree.getMissingAmount()), this, ResourceType.PROVIDER);
        tree.addPromise(promise);
    } else if (tree.getRequestType() instanceof DictResource) {
        DictResource dict = (DictResource) tree.getRequestType();
        HashMap<ItemIdentifier, Integer> available = new HashMap<>();
        getAllItems(available, filters);
        for (Entry<ItemIdentifier, Integer> item : available.entrySet()) {
            if (!dict.matches(item.getKey(), IResource.MatchSettings.NORMAL)) {
                continue;
            }
            int canProvide = getAvailableItemCount(item.getKey());
            canProvide -= root.getAllPromissesFor(this, item.getKey());
            if (canProvide < 1) {
                continue;
            }
            LogisticsPromise promise = new LogisticsPromise(item.getKey(), Math.min(canProvide, tree.getMissingAmount()), this, ResourceType.PROVIDER);
            tree.addPromise(promise);
            if (tree.getMissingAmount() <= 0) {
                break;
            }
        }
    }
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) Entry(java.util.Map.Entry) IFilter(logisticspipes.interfaces.routing.IFilter) HashMap(java.util.HashMap) LogisticsPromise(logisticspipes.routing.LogisticsPromise) DictResource(logisticspipes.request.resources.DictResource) ItemResource(logisticspipes.request.resources.ItemResource)

Aggregations

DictResource (logisticspipes.request.resources.DictResource)3 LogisticsPromise (logisticspipes.routing.LogisticsPromise)3 Entry (java.util.Map.Entry)2 IFilter (logisticspipes.interfaces.routing.IFilter)2 LogisticsItemOrder (logisticspipes.routing.order.LogisticsItemOrder)2 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)2 Side (cpw.mods.fml.relauncher.Side)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Collectors (java.util.stream.Collectors)1 HUDProviderModule (logisticspipes.gui.hud.modules.HUDProviderModule)1 IClientInformationProvider (logisticspipes.interfaces.IClientInformationProvider)1 IHUDModuleHandler (logisticspipes.interfaces.IHUDModuleHandler)1 IHUDModuleRenderer (logisticspipes.interfaces.IHUDModuleRenderer)1 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)1