Search in sources :

Example 11 with ExitRoute

use of logisticspipes.routing.ExitRoute 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 12 with ExitRoute

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

the class RequestRoutingLasersPacket method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    LogisticsTileGenericPipe tile = this.getPipe(player.worldObj);
    if (tile == null) {
        return;
    }
    if (tile.pipe instanceof CoreRoutedPipe) {
        IRouter router = ((CoreRoutedPipe) tile.pipe).getRouter();
        //this is here to allow players to manually trigger a network-wide LSA update
        router.forceLsaUpdate();
        List<List<ExitRoute>> exits = router.getRouteTable();
        HashMap<ForgeDirection, ArrayList<ExitRoute>> routers = new HashMap<>();
        for (List<ExitRoute> exit : exits) {
            if (exit == null) {
                continue;
            }
            for (ExitRoute e : exit) {
                if (!routers.containsKey(e.exitOrientation)) {
                    routers.put(e.exitOrientation, new ArrayList<>());
                }
                if (!routers.get(e.exitOrientation).contains(e)) {
                    routers.get(e.exitOrientation).add(e);
                }
            }
        }
        ArrayList<LaserData> lasers = new ArrayList<>();
        firstPipe = true;
        for (final ForgeDirection dir : routers.keySet()) {
            if (dir == ForgeDirection.UNKNOWN) {
                continue;
            }
            handleRouteInDirection(tile, dir, routers.get(dir), lasers, EnumSet.allOf(PipeRoutingConnectionType.class), new Log() {

                @Override
                void log(String log) {
                    if (LPConstants.DEBUG) {
                        System.out.println(dir.name() + ": " + log);
                    }
                }
            });
        }
        lasers = compressLasers(lasers);
        MainProxy.sendPacketToPlayer(PacketHandler.getPacket(RoutingLaserPacket.class).setLasers(lasers), player);
    }
}
Also used : PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) IRouter(logisticspipes.routing.IRouter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LaserData(logisticspipes.routing.LaserData) ExitRoute(logisticspipes.routing.ExitRoute)

Example 13 with ExitRoute

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

the class ItemAmountPipeSign method spread.

private void spread(Map<ItemIdentifier, Integer> availableItems, BitSet set) {
    // Improve performance by updating a wall of Amount pipe signs all at once
    IRouter router = pipe.getRouter();
    if (set.get(router.getSimpleID()))
        return;
    set.set(router.getSimpleID());
    for (ExitRoute exit : router.getIRoutersByCost()) {
        // Only when the signs are in one wall. To not spread to far.
        if (exit.distanceToDestination > 2)
            break;
        if (!exit.filters.isEmpty())
            continue;
        if (set.get(exit.destination.getSimpleID()))
            continue;
        if (exit.connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && exit.connectionDetails.contains(PipeRoutingConnectionType.canRouteTo)) {
            CoreRoutedPipe cachedPipe = exit.destination.getCachedPipe();
            if (cachedPipe != null) {
                List<Pair<ForgeDirection, IPipeSign>> pipeSigns = cachedPipe.getPipeSigns();
                pipeSigns.stream().filter(signPair -> signPair != null && signPair.getValue2() instanceof ItemAmountPipeSign).forEach(signPair -> ((ItemAmountPipeSign) signPair.getValue2()).updateStats(availableItems, set));
            }
        }
    }
}
Also used : IRouter(logisticspipes.routing.IRouter) Item(net.minecraft.item.Item) MainProxy(logisticspipes.proxy.MainProxy) StringUtils(logisticspipes.utils.string.StringUtils) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) LogisticsRenderPipe(logisticspipes.renderer.LogisticsRenderPipe) GL11(org.lwjgl.opengl.GL11) ItemAmountSignUpdatePacket(logisticspipes.network.packets.pipe.ItemAmountSignUpdatePacket) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NewGuiHandler(logisticspipes.network.NewGuiHandler) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) Side(cpw.mods.fml.relauncher.Side) ItemAmountSignGui(logisticspipes.network.guis.item.ItemAmountSignGui) SideOnly(cpw.mods.fml.relauncher.SideOnly) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) PacketHandler(logisticspipes.network.PacketHandler) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ExitRoute(logisticspipes.routing.ExitRoute) ServerRouter(logisticspipes.routing.ServerRouter) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) ISimpleInventoryEventHandler(logisticspipes.utils.ISimpleInventoryEventHandler) List(java.util.List) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) FontRenderer(net.minecraft.client.gui.FontRenderer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) IInventory(net.minecraft.inventory.IInventory) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Data(lombok.Data) BitSet(java.util.BitSet) IRouter(logisticspipes.routing.IRouter) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute) Pair(logisticspipes.utils.tuples.Pair)

