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