Search in sources :

Example 16 with ExitRoute

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

the class HUDRoutingTableGeneralInfo method renderHeadUpDisplay.

@Override
public void renderHeadUpDisplay(double distance, boolean day, boolean shifted, Minecraft mc, IHUDConfig config) {
    if (route.isNew) {
        line = -65;
    } else {
        line = -75;
    }
    GL11.glColor4b((byte) 127, (byte) 127, (byte) 127, (byte) 64);
    GuiGraphics.drawGuiBackGround(mc, -70, -80, 70, 80, 0, false);
    GL11.glTranslatef(0.0F, 0.0F, -0.0005F);
    super.renderHeadUpDisplay(distance, day, shifted, mc, config);
    GL11.glTranslatef(0.0F, 0.0F, -0.0005F);
    write("Routing Update in: ", mc);
    write(route.positions.toString(), mc);
    if (route.closedSet != null) {
        int left = -55;
        for (PipeRoutingConnectionType flag : PipeRoutingConnectionType.values) {
            if (route.closedSet.contains(flag)) {
                mc.fontRenderer.drawString("+", left, line, getColorForFlag(flag));
                left += mc.fontRenderer.getStringWidth("+");
            } else {
                mc.fontRenderer.drawString("-", left, line, getColorForFlag(flag));
                left += mc.fontRenderer.getStringWidth("-");
            }
        }
        line += 10;
    }
    if (route.routes != null) {
        for (ExitRoute exit : route.routes) {
            mc.fontRenderer.drawString("Possible: ", -55, line, 0xffffff);
            int left = -55 + mc.fontRenderer.getStringWidth("Possible: ");
            for (PipeRoutingConnectionType flag : PipeRoutingConnectionType.values) {
                if (exit.containsFlag(flag)) {
                    mc.fontRenderer.drawString("+", left, line, getColorForFlag(flag));
                    left += mc.fontRenderer.getStringWidth("+");
                } else {
                    mc.fontRenderer.drawString("-", left, line, getColorForFlag(flag));
                    left += mc.fontRenderer.getStringWidth("-");
                }
            }
            line += 10;
            write("  " + exit.debug.filterPosition, mc);
        }
    }
    GL11.glTranslatef(0.0F, 0.0F, 0.0010F);
}
Also used : PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) ExitRoute(logisticspipes.routing.ExitRoute)

Example 17 with ExitRoute

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

the class LogisticsManager method assignDestinationFor.

/**
	 * Will assign a destination for a IRoutedItem based on a best sink reply
	 * recieved from other pipes.
	 * 
	 * @param item
	 *            The item that needs to be routed.
	 * @param sourceRouterID
	 *            The SimpleID of the pipe that is sending the item. (the
	 *            routedItem will cache the UUID, and that the SimpleID belongs
	 *            to the UUID will be checked when appropriate)
	 * @param excludeSource
	 *            Boolean, true means that it wont set the source as the
	 *            destination.
	 * @return IRoutedItem with a newly assigned destination
	 */
