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);
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations