Search in sources :

Example 11 with IRoutedItem

use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.

the class PipeTransportLogistics method handleTileReachedServer_internal.

protected final void handleTileReachedServer_internal(LPTravelingItemServer arrivingItem, TileEntity tile, ForgeDirection dir) {
    if (isRouted && getPipe().container.tilePart.getBCPipePluggable(dir) != null && getPipe().container.tilePart.getBCPipePluggable(dir).isAcceptingItems(arrivingItem)) {
        LPTravelingItemServer remainingItem = getPipe().container.tilePart.getBCPipePluggable(dir).handleItem(arrivingItem);
        if (remainingItem != null) {
            getRoutedPipe().getRouter().update(true, getRoutedPipe());
            this.injectItem(remainingItem, dir);
        }
        return;
    }
    if (getPipe() instanceof PipeItemsFluidSupplier) {
        ((PipeItemsFluidSupplier) getPipe()).endReached(arrivingItem, tile);
        if (arrivingItem.getItemIdentifierStack().getStackSize() <= 0) {
            return;
        }
    }
    markChunkModified(tile);
    if (MainProxy.isServer(getWorld()) && arrivingItem.getInfo() != null && arrivingItem.getArrived() && isRouted) {
        getRoutedPipe().notifyOfItemArival(arrivingItem.getInfo());
    }
    if (getPipe() instanceof FluidRoutedPipe) {
        if (((FluidRoutedPipe) getPipe()).endReached(arrivingItem, tile)) {
            return;
        }
    }
    boolean isSpecialConnectionInformationTransition = false;
    if (MainProxy.isServer(getWorld())) {
        if (SimpleServiceLocator.specialtileconnection.needsInformationTransition(tile)) {
            isSpecialConnectionInformationTransition = true;
            SimpleServiceLocator.specialtileconnection.transmit(tile, arrivingItem);
        }
    }
    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(tile)) {
        if (passToNextPipe(arrivingItem, tile)) {
            return;
        }
    } else if (tile instanceof IInventory && isRouted) {
        getRoutedPipe().getCacheHolder().trigger(CacheTypes.Inventory);
        // items.scheduleRemoval(arrivingItem);
        if (MainProxy.isServer(getWorld())) {
            // destroy the item on exit if it isn't exitable
            if (!isSpecialConnectionInformationTransition && !isItemExitable(arrivingItem.getItemIdentifierStack())) {
                return;
            }
            // last chance for chassi to back out
            if (arrivingItem != null) {
                if (arrivingItem.getTransportMode() != TransportMode.Active && !getRoutedPipe().getTransportLayer().stillWantItem(arrivingItem)) {
                    reverseItem(arrivingItem);
                    return;
                }
            }
            ISlotUpgradeManager slotManager;
            {
                ModulePositionType slot = null;
                int positionInt = -1;
                if (arrivingItem.getInfo().targetInfo instanceof ChassiTargetInformation) {
                    positionInt = ((ChassiTargetInformation) arrivingItem.getInfo().targetInfo).getModuleSlot();
                    slot = ModulePositionType.SLOT;
                } else if (LPConstants.DEBUG && container.pipe instanceof PipeLogisticsChassi) {
                    System.out.println(arrivingItem);
                    new RuntimeException("[ItemInsertion] Information weren't ment for a chassi pipe").printStackTrace();
                }
                slotManager = getRoutedPipe().getUpgradeManager(slot, positionInt);
            }
            boolean tookSome = false;
            if (arrivingItem.getAdditionalTargetInformation() instanceof ITargetSlotInformation) {
                ITargetSlotInformation information = (ITargetSlotInformation) arrivingItem.getAdditionalTargetInformation();
                IInventory inv = (IInventory) tile;
                if (inv instanceof ISidedInventory) {
                    inv = new SidedInventoryMinecraftAdapter((ISidedInventory) inv, ForgeDirection.UNKNOWN, false);
                }
                IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv);
                if (util instanceof ISpecialInsertion) {
                    int slot = information.getTargetSlot();
                    int amount = information.getAmount();
                    if (util.getSizeInventory() > slot) {
                        ItemStack content = util.getStackInSlot(slot);
                        ItemStack toAdd = arrivingItem.getItemIdentifierStack().makeNormalStack();
                        toAdd.stackSize = Math.min(toAdd.stackSize, Math.max(0, amount - (content != null ? content.stackSize : 0)));
                        if (toAdd.stackSize > 0) {
                            if (util.getSizeInventory() > slot) {
                                int added = ((ISpecialInsertion) util).addToSlot(toAdd, slot);
                                arrivingItem.getItemIdentifierStack().lowerStackSize(added);
                                if (added > 0) {
                                    tookSome = true;
                                }
                            }
                        }
                    }
                    if (information.isLimited()) {
                        if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                            reverseItem(arrivingItem);
                        }
                        return;
                    }
                }
            }
            // sneaky insertion
            if (!getRoutedPipe().getUpgradeManager().hasCombinedSneakyUpgrade() || slotManager.hasOwnSneakyUpgrade()) {
                ForgeDirection insertion = arrivingItem.output.getOpposite();
                if (slotManager.hasSneakyUpgrade()) {
                    insertion = slotManager.getSneakyOrientation();
                }
                ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
                arrivingItem.getItemIdentifierStack().lowerStackSize(added.stackSize);
                if (added.stackSize > 0 && arrivingItem instanceof IRoutedItem) {
                    tookSome = true;
                    arrivingItem.setBufferCounter(0);
                }
                ItemRoutingInformation info;
                if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                    // we have some leftovers, we are splitting the stack, we need to clone the info
                    info = arrivingItem.getInfo().clone();
                    // For InvSysCon
                    info.getItem().setStackSize(added.stackSize);
                    insertedItemStack(info, tile);
                } else {
                    info = arrivingItem.getInfo();
                    info.getItem().setStackSize(added.stackSize);
                    // For InvSysCon
                    insertedItemStack(info, tile);
                    // every item has been inserted.
                    return;
                }
            } else {
                ForgeDirection[] dirs = getRoutedPipe().getUpgradeManager().getCombinedSneakyOrientation();
                for (ForgeDirection insertion : dirs) {
                    if (insertion == null) {
                        continue;
                    }
                    ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
                    arrivingItem.getItemIdentifierStack().lowerStackSize(added.stackSize);
                    if (added.stackSize > 0) {
                        tookSome = true;
                        arrivingItem.setBufferCounter(0);
                    }
                    ItemRoutingInformation info;
                    if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                        // we have some leftovers, we are splitting the stack, we need to clone the info
                        info = arrivingItem.getInfo().clone();
                        // For InvSysCon
                        info.getItem().setStackSize(added.stackSize);
                        insertedItemStack(info, tile);
                    } else {
                        info = arrivingItem.getInfo();
                        info.getItem().setStackSize(added.stackSize);
                        // For InvSysCon
                        insertedItemStack(info, tile);
                        // every item has been inserted.
                        return;
                    }
                }
            }
            if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                reverseItem(arrivingItem);
            }
        }
        // the item is handled
        return;
    }
    // end of insert into IInventory
    dropItem(arrivingItem);
}
Also used : IInventory(net.minecraft.inventory.IInventory) ITargetSlotInformation(logisticspipes.interfaces.routing.ITargetSlotInformation) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) FluidRoutedPipe(logisticspipes.pipes.basic.fluid.FluidRoutedPipe) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ModulePositionType(logisticspipes.modules.abstractmodules.LogisticsModule.ModulePositionType) ISidedInventory(net.minecraft.inventory.ISidedInventory) PipeItemsFluidSupplier(logisticspipes.pipes.PipeItemsFluidSupplier) ISpecialInsertion(logisticspipes.interfaces.ISpecialInsertion) ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation) PipeLogisticsChassi(logisticspipes.pipes.PipeLogisticsChassi) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Example 12 with IRoutedItem

use of logisticspipes.logisticspipes.IRoutedItem 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)

Example 13 with IRoutedItem

use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.

the class CoreRoutedPipe method addStatusInformation.

@Override
public void addStatusInformation(List<StatusEntry> status) {
    StatusEntry entry = new StatusEntry();
    entry.name = "Send Queue";
    entry.subEntry = new ArrayList<>();
    for (Triplet<IRoutedItem, EnumFacing, ItemSendMode> part : _sendQueue) {
        StatusEntry subEntry = new StatusEntry();
        subEntry.name = part.toString();
        entry.subEntry.add(subEntry);
    }
    status.add(entry);
    entry = new StatusEntry();
    entry.name = "In Transit To Me";
    entry.subEntry = new ArrayList<>();
    for (ItemRoutingInformation part : _inTransitToMe) {
        StatusEntry subEntry = new StatusEntry();
        subEntry.name = part.toString();
        entry.subEntry.add(subEntry);
    }
    status.add(entry);
}
Also used : IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) EnumFacing(net.minecraft.util.EnumFacing) StatusEntry(logisticspipes.pipes.basic.debug.StatusEntry)

Example 14 with IRoutedItem

use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.

the class CoreRoutedPipe method sendStack.

@Override
public IRoutedItem sendStack(@Nonnull ItemStack stack, int destination, ItemSendMode mode, IAdditionalTargetInformation info, EnumFacing direction) {
    IRoutedItem itemToSend = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
    itemToSend.setDestination(destination);
    itemToSend.setTransportMode(TransportMode.Active);
    itemToSend.setAdditionalTargetInformation(info);
    queueRoutedItem(itemToSend, direction, mode);
    return itemToSend;
}
Also used : IRoutedItem(logisticspipes.logisticspipes.IRoutedItem)

Example 15 with IRoutedItem

use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.

the class PipeItemsInvSysConnector method sendStack.

public void sendStack(ItemRoutingInformation info, EnumFacing dir) {
    IRoutedItem itemToSend = SimpleServiceLocator.routedItemHelper.createNewTravelItem(info);
    super.queueRoutedItem(itemToSend, dir);
    spawnParticle(Particles.OrangeParticle, 4);
}
Also used : IRoutedItem(logisticspipes.logisticspipes.IRoutedItem)

Aggregations

IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)17 EnumFacing (net.minecraft.util.EnumFacing)7 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)5 Pair (logisticspipes.utils.tuples.Pair)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 List (java.util.List)4 Map (java.util.Map)4 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)4 IAdditionalTargetInformation (logisticspipes.interfaces.routing.IAdditionalTargetInformation)4 IFilter (logisticspipes.interfaces.routing.IFilter)4 Nonnull (javax.annotation.Nonnull)3 IRequestItems (logisticspipes.interfaces.routing.IRequestItems)3 LogisticsManager (logisticspipes.logistics.LogisticsManager)3 TransportMode (logisticspipes.logisticspipes.IRoutedItem.TransportMode)3 PacketHandler (logisticspipes.network.PacketHandler)3 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)3 RequestTree (logisticspipes.request.RequestTree)3 RequestTreeNode (logisticspipes.request.RequestTreeNode)3 ResourceType (logisticspipes.routing.order.IOrderInfoProvider.ResourceType)3