@Override
public IRoutedItem assignDestinationFor(IRoutedItem item, int sourceRouterID, boolean excludeSource) {
    //Assert: only called server side.
    //If we for some reason can't get the router we can't do anything either
    IRouter sourceRouter = SimpleServiceLocator.routerManager.getRouterUnsafe(sourceRouterID, false);
    if (sourceRouter == null) {
        return item;
    }
    //Wipe current destination
    item.clearDestination();
    BitSet routersIndex = ServerRouter.getRoutersInterestedIn(item.getItemIdentifierStack().getItem());
    // get the routing table
    List<ExitRoute> validDestinations = new ArrayList<>();
    for (int i = routersIndex.nextSetBit(0); i >= 0; i = routersIndex.nextSetBit(i + 1)) {
        IRouter r = SimpleServiceLocator.routerManager.getRouterUnsafe(i, false);
        List<ExitRoute> exits = sourceRouter.getDistanceTo(r);
        if (exits != null) {
            validDestinations.addAll(exits.stream().filter(e -> e.containsFlag(PipeRoutingConnectionType.canRouteTo)).collect(Collectors.toList()));
        }
    }
    Collections.sort(validDestinations);
    if (item.getItemIdentifierStack() != null && item.getItemIdentifierStack().makeNormalStack().getItem() instanceof LogisticsFluidContainer) {
        Pair<Integer, Integer> bestReply = SimpleServiceLocator.logisticsFluidManager.getBestReply(SimpleServiceLocator.logisticsFluidManager.getFluidFromContainer(item.getItemIdentifierStack()), sourceRouter, item.getJamList());
        if (bestReply.getValue1() != null && bestReply.getValue1() != 0) {
            item.setDestination(bestReply.getValue1());
        }
        return item;
    } else {
        Triplet<Integer, SinkReply, List<IFilter>> bestReply = getBestReply(item.getItemIdentifierStack().getItem(), sourceRouter, validDestinations, excludeSource, item.getJamList(), null, true);
        if (bestReply.getValue1() != null && bestReply.getValue1() != 0) {
            item.setDestination(bestReply.getValue1());
            if (bestReply.getValue2().isPassive) {
                if (bestReply.getValue2().isDefault) {
                    item.setTransportMode(TransportMode.Default);
                } else {
                    item.setTransportMode(TransportMode.Passive);
                }
            } else {
                item.setTransportMode(TransportMode.Active);
            }
            item.setAdditionalTargetInformation(bestReply.getValue2().addInfo);
        }
        return item;
    }
}
Also used : LogisticsFluidContainer(logisticspipes.items.LogisticsFluidContainer) IRouter(logisticspipes.routing.IRouter) SinkReply(logisticspipes.utils.SinkReply) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExitRoute(logisticspipes.routing.ExitRoute)

Example 18 with ExitRoute

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

the class RouteLayer method getOrientationForItem.

public ForgeDirection getOrientationForItem(IRoutedItem item, ForgeDirection blocked) {
    item.checkIDFromUUID();
    //If a item has no destination, find one
    if (item.getDestination() < 0) {
        item = SimpleServiceLocator.logisticsManager.assignDestinationFor(item, _router.getSimpleID(), false);
        _pipe.debug.log("No Destination, assigned new destination: (" + ((LPTravelingItemServer) item).getInfo());
    }
    //If the destination is unknown / unroutable or it already arrived at its destination and somehow looped back
    if (item.getDestination() >= 0 && (!_router.hasRoute(item.getDestination(), item.getTransportMode() == TransportMode.Active, item.getItemIdentifierStack().getItem()) || item.getArrived())) {
        item = SimpleServiceLocator.logisticsManager.assignDestinationFor(item, _router.getSimpleID(), false);
        _pipe.debug.log("Unreachable Destination, sssigned new destination: (" + ((LPTravelingItemServer) item).getInfo());
    }
    item.checkIDFromUUID();
    //If we still have no destination or client side unroutable, drop it
    if (item.getDestination() < 0) {
        return ForgeDirection.UNKNOWN;
    }
    //Is the destination ourself? Deliver it
    if (item.getDestinationUUID().equals(_router.getId())) {
        _transport.handleItem(item);
        if (item.getDistanceTracker() != null) {
            item.getDistanceTracker().setCurrentDistanceToTarget(0);
            item.getDistanceTracker().setDestinationReached();
        }
        if (item.getTransportMode() != TransportMode.Active && !_transport.stillWantItem(item)) {
            return getOrientationForItem(SimpleServiceLocator.logisticsManager.assignDestinationFor(item, _router.getSimpleID(), true), null);
        }
        item.setDoNotBuffer(true);
        item.setArrived(true);
        ForgeDirection o = _transport.itemArrived(item, blocked);
        return o != null ? o : ForgeDirection.UNKNOWN;
    }
    //Do we now know the destination?
    if (!_router.hasRoute(item.getDestination(), item.getTransportMode() == TransportMode.Active, item.getItemIdentifierStack().getItem())) {
        return ForgeDirection.UNKNOWN;
    }
    //Which direction should we send it
    ExitRoute exit = _router.getExitFor(item.getDestination(), item.getTransportMode() == TransportMode.Active, item.getItemIdentifierStack().getItem());
    if (exit == null) {
        return ForgeDirection.UNKNOWN;
    }
    if (item.getDistanceTracker() != null) {
        item.getDistanceTracker().setCurrentDistanceToTarget(exit.blockDistance);
    }
    return exit.exitOrientation;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ExitRoute(logisticspipes.routing.ExitRoute) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Example 19 with ExitRoute

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

the class LogisticsFluidManager method getAvailableFluid.

@Override
public TreeSet<ItemIdentifierStack> getAvailableFluid(List<ExitRoute> validDestinations) {
    Map<FluidIdentifier, Integer> allAvailableItems = new HashMap<>();
    for (ExitRoute r : validDestinations) {
        if (r == null) {
            continue;
        }
        if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
            continue;
        }
        if (!(r.destination.getPipe() instanceof IProvideFluids)) {
            continue;
        }
        IProvideFluids provider = (IProvideFluids) r.destination.getPipe();
        Map<FluidIdentifier, Integer> allItems = provider.getAvailableFluids();
        for (Entry<FluidIdentifier, Integer> liquid : allItems.entrySet()) {
            Integer amount = allAvailableItems.get(liquid.getKey());
            if (amount == null) {
                allAvailableItems.put(liquid.getKey(), liquid.getValue());
            } else {
                long addition = ((long) amount) + liquid.getValue();
                if (addition > Integer.MAX_VALUE) {
                    addition = Integer.MAX_VALUE;
                }
                allAvailableItems.put(liquid.getKey(), (int) addition);
            }
        }
    }
    TreeSet<ItemIdentifierStack> itemIdentifierStackList = allAvailableItems.entrySet().stream().map(item -> new ItemIdentifierStack(item.getKey().getItemIdentifier(), item.getValue())).collect(Collectors.toCollection(TreeSet::new));
    return itemIdentifierStackList;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) IRouter(logisticspipes.routing.IRouter) LogisticsPipes(logisticspipes.LogisticsPipes) IFluidSink(logisticspipes.interfaces.routing.IFluidSink) HashMap(java.util.HashMap) LogisticsFluidContainer(logisticspipes.items.LogisticsFluidContainer) Collectors(java.util.stream.Collectors) ExitRoute(logisticspipes.routing.ExitRoute) TreeSet(java.util.TreeSet) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) Map(java.util.Map) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) FluidStack(net.minecraftforge.fluids.FluidStack) IProvideFluids(logisticspipes.interfaces.routing.IProvideFluids) HashMap(java.util.HashMap) IProvideFluids(logisticspipes.interfaces.routing.IProvideFluids) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ExitRoute(logisticspipes.routing.ExitRoute) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 20 with ExitRoute

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

