Search in sources :

Example 1 with Quartet

use of logisticspipes.utils.tuples.Quartet in project LogisticsPipes by RS485.

the class LogisticsNewRenderPipe method loadModels.

public static void loadModels() {
    if (!SimpleServiceLocator.cclProxy.isActivated())
        return;
    try {
        Map<String, IModel3D> pipePartModels = SimpleServiceLocator.cclProxy.parseObjModels(LogisticsPipes.class.getResourceAsStream("/logisticspipes/models/PipeModel_moved.obj"), 7, new LPScale(1 / 100f));
        List<IModel3D> highlightList = new ArrayList<>();
        for (EnumFacing dir : EnumFacing.VALUES) {
            LogisticsNewRenderPipe.sideNormal.put(dir, new ArrayList<>());
            String grp = "Side_" + LogisticsNewRenderPipe.getDirAsString_Type1(dir);
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.sideNormal.get(dir).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)))));
            if (LogisticsNewRenderPipe.sideNormal.get(dir).size() != 4) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.sideNormal.get(dir).size());
            }
        }
        for (EnumFacing dir : EnumFacing.VALUES) {
            LogisticsNewRenderPipe.sideBC.put(dir, new ArrayList<>());
            String grp = "Side_BC_" + LogisticsNewRenderPipe.getDirAsString_Type1(dir);
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.sideBC.get(dir).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)))));
            if (LogisticsNewRenderPipe.sideBC.get(dir).size() != 8) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.sideBC.get(dir).size());
            }
        }
        for (Edge edge : Edge.values()) {
            String grp;
            if (edge.part1 == EnumFacing.UP || edge.part1 == EnumFacing.DOWN) {
                grp = "Edge_M_" + LogisticsNewRenderPipe.getDirAsString_Type1(edge.part1) + "_" + LogisticsNewRenderPipe.getDirAsString_Type1(edge.part2);
            } else {
                grp = "Edge_M_S_" + LogisticsNewRenderPipe.getDirAsString_Type1(edge.part1) + LogisticsNewRenderPipe.getDirAsString_Type1(edge.part2);
            }
            for (Entry<String, IModel3D> entry : pipePartModels.entrySet()) {
                if (entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)) {
                    LogisticsNewRenderPipe.edges.put(edge, LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0))));
                    break;
                }
            }
            if (LogisticsNewRenderPipe.edges.get(edge) == null) {
                throw new RuntimeException("Couldn't load " + edge.name() + " (" + grp + ")");
            }
            highlightList.add(LogisticsNewRenderPipe.edges.get(edge));
        }
        for (Corner corner : Corner.values()) {
            LogisticsNewRenderPipe.corners_M.put(corner, new ArrayList<>());
            String grp = "Corner_M_" + corner.ud.s + "_" + corner.ns.s + corner.ew.s;
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.corners_M.get(corner).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)))));
            if (LogisticsNewRenderPipe.corners_M.get(corner).size() != 2) {
                throw new RuntimeException("Couldn't load " + corner.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.corners_M.get(corner).size());
            }
            highlightList.addAll(LogisticsNewRenderPipe.corners_M.get(corner));
        }
        for (Corner corner : Corner.values()) {
            LogisticsNewRenderPipe.corners_I3.put(corner, new ArrayList<>());
            String grp = "Corner_I3_" + corner.ud.s + "_" + corner.ns.s + corner.ew.s;
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.corners_I3.get(corner).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)))));
            if (LogisticsNewRenderPipe.corners_I3.get(corner).size() != 2) {
                throw new RuntimeException("Couldn't load " + corner.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.corners_I3.get(corner).size());
            }
        }
        for (PipeSupport support : PipeSupport.values()) {
            String grp = "Support_" + LogisticsNewRenderPipe.getDirAsString_Type1(support.dir) + "_" + support.ori.s;
            for (Entry<String, IModel3D> entry : pipePartModels.entrySet()) {
                if (entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)) {
                    LogisticsNewRenderPipe.supports.put(support, LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0))));
                    break;
                }
            }
            if (LogisticsNewRenderPipe.supports.get(support) == null) {
                throw new RuntimeException("Couldn't load " + support.name() + " (" + grp + ")");
            }
        }
        for (PipeTurnCorner corner : PipeTurnCorner.values()) {
            String grp = "Corner_I_" + corner.corner.ud.s + "_" + corner.corner.ns.s + corner.corner.ew.s;
            for (Entry<String, IModel3D> entry : pipePartModels.entrySet()) {
                if (entry.getKey().contains(" " + grp)) {
                    char c = ' ';
                    if (!entry.getKey().endsWith(" " + grp)) {
                        c = entry.getKey().charAt(entry.getKey().indexOf(" " + grp) + (" " + grp).length());
                    }
                    if (Character.isDigit(c)) {
                        if (c == '2') {
                            if (corner.turn != Turn.NORTH_SOUTH) {
                                continue;
                            }
                        } else if (c == '1') {
                            if (corner.turn != Turn.EAST_WEST) {
                                continue;
                            }
                        } else {
                            throw new UnsupportedOperationException();
                        }
                    } else {
                        if (corner.turn != Turn.UP_DOWN) {
                            continue;
                        }
                    }
                    LogisticsNewRenderPipe.corners_I.put(corner, LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0))));
                    break;
                }
            }
            if (LogisticsNewRenderPipe.corners_I.get(corner) == null) {
                throw new RuntimeException("Couldn't load " + corner.name() + " (" + grp + ")");
            }
        }
        for (PipeTurnCorner corner : PipeTurnCorner.values()) {
            String grp = "Spacer" + corner.number;
            for (Entry<String, IModel3D> entry : pipePartModels.entrySet()) {
                if (entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)) {
                    LogisticsNewRenderPipe.spacers.put(corner, LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0))));
                    break;
                }
            }
            if (LogisticsNewRenderPipe.spacers.get(corner) == null) {
                throw new RuntimeException("Couldn't load " + corner.name() + " (" + grp + ")");
            }
        }
        for (PipeMount mount : PipeMount.values()) {
            String grp = "Mount_" + LogisticsNewRenderPipe.getDirAsString_Type1(mount.dir) + "_" + LogisticsNewRenderPipe.getDirAsString_Type1(mount.side);
            for (Entry<String, IModel3D> entry : pipePartModels.entrySet()) {
                if (entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)) {
                    LogisticsNewRenderPipe.mounts.put(mount, LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0))));
                    break;
                }
            }
            if (LogisticsNewRenderPipe.mounts.get(mount) == null) {
                throw new RuntimeException("Couldn't load " + mount.name() + " (" + grp + ")");
            }
        }
        for (EnumFacing dir : EnumFacing.VALUES) {
            LogisticsNewRenderPipe.texturePlate_Inner.put(dir, new ArrayList<>());
            String grp = "Inner_Plate_" + LogisticsNewRenderPipe.getDirAsString_Type1(dir);
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.texturePlate_Inner.get(dir).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)))));
            if (LogisticsNewRenderPipe.texturePlate_Inner.get(dir).size() != 2) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.texturePlate_Inner.get(dir).size());
            }
        }
        for (EnumFacing dir : EnumFacing.VALUES) {
            LogisticsNewRenderPipe.texturePlate_Outer.put(dir, new ArrayList<>());
            String grp = "Texture_Plate_" + LogisticsNewRenderPipe.getDirAsString_Type1(dir);
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.texturePlate_Outer.get(dir).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)).apply(new LPTranslation(-0.5, -0.5, -0.5)).apply(new LPScale(1.001D)).apply(new LPTranslation(0.5, 0.5, 0.5)))));
            if (LogisticsNewRenderPipe.texturePlate_Outer.get(dir).size() != 2) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.texturePlate_Outer.get(dir).size());
            }
        }
        for (EnumFacing dir : EnumFacing.VALUES) {
            LogisticsNewRenderPipe.sideTexturePlate.put(dir, new Quartet<>(new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>()));
            String grp = "Texture_Side_" + LogisticsNewRenderPipe.getDirAsString_Type1(dir);
            for (Entry<String, IModel3D> entry : pipePartModels.entrySet()) {
                if (entry.getKey().contains(" " + grp)) {
                    IModel3D model = LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)));
                    double sizeA = (model.bounds().max().x() - model.bounds().min().x()) + (model.bounds().max().y() - model.bounds().min().y()) + (model.bounds().max().z() - model.bounds().min().z());
                    double dis = Math.pow(model.bounds().min().x() - 0.5D, 2) + Math.pow(model.bounds().min().y() - 0.5D, 2) + Math.pow(model.bounds().min().z() - 0.5D, 2);
                    if (sizeA < 0.5D) {
                        if ((dis > 0.22 && dis < 0.24) || (dis > 0.38 && dis < 0.40)) {
                            LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue4().add(model);
                        } else if ((dis < 0.2 && dis > 0.18) || (dis < 0.36 && dis > 0.34)) {
                            LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue2().add(model);
                        } else {
                            throw new UnsupportedOperationException("Dis: " + dis);
                        }
                    } else {
                        if ((dis > 0.22 && dis < 0.24) || (dis > 0.38 && dis < 0.40)) {
                            LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue3().add(model);
                        } else if ((dis < 0.2 && dis > 0.18) || (dis < 0.36 && dis > 0.34)) {
                            LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue1().add(model);
                        } else {
                            throw new UnsupportedOperationException("Dis: " + dis);
                        }
                    }
                }
            }
            if (LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue1().size() != 8) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue1().size());
            }
            if (LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue2().size() != 8) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue2().size());
            }
            if (LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue3().size() != 8) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue3().size());
            }
            if (LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue4().size() != 8) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue4().size());
            }
        }
        for (PipeMount mount : PipeMount.values()) {
            LogisticsNewRenderPipe.textureConnectorPlate.put(mount, new ArrayList<>());
            String grp = "Texture_Connector_" + LogisticsNewRenderPipe.getDirAsString_Type1(mount.dir) + "_" + LogisticsNewRenderPipe.getDirAsString_Type1(mount.side);
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.textureConnectorPlate.get(mount).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)))));
            if (LogisticsNewRenderPipe.textureConnectorPlate.get(mount).size() != 4) {
                throw new RuntimeException("Couldn't load " + mount.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.textureConnectorPlate.get(mount).size());
            }
        }
        highlight = SimpleServiceLocator.cclProxy.combine(highlightList);
        pipePartModels = SimpleServiceLocator.cclProxy.parseObjModels(LogisticsPipes.class.getResourceAsStream("/logisticspipes/models/PipeModel_Transport_Box.obj"), 7, new LPScale(1 / 100f));
        LogisticsNewRenderPipe.innerTransportBox = LogisticsNewRenderPipe.compute(pipePartModels.get("InnerTransportBox").backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)).apply(new LPTranslation(-0.5, -0.5, -0.5)).apply(new LPScale(0.99D)).apply(new LPTranslation(0.5, 0.5, 0.5)));
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
Also used : Arrays(java.util.Arrays) IVec3(logisticspipes.proxy.object3d.interfaces.IVec3) Textures(logisticspipes.textures.Textures) LogisticsPipes(logisticspipes.LogisticsPipes) Quartet(logisticspipes.utils.tuples.Quartet) MainProxy(logisticspipes.proxy.MainProxy) Block(net.minecraft.block.Block) Side(net.minecraftforge.fml.relauncher.Side) ClientConfiguration(network.rs485.logisticspipes.config.ClientConfiguration) Map(java.util.Map) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) PipeBlockRequestTable(logisticspipes.pipes.PipeBlockRequestTable) GL11(org.lwjgl.opengl.GL11) I3DOperation(logisticspipes.proxy.object3d.interfaces.I3DOperation) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) CoordinateUtils(network.rs485.logisticspipes.world.CoordinateUtils) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) Entry(java.util.Map.Entry) PipeRenderState(logisticspipes.renderer.state.PipeRenderState) EntityModelFX(logisticspipes.pipefxhandlers.EntityModelFX) IModel3D(logisticspipes.proxy.object3d.interfaces.IModel3D) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) LPTranslation(logisticspipes.proxy.object3d.operation.LPTranslation) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) HashMap(java.util.HashMap) PipeItemsBasicLogistics(logisticspipes.pipes.PipeItemsBasicLogistics) LPUVTranslation(logisticspipes.proxy.object3d.operation.LPUVTranslation) LPUVTransformationList(logisticspipes.proxy.object3d.operation.LPUVTransformationList) ArrayList(java.util.ArrayList) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) Lists(com.google.common.collect.Lists) Minecraft(net.minecraft.client.Minecraft) IBounds(logisticspipes.proxy.object3d.interfaces.IBounds) LinkedList(java.util.LinkedList) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) LPConstants(logisticspipes.LPConstants) Nonnull(javax.annotation.Nonnull) LPColourMultiplier(logisticspipes.proxy.object3d.operation.LPColourMultiplier) Iterator(java.util.Iterator) World(net.minecraft.world.World) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) TextureMap(net.minecraft.client.renderer.texture.TextureMap) EnumFacing(net.minecraft.util.EnumFacing) LPUVScale(logisticspipes.proxy.object3d.operation.LPUVScale) ParticleManager(net.minecraft.client.particle.ParticleManager) ResourceLocation(net.minecraft.util.ResourceLocation) Data(lombok.Data) TextureTransformation(logisticspipes.proxy.object3d.interfaces.TextureTransformation) TileEntity(net.minecraft.tileentity.TileEntity) LPScale(logisticspipes.proxy.object3d.operation.LPScale) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) IModel3D(logisticspipes.proxy.object3d.interfaces.IModel3D) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) LPTranslation(logisticspipes.proxy.object3d.operation.LPTranslation) LogisticsPipes(logisticspipes.LogisticsPipes) LPScale(logisticspipes.proxy.object3d.operation.LPScale)

