Search in sources :

Example 1 with ItemSendMode

use of logisticspipes.pipes.basic.CoreRoutedPipe.ItemSendMode in project LogisticsPipes by RS485.

the class ModuleProvider method sendStack.

// returns -1 on permanently failed, don't try another stack this tick
// returns 0 on "unable to do this delivery"
public int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
    final IPipeServiceProvider service = _service;
    if (service == null)
        return -1;
    ItemIdentifier item = stack.getItem();
    Iterator<Pair<IInventoryUtil, EnumFacing>> iterator = service.getAvailableAdjacent().inventories().stream().flatMap(neighbor -> {
        final IInventoryUtil invUtil = getInventoryUtilWithMode(neighbor);
        if (invUtil == null)
            return Stream.empty();
        return Stream.of(new Pair<>(invUtil, neighbor.getDirection()));
    }).iterator();
    while (iterator.hasNext()) {
        final Pair<IInventoryUtil, EnumFacing> current = iterator.next();
        int available = current.getValue1().itemCount(item);
        if (available == 0) {
            continue;
        }
        int wanted = Math.min(available, stack.getStackSize());
        wanted = Math.min(wanted, maxCount);
        wanted = Math.min(wanted, item.getMaxStackSize());
        IRouter dRtr = SimpleServiceLocator.routerManager.getServerRouter(destination);
        if (dRtr == null) {
            service.getItemOrderManager().sendFailed();
            return 0;
        }
        SinkReply reply = LogisticsManager.canSink(stack.makeNormalStack(), dRtr, null, true, stack.getItem(), null, true, false);
        boolean defersend = false;
        if (reply != null) {
            // some pipes are not aware of the space in the adjacent inventory, so they return null
            if (reply.maxNumberOfItems < wanted) {
                wanted = reply.maxNumberOfItems;
                if (wanted <= 0) {
                    service.getItemOrderManager().deferSend();
                    return 0;
                }
                defersend = true;
            }
        }
        if (!service.canUseEnergy(wanted * neededEnergy())) {
            return -1;
        }
        ItemStack removed = current.getValue1().getMultipleItems(item, wanted);
        if (removed.isEmpty()) {
            continue;
        }
        int sent = removed.getCount();
        service.useEnergy(sent * neededEnergy());
        final IRoutedItem routedItem = service.sendStack(removed, destination, itemSendMode(), info, current.getValue2());
        service.getItemOrderManager().sendSuccessfull(sent, defersend, routedItem);
        return sent;
    }
    service.getItemOrderManager().sendFailed();
    return 0;
}
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) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) EnumFacing(net.minecraft.util.EnumFacing) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IRouter(logisticspipes.routing.IRouter) SinkReply(logisticspipes.utils.SinkReply) ItemStack(net.minecraft.item.ItemStack) Pair(logisticspipes.utils.tuples.Pair)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)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 IHUDModuleRenderer (logisticspipes.interfaces.IHUDModuleRenderer)1 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)1 ILegacyActiveModule (logisticspipes.interfaces.ILegacyActiveModule)1 IModuleInventoryReceive (logisticspipes.interfaces.IModuleInventoryReceive)1 IModuleWatchReciver (logisticspipes.interfaces.IModuleWatchReciver)1 IPipeServiceProvider (logisticspipes.interfaces.IPipeServiceProvider)1