the class ModuleCrafter method getNextConnectSatelliteId.

protected int getNextConnectSatelliteId(boolean prev, int x) {
    int closestIdFound = prev ? 0 : Integer.MAX_VALUE;
    if (_service == null) {
        return prev ? Math.max(0, satelliteId - 1) : satelliteId + 1;
    }
    for (final PipeItemsSatelliteLogistics satellite : PipeItemsSatelliteLogistics.AllSatellites) {
        CoreRoutedPipe satPipe = satellite;
        if (satPipe == null || satPipe.stillNeedReplace() || satPipe.getRouter() == null || satPipe.isFluidPipe()) {
            continue;
        }
        IRouter satRouter = satPipe.getRouter();
        List<ExitRoute> routes = getRouter().getDistanceTo(satRouter);
        if (routes != null && !routes.isEmpty()) {
            boolean filterFree = false;
            for (ExitRoute route : routes) {
                if (route.filters.isEmpty()) {
                    filterFree = true;
                    break;
                }
            }
            if (!filterFree) {
                continue;
            }
            if (x == -1) {
                if (!prev && satellite.satelliteId > satelliteId && satellite.satelliteId < closestIdFound) {
                    closestIdFound = satellite.satelliteId;
                } else if (prev && satellite.satelliteId < satelliteId && satellite.satelliteId > closestIdFound) {
                    closestIdFound = satellite.satelliteId;
                }
            } else {
                if (!prev && satellite.satelliteId > advancedSatelliteIdArray[x] && satellite.satelliteId < closestIdFound) {
                    closestIdFound = satellite.satelliteId;
                } else if (prev && satellite.satelliteId < advancedSatelliteIdArray[x] && satellite.satelliteId > closestIdFound) {
                    closestIdFound = satellite.satelliteId;
                }
            }
        }
    }
    if (closestIdFound == Integer.MAX_VALUE) {
        if (x == -1) {
            return satelliteId;
        } else {
            return advancedSatelliteIdArray[x];
        }
    }
    return closestIdFound;
}
Also used : PipeItemsSatelliteLogistics(logisticspipes.pipes.PipeItemsSatelliteLogistics) IRouter(logisticspipes.routing.IRouter) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute)

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