Example 2 with Quartet

use of logisticspipes.utils.tuples.Quartet in project LogisticsPipes by RS485.

the class PathFinder method getConnectedRoutingPipes.

private HashMap<CoreRoutedPipe, ExitRoute> getConnectedRoutingPipes(IPipeInformationProvider startPipe, EnumSet<PipeRoutingConnectionType> connectionFlags, EnumFacing side) {
    HashMap<CoreRoutedPipe, ExitRoute> foundPipes = new HashMap<>();
    final int setVisitedSize = setVisited.size();
    boolean root = setVisitedSize == 0;
    // Reset visited count at top level
    if (setVisitedSize == 1) {
        pipesVisited = 0;
    }
    // Break recursion if we have visited a set number of pipes, to prevent client hang if pipes are weirdly configured
    pipesVisited += startPipe.getDistanceWeight() > 0 ? startPipe.getDistanceWeight() : 1;
    if (pipesVisited > maxVisited) {
        return foundPipes;
    }
    // Break recursion after certain amount of nodes visited
    if (setVisitedSize > maxLength * 10) {
        return foundPipes;
    }
    // Check size of setVisited first to speed up the process, so we don't sum the distances all the time
    if (setVisitedSize > maxLength && distances.values().stream().mapToDouble(i -> Math.max(Math.min(i, 1), 0)).sum() > maxLength) {
        return foundPipes;
    }
    if (!startPipe.isRouterInitialized()) {
        return foundPipes;
    }
    // Break recursion if we end up on a routing pipe, unless its the first one. Will break if matches the first call
    if (startPipe.isRoutingPipe() && setVisitedSize != 0) {
        CoreRoutedPipe rp = startPipe.getRoutingPipe();
        if (rp.stillNeedReplace()) {
            return foundPipes;
        }
        double size = 0;
        for (Double dis : distances.values()) {
            size += dis;
        }
        if (!rp.getUpgradeManager().hasPowerPassUpgrade()) {
            connectionFlags.remove(PipeRoutingConnectionType.canPowerSubSystemFrom);
        }
        foundPipes.put(rp, new ExitRoute(null, rp.getRouter(), null, side.getOpposite(), Math.max(1, size), connectionFlags, distances.size()));
        return foundPipes;
    }
    // Visited is checked after, so we can reach the same target twice to allow to keep the shortest path
    setVisited.add(new DoubleCoordinates(startPipe));
    distances.put(new DoubleCoordinates(startPipe), startPipe.getDistance() * startPipe.getDistanceWeight());
    // first check specialPipeConnections (tesseracts, teleports, other connectors)
    List<ConnectionInformation> pipez = SimpleServiceLocator.specialpipeconnection.getConnectedPipes(startPipe, connectionFlags, side);
    for (ConnectionInformation specialConnection : pipez) {
        if (setVisited.contains(new DoubleCoordinates(specialConnection.getConnectedPipe()))) {
            // Don't go where we have been before
            continue;
        }
        distances.put(new DoubleCoordinates(startPipe).center(), specialConnection.getDistance());
        HashMap<CoreRoutedPipe, ExitRoute> result = getConnectedRoutingPipes(specialConnection.getConnectedPipe(), specialConnection.getConnectionFlags(), specialConnection.getInsertOrientation());
        distances.remove(new DoubleCoordinates(startPipe).center());
        for (Entry<CoreRoutedPipe, ExitRoute> pipe : result.entrySet()) {
            pipe.getValue().exitOrientation = specialConnection.getExitOrientation();
            ExitRoute foundPipe = foundPipes.get(pipe.getKey());
            if (foundPipe == null || (pipe.getValue().distanceToDestination < foundPipe.distanceToDestination)) {
                // New path OR 	If new path is better, replace old path
                foundPipes.put(pipe.getKey(), pipe.getValue());
            }
        }
    }
    ArrayDeque<Quartet<TileEntity, EnumFacing, Integer, Boolean>> connections = new ArrayDeque<>();
    // Recurse in all directions
    for (EnumFacing direction : EnumFacing.VALUES) {
        if (root && side != null && !direction.equals(side)) {
            continue;
        }
        // tile may be up to 1 second old, but any neighbour pipe change will cause an immidiate update here, so we know that if it has changed, it isn't a pipe that has done so.
        TileEntity tile = startPipe.getNextConnectedTile(direction);
        if (tile == null) {
            continue;
        }
        if (root && (direction.getAxis() == EnumFacing.Axis.X || direction.getAxis() == EnumFacing.Axis.Z)) {
            if (tile instanceof ILogisticsPowerProvider) {
                if (powerNodes == null) {
                    powerNodes = new ArrayList<>();
                }
                // If we are a FireWall pipe add our filter to the pipes
                if (startPipe.isFirewallPipe()) {
                    powerNodes.add(new Pair<>((ILogisticsPowerProvider) tile, new OneList<>(startPipe.getFirewallFilter())));
                } else {
                    powerNodes.add(new Pair<>((ILogisticsPowerProvider) tile, Collections.unmodifiableList(new ArrayList<>(0))));
                }
            } else if (tile instanceof ISubSystemPowerProvider) {
                if (subPowerProvider == null) {
                    subPowerProvider = new ArrayList<>();
                }
                // If we are a FireWall pipe add our filter to the pipes
                if (startPipe.isFirewallPipe()) {
                    subPowerProvider.add(new Pair<>((ISubSystemPowerProvider) tile, new OneList<>(startPipe.getFirewallFilter())));
                } else {
                    subPowerProvider.add(new Pair<>((ISubSystemPowerProvider) tile, Collections.unmodifiableList(new ArrayList<>(0))));
                }
            }
        }
        connections.add(new Quartet<>(tile, direction, 0, false));
    }
    while (!connections.isEmpty()) {
        Quartet<TileEntity, EnumFacing, Integer, Boolean> quartet = connections.pollFirst();
        TileEntity tile = quartet.getValue1();
        EnumFacing direction = quartet.getValue2();
        int resistance = quartet.getValue3();
        boolean isDirectConnection = quartet.getValue4();
        EnumSet<PipeRoutingConnectionType> nextConnectionFlags = EnumSet.copyOf(connectionFlags);
        if (root) {
            Collection<TileEntity> list = SimpleServiceLocator.specialtileconnection.getConnectedPipes(tile);
            if (!list.isEmpty()) {
                connections.addAll(list.stream().map(pipe -> new Quartet<>(pipe, direction, 0, false)).collect(Collectors.toList()));
                listTileEntity(tile);
                continue;
            }
            if (!startPipe.getRoutingPipe().getUpgradeManager().hasPowerPassUpgrade()) {
                nextConnectionFlags.remove(PipeRoutingConnectionType.canPowerSubSystemFrom);
            }
        }
        if (!SimpleServiceLocator.pipeInformationManager.isPipe(tile) && tile.hasCapability(LogisticsPipes.ITEM_HANDLER_CAPABILITY, direction.getOpposite()) && startPipe.isRoutingPipe() && startPipe.getRoutingPipe() instanceof IChannelRoutingConnection && startPipe.canConnect(tile, direction, false)) {
            if (SimpleServiceLocator.connectionManager.hasChannelConnection(startPipe.getRoutingPipe().getRouter())) {
                List<CoreRoutedPipe> connectedPipes = SimpleServiceLocator.connectionManager.getConnectedPipes(startPipe.getRoutingPipe().getRouter());
                connections.addAll(connectedPipes.stream().map(pipe -> new Quartet<>((TileEntity) pipe.container, direction, ((IChannelRoutingConnection) startPipe.getRoutingPipe()).getConnectionResistance(), true)).collect(Collectors.toList()));
                if (!connectedPipes.isEmpty()) {
                    continue;
                }
            }
        }
        if (tile == null) {
            continue;
        }
        IPipeInformationProvider currentPipe = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(tile);
        if (currentPipe != null && currentPipe.isRouterInitialized() && (isDirectConnection || SimpleServiceLocator.pipeInformationManager.canConnect(startPipe, currentPipe, direction, true))) {
            listTileEntity(tile);
            if (currentPipe.isMultiBlock()) {
                currentPipe.getPartsOfPipe().forEach(this::listTileEntity);
            }
            if (setVisited.contains(new DoubleCoordinates(currentPipe))) {
                // Don't go where we have been before
                continue;
            }
            if (side != direction && !root) {
                // Only straight connections for subsystem power
                nextConnectionFlags.remove(PipeRoutingConnectionType.canPowerSubSystemFrom);
            }
            if (isDirectConnection) {
                // ISC doesn't pass power
                nextConnectionFlags.remove(PipeRoutingConnectionType.canPowerFrom);
                nextConnectionFlags.remove(PipeRoutingConnectionType.canPowerSubSystemFrom);
            }
            // Iron, obsidean and liquid pipes will separate networks
            if (currentPipe.divideNetwork()) {
                continue;
            }
            if (currentPipe.powerOnly()) {
                nextConnectionFlags.remove(PipeRoutingConnectionType.canRouteTo);
                nextConnectionFlags.remove(PipeRoutingConnectionType.canRequestFrom);
            }
            if (startPipe.isOnewayPipe()) {
                if (startPipe.isOutputClosed(direction)) {
                    nextConnectionFlags.remove(PipeRoutingConnectionType.canRouteTo);
                }
            }
            if (currentPipe.isOnewayPipe()) {
                nextConnectionFlags.remove(PipeRoutingConnectionType.canPowerSubSystemFrom);
                if (currentPipe.isOutputClosed(direction.getOpposite())) {
                    nextConnectionFlags.remove(PipeRoutingConnectionType.canRequestFrom);
                    nextConnectionFlags.remove(PipeRoutingConnectionType.canPowerFrom);
                }
            }
            if (nextConnectionFlags.isEmpty()) {
                // don't bother going somewhere we can't do anything with
                continue;
            }
            int beforeRecurseCount = foundPipes.size();
            HashMap<CoreRoutedPipe, ExitRoute> result = null;
            if (currentPipe instanceof IRouteProvider) {
                List<RouteInfo> list = ((IRouteProvider) currentPipe).getConnectedPipes(direction.getOpposite());
                if (list != null) {
                    result = new HashMap<>();
                    DoubleCoordinates pos = new DoubleCoordinates(currentPipe);
                    for (RouteInfo info : list) {
                        if (info.getPipe() == startPipe)
                            continue;
                        if (setVisited.contains(new DoubleCoordinates(info.getPipe()))) {
                            // Don't go where we have been before
                            continue;
                        }
                        distances.put(pos, (currentPipe.getDistance() * currentPipe.getDistanceWeight()) + info.getLength());
                        result.putAll(getConnectedRoutingPipes(info.getPipe(), nextConnectionFlags, direction));
                        distances.remove(pos);
                    }
                }
            }
            if (result == null) {
                result = getConnectedRoutingPipes(currentPipe, nextConnectionFlags, direction);
            }
            for (Entry<CoreRoutedPipe, ExitRoute> pipeEntry : result.entrySet()) {
                // Update Result with the direction we took
                pipeEntry.getValue().exitOrientation = direction;
                ExitRoute foundPipe = foundPipes.get(pipeEntry.getKey());
                if (foundPipe == null) {
                    // New path
                    foundPipes.put(pipeEntry.getKey(), pipeEntry.getValue());
                    // Add resistance
                    pipeEntry.getValue().distanceToDestination += resistance;
                } else if (pipeEntry.getValue().distanceToDestination + resistance < foundPipe.distanceToDestination) {
                    // If new path is better, replace old path, otherwise do nothing
                    foundPipes.put(pipeEntry.getKey(), pipeEntry.getValue());
                    // Add resistance
                    pipeEntry.getValue().distanceToDestination += resistance;
                }
            }
            if (foundPipes.size() > beforeRecurseCount && pathPainter != null) {
                pathPainter.addLaser(startPipe.getWorld(), new LaserData(startPipe.getX(), startPipe.getY(), startPipe.getZ(), direction, connectionFlags));
            }
        }
    }
    setVisited.remove(new DoubleCoordinates(startPipe));
    distances.remove(new DoubleCoordinates(startPipe));
    if (startPipe.isRoutingPipe()) {
        // ie, has the recursion returned to the pipe it started from?
        for (ExitRoute e : foundPipes.values()) {
            e.root = (startPipe.getRoutingPipe()).getRouter();
        }
    }
    // If we are a FireWall pipe add our filter to the pipes
    if (startPipe.isFirewallPipe() && root) {
        for (ExitRoute e : foundPipes.values()) {
            e.filters = new OneList<>(startPipe.getFirewallFilter());
        }
    }
    return foundPipes;
}
Also used : LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) LogisticsPipes(logisticspipes.LogisticsPipes) Quartet(logisticspipes.utils.tuples.Quartet) HashMap(java.util.HashMap) ILogisticsPowerProvider(logisticspipes.api.ILogisticsPowerProvider) IPaintPath(logisticspipes.routing.IPaintPath) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ISubSystemPowerProvider(logisticspipes.interfaces.ISubSystemPowerProvider) LPTileEntityObject(logisticspipes.asm.te.LPTileEntityObject) OneList(logisticspipes.utils.OneList) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) ConnectionInformation(logisticspipes.proxy.specialconnection.SpecialPipeConnection.ConnectionInformation) EnumSet(java.util.EnumSet) ITileEntityChangeListener(logisticspipes.asm.te.ITileEntityChangeListener) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) World(net.minecraft.world.World) Collection(java.util.Collection) Set(java.util.Set) EnumFacing(net.minecraft.util.EnumFacing) CoordinateUtils(network.rs485.logisticspipes.world.CoordinateUtils) Collectors(java.util.stream.Collectors) ExitRoute(logisticspipes.routing.ExitRoute) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) LaserData(logisticspipes.routing.LaserData) IFilter(logisticspipes.interfaces.routing.IFilter) RouteInfo(logisticspipes.routing.pathfinder.IRouteProvider.RouteInfo) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) TileEntity(net.minecraft.tileentity.TileEntity) IChannelRoutingConnection(logisticspipes.interfaces.routing.IChannelRoutingConnection) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) ConnectionInformation(logisticspipes.proxy.specialconnection.SpecialPipeConnection.ConnectionInformation) Quartet(logisticspipes.utils.tuples.Quartet) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) IChannelRoutingConnection(logisticspipes.interfaces.routing.IChannelRoutingConnection) TileEntity(net.minecraft.tileentity.TileEntity) ILogisticsPowerProvider(logisticspipes.api.ILogisticsPowerProvider) RouteInfo(logisticspipes.routing.pathfinder.IRouteProvider.RouteInfo) ISubSystemPowerProvider(logisticspipes.interfaces.ISubSystemPowerProvider) Pair(logisticspipes.utils.tuples.Pair) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) ArrayDeque(java.util.ArrayDeque) OneList(logisticspipes.utils.OneList) LaserData(logisticspipes.routing.LaserData) ExitRoute(logisticspipes.routing.ExitRoute)

Aggregations

ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 LogisticsPipes (logisticspipes.LogisticsPipes)2 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)2 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)2 Quartet (logisticspipes.utils.tuples.Quartet)2 Lists (com.google.common.collect.Lists)1 ArrayDeque (java.util.ArrayDeque)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1