Search in sources :

Example 1 with ConnectionType

use of network.rs485.logisticspipes.connection.ConnectionType in project LogisticsPipes by RS485.

the class PathFinder method paintAndgetConnectedRoutingPipes.

/**
 * Recurse through all exists of a pipe to find instances of
 * PipeItemsRouting. maxVisited and maxLength are safeguards for recursion
 * runaways.
 *
 * @param startPipe
 *            - The TileEntity to start the search from
 * @param maxVisited
 *            - The maximum number of pipes to visit, regardless of
 *            recursion level
 * @param maxLength
 *            - The maximum recurse depth, i.e. the maximum length pipe that
 *            is supported
 */
public static HashMap<CoreRoutedPipe, ExitRoute> paintAndgetConnectedRoutingPipes(TileEntity startPipe, EnumFacing startOrientation, int maxVisited, int maxLength, IPaintPath pathPainter, EnumSet<PipeRoutingConnectionType> connectionType) {
    IPipeInformationProvider startProvider = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(startPipe);
    if (startProvider == null) {
        return new HashMap<>();
    }
    PathFinder newSearch = new PathFinder(maxVisited, maxLength, pathPainter);
    DoubleCoordinates p = new DoubleCoordinates(startProvider);
    newSearch.setVisited.add(p);
    CoordinateUtils.add(p, startOrientation);
    TileEntity entity = p.getTileEntity(startProvider.getWorld());
    IPipeInformationProvider provider = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(entity);
    if (provider == null) {
        return new HashMap<>();
    }
    return newSearch.getConnectedRoutingPipes(provider, connectionType, startOrientation);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) HashMap(java.util.HashMap) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 2 with ConnectionType

use of network.rs485.logisticspipes.connection.ConnectionType in project LogisticsPipes by RS485.

the class PathFinder method paintAndgetConnectedRoutingPipes.

/**
	 * Recurse through all exists of a pipe to find instances of
	 * PipeItemsRouting. maxVisited and maxLength are safeguards for recursion
	 * runaways.
	 * 
	 * @param startPipe
	 *            - The TileEntity to start the search from
	 * @param maxVisited
	 *            - The maximum number of pipes to visit, regardless of
	 *            recursion level
	 * @param maxLength
	 *            - The maximum recurse depth, i.e. the maximum length pipe that
	 *            is supported
	 * @return
	 */
public static HashMap<CoreRoutedPipe, ExitRoute> paintAndgetConnectedRoutingPipes(TileEntity startPipe, ForgeDirection startOrientation, int maxVisited, int maxLength, IPaintPath pathPainter, EnumSet<PipeRoutingConnectionType> connectionType) {
    IPipeInformationProvider startProvider = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(startPipe);
    if (startProvider == null) {
        return new HashMap<>();
    }
    PathFinder newSearch = new PathFinder(maxVisited, maxLength, pathPainter);
    DoubleCoordinates p = new DoubleCoordinates(startProvider);
    newSearch.setVisited.add(p);
    CoordinateUtils.add(p, startOrientation);
    TileEntity entity = p.getTileEntity(startProvider.getWorld());
    IPipeInformationProvider provider = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(entity);
    if (provider == null) {
        return new HashMap<>();
    }
    return newSearch.getConnectedRoutingPipes(provider, connectionType, startOrientation);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) HashMap(java.util.HashMap) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 3 with ConnectionType

use of network.rs485.logisticspipes.connection.ConnectionType in project LogisticsPipes by RS485.

the class PipeLogisticsChassis method nextOrientation.

@Override
public void nextOrientation() {
    final SingleAdjacent pointedAdjacent = this.pointedAdjacent;
    Pair<NeighborTileEntity<TileEntity>, ConnectionType> newNeighbor;
    if (pointedAdjacent == null) {
        newNeighbor = nextPointedOrientation(null);
    } else {
        newNeighbor = nextPointedOrientation(pointedAdjacent.getDir());
    }
    final ChassisOrientationPacket packet = PacketHandler.getPacket(ChassisOrientationPacket.class);
    if (newNeighbor == null) {
        this.pointedAdjacent = null;
        packet.setDir(null);
    } else {
        this.pointedAdjacent = new SingleAdjacent(this, newNeighbor.getValue1().getDirection(), newNeighbor.getValue2());
        packet.setDir(newNeighbor.getValue1().getDirection());
    }
    MainProxy.sendPacketToAllWatchingChunk(_module, packet.setTilePos(container));
    refreshRender(true);
}
Also used : RequestChassisOrientationPacket(logisticspipes.network.packets.pipe.RequestChassisOrientationPacket) ChassisOrientationPacket(logisticspipes.network.packets.pipe.ChassisOrientationPacket) ConnectionType(network.rs485.logisticspipes.connection.ConnectionType) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) SingleAdjacent(network.rs485.logisticspipes.connection.SingleAdjacent)

Example 4 with ConnectionType

use of network.rs485.logisticspipes.connection.ConnectionType in project LogisticsPipes by RS485.

the class PipeLogisticsChassis method updateAdjacentCache.

/**
 * Updates pointedAdjacent on {@link CoreRoutedPipe}.
 */
@Override
protected void updateAdjacentCache() {
    super.updateAdjacentCache();
    final Adjacent adjacent = getAdjacent();
    if (adjacent instanceof SingleAdjacent) {
        pointedAdjacent = ((SingleAdjacent) adjacent);
    } else {
        final SingleAdjacent oldPointedAdjacent = pointedAdjacent;
        SingleAdjacent newPointedAdjacent = null;
        if (oldPointedAdjacent != null) {
            // update pointed adjacent with connection type or reset it
            newPointedAdjacent = adjacent.optionalGet(oldPointedAdjacent.getDir()).map(connectionType -> new SingleAdjacent(this, oldPointedAdjacent.getDir(), connectionType)).orElse(null);
        }
        if (newPointedAdjacent == null) {
            newPointedAdjacent = adjacent.neighbors().entrySet().stream().findAny().map(connectedNeighbor -> new SingleAdjacent(this, connectedNeighbor.getKey().getDirection(), connectedNeighbor.getValue())).orElse(null);
        }
        pointedAdjacent = newPointedAdjacent;
    }
}
Also used : Adjacent(network.rs485.logisticspipes.connection.Adjacent) SingleAdjacent(network.rs485.logisticspipes.connection.SingleAdjacent) NoAdjacent(network.rs485.logisticspipes.connection.NoAdjacent) SingleAdjacent(network.rs485.logisticspipes.connection.SingleAdjacent)

Aggregations

HashMap (java.util.HashMap)2 TileEntity (net.minecraft.tileentity.TileEntity)2 SingleAdjacent (network.rs485.logisticspipes.connection.SingleAdjacent)2 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)2 ChassisOrientationPacket (logisticspipes.network.packets.pipe.ChassisOrientationPacket)1 RequestChassisOrientationPacket (logisticspipes.network.packets.pipe.RequestChassisOrientationPacket)1 Adjacent (network.rs485.logisticspipes.connection.Adjacent)1 ConnectionType (network.rs485.logisticspipes.connection.ConnectionType)1 NeighborTileEntity (network.rs485.logisticspipes.connection.NeighborTileEntity)1 NoAdjacent (network.rs485.logisticspipes.connection.NoAdjacent)1