Example 14 with ExitRoute

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

the class ClientViewController method updateList.

public void updateList(RoutingUpdateDebugCanidateList routingUpdateDebugCanidateList) {
    debugWindow.clear();
    ExitRoute[] e = routingUpdateDebugCanidateList.getMsg();
    int i = 0;
    for (ExitRoute exit : e) {
        i++;
        Color color = Color.BLACK;
        if (exit.debug.isNewlyAddedCanidate) {
            color = Color.BLUE;
        }
        debugWindow.showInfo(exit.destination.toString(), color);
        debugWindow.showInfo("\n", color);
        for (int j = 0; j < 2; j++) {
            debugWindow.showInfo("\t", color);
        }
        debugWindow.showInfo(exit.debug.toStringNetwork, color);
        debugWindow.showInfo("\n", color);
        DoubleCoordinates pos = exit.destination.getLPPosition();
        getDebugInformation(pos).routes.add(exit);
        getDebugInformation(pos).positions.add(i);
    }
    listHUD.addAll(HUDPositions.entrySet().stream().map(entry -> new HUDRoutingTableDebugProvider(new HUDRoutingTableGeneralInfo(entry.getValue()), entry.getKey())).collect(Collectors.toList()));
}
Also used : Color(java.awt.Color) ExitRoute(logisticspipes.routing.ExitRoute) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 15 with ExitRoute

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

the class RequestTreeNode method getCrafters.

private static List<Pair<ICraftingTemplate, List<IFilter>>> getCrafters(IResource iRequestType, List<ExitRoute> validDestinations) {
    List<Pair<ICraftingTemplate, List<IFilter>>> crafters = new ArrayList<>(validDestinations.size());
    for (ExitRoute r : validDestinations) {
        CoreRoutedPipe pipe = r.destination.getPipe();
        if (r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
            if (pipe instanceof ICraft) {
                ICraftingTemplate craftable = ((ICraft) pipe).addCrafting(iRequestType);
                if (craftable != null) {
                    for (IFilter filter : r.filters) {
                        if (filter.isBlocked() == filter.isFilteredItem(craftable.getResultItem()) || filter.blockCrafting()) {
                            continue;
                        }
                    }
                    List<IFilter> list = new LinkedList<>();
                    list.addAll(r.filters);
                    crafters.add(new Pair<>(craftable, list));
                }
            }
        }
    }
    //		Collections.sort(crafters,new CraftingTemplate.PairPrioritizer());
    return crafters;
}
Also used : ICraft(logisticspipes.interfaces.routing.ICraft) IFilter(logisticspipes.interfaces.routing.IFilter) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute) LinkedList(java.util.LinkedList) Pair(logisticspipes.utils.tuples.Pair)

Aggregations

ExitRoute (logisticspipes.routing.ExitRoute)30 IRouter (logisticspipes.routing.IRouter)17 ArrayList (java.util.ArrayList)16 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)16 LinkedList (java.util.LinkedList)12 IFilter (logisticspipes.interfaces.routing.IFilter)12 List (java.util.List)11 BitSet (java.util.BitSet)10 PipeRoutingConnectionType (logisticspipes.routing.PipeRoutingConnectionType)8 HashMap (java.util.HashMap)7 Pair (logisticspipes.utils.tuples.Pair)7 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)7 Map (java.util.Map)5 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)5 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)4 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)4 LaserData (logisticspipes.routing.LaserData)3 ServerRouter (logisticspipes.routing.ServerRouter)3 Iterator (java.util.Iterator)2 Entry (java.util.Map.Entry)2