use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class LPBCTileGenericPipe method getBCPipePluggable.
@Override
public IBCPipePluggable getBCPipePluggable(final ForgeDirection sideHit) {
final PipePluggable plug = getPipePluggable(sideHit);
if (plug == null) {
return null;
}
return new IBCPipePluggable() {
@Override
public ItemStack[] getDropItems(LogisticsTileGenericPipe container) {
return plug.getDropItems(container);
}
@Override
public boolean isBlocking() {
return plug.isBlocking(pipe.container, sideHit);
}
@Override
public Object getOriginal() {
return plug;
}
@Override
@SideOnly(Side.CLIENT)
public void renderPluggable(RenderBlocks renderblocks, ForgeDirection dir, int renderPass, int x, int y, int z) {
if (plug.getRenderer() == null) {
return;
}
plug.getRenderer().renderPluggable(renderblocks, bcPipe, dir, plug, FakeBlock.INSTANCE, renderPass, x, y, z);
}
@Override
public boolean isAcceptingItems(LPTravelingItemServer arrivingItem) {
if (plug instanceof RobotStationPluggable) {
return true;
}
return false;
}
@Override
public LPTravelingItemServer handleItem(LPTravelingItemServer arrivingItem) {
DockingStation station = ((RobotStationPluggable) plug).getStation();
if (!station.isTaken()) {
return arrivingItem;
}
EntityRobotBase robot = station.robotTaking();
if (!(robot.getBoard() instanceof LogisticsRoutingBoardRobot)) {
return arrivingItem;
}
if (!((LogisticsRoutingBoardRobot) robot.getBoard()).isAcceptsItems()) {
return arrivingItem;
}
DoubleCoordinates robotPos = new DoubleCoordinates(robot);
if (CoordinateUtils.add(new DoubleCoordinates(LPBCTileGenericPipe.this).center(), sideHit, 0.5).distanceTo(robotPos) > 0.05) {
// Not at station
return arrivingItem;
}
return ((LogisticsRoutingBoardRobot) robot.getBoard()).handleItem(arrivingItem);
}
};
}
use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class LogisticsNewPipeWorldRenderer method renderWorldBlock.
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
Tessellator tess = Tessellator.instance;
TileEntity tile = world.getTileEntity(x, y, z);
LogisticsTileGenericPipe pipeTile = (LogisticsTileGenericPipe) tile;
PipeRenderState renderState = pipeTile.renderState;
if (pipeTile.pipe instanceof PipeBlockRequestTable) {
if (LogisticsPipeWorldRenderer.renderPass != 0) {
return false;
}
IIconProvider icons = pipeTile.getPipeIcons();
if (icons == null) {
return false;
}
if (requestBlock == null || true) {
requestBlock = new HashMap<>();
for (BlockRotation rot : BlockRotation.values()) {
requestBlock.put(rot, LogisticsNewSolidBlockWorldRenderer.block.get(rot).copy().apply(new LPScale(0.999)).apply(new LPTranslation(0.0005, 0.0005, 0.0005)));
}
}
SimpleServiceLocator.cclProxy.getRenderState().reset();
SimpleServiceLocator.cclProxy.getRenderState().setUseNormals(true);
SimpleServiceLocator.cclProxy.getRenderState().setAlphaOverride(0xff);
BlockRotation rotation = BlockRotation.getRotation(((PipeBlockRequestTable) pipeTile.pipe).getRotation());
int brightness = new DoubleCoordinates(x, y, z).getBlock(world).getMixedBrightnessForBlock(world, x, y, z);
tess.setColorOpaque_F(1F, 1F, 1F);
tess.setBrightness(brightness);
IIconTransformation icon = SimpleServiceLocator.cclProxy.createIconTransformer(Textures.LOGISTICS_REQUEST_TABLE_NEW);
requestBlock.get(rotation).render(new LPTranslation(x, y, z), icon);
for (CoverSides side : CoverSides.values()) {
if (!pipeTile.renderState.pipeConnectionMatrix.isConnected(side.getDir(rotation))) {
LogisticsNewSolidBlockWorldRenderer.texturePlate_Outer.get(side).get(rotation).render(new LPTranslation(x, y, z), icon);
LogisticsNewSolidBlockWorldRenderer.texturePlate_Inner.get(side).get(rotation).render(new LPTranslation(x, y, z), icon);
}
}
return true;
}
boolean hasRendered = false;
tess.addTranslation(0.00002F, 0.00002F, 0.00002F);
renderer.setRenderBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (pipeTile.tilePart.hasPipePluggable(dir)) {
IBCPipePluggable p = pipeTile.tilePart.getBCPipePluggable(dir);
p.renderPluggable(renderer, dir, LogisticsPipeWorldRenderer.renderPass, x, y, z);
hasRendered = true;
}
}
tess.addTranslation(-0.00002F, -0.00002F, -0.00002F);
boolean[] solidSides = new boolean[6];
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
DoubleCoordinates pos = CoordinateUtils.add(new DoubleCoordinates((TileEntity) pipeTile), dir);
Block blockSide = pos.getBlock(pipeTile.getWorldObj());
if (blockSide != null && blockSide.isSideSolid(pipeTile.getWorldObj(), pos.getXInt(), pos.getYInt(), pos.getZInt(), dir.getOpposite()) && !renderState.pipeConnectionMatrix.isConnected(dir)) {
solidSides[dir.ordinal()] = true;
}
}
if (!Arrays.equals(solidSides, renderState.solidSidesCache)) {
renderState.solidSidesCache = solidSides.clone();
renderState.cachedRenderer = null;
}
if (hasRendered) {
block.setBlockBounds(0, 0, 0, 0, 0, 0);
renderer.setRenderBoundsFromBlock(block);
renderer.renderStandardBlock(block, x, y, z);
block.setBlockBounds(0, 0, 0, 1, 1, 1);
}
return hasRendered;
}
use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class LogisticsNewRenderPipe method fillObjectsToRenderList.
private void fillObjectsToRenderList(List<RenderEntry> objectsToRender, LogisticsTileGenericPipe pipeTile, PipeRenderState renderState) {
List<Edge> edgesToRender = new ArrayList<>(Arrays.asList(Edge.values()));
Map<Corner, Integer> connectionAtCorner = new HashMap<>();
List<PipeMount> mountCanidates = new ArrayList<>(Arrays.asList(PipeMount.values()));
int connectionCount = 0;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (renderState.pipeConnectionMatrix.isConnected(dir) || pipeTile.pipe.hasSpecialPipeEndAt(dir)) {
connectionCount++;
if (renderState.pipeConnectionMatrix.isBCConnected(dir) || renderState.pipeConnectionMatrix.isTDConnected(dir)) {
I3DOperation[] texture = new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture };
if (renderState.textureMatrix.isRouted()) {
if (renderState.textureMatrix.isRoutedInDir(dir)) {
if (renderState.textureMatrix.isSubPowerInDir(dir)) {
texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(0, +23F / 100), LogisticsNewRenderPipe.statusBCTexture) };
} else {
texture = new I3DOperation[] { LogisticsNewRenderPipe.statusBCTexture };
}
} else {
texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(0, -23F / 100), LogisticsNewRenderPipe.statusBCTexture) };
}
}
for (IModel3D model : LogisticsNewRenderPipe.sideBC.get(dir)) {
objectsToRender.add(new RenderEntry(model, texture));
}
} else if (!pipeTile.pipe.hasSpecialPipeEndAt(dir)) {
I3DOperation[] texture = new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture };
if (renderState.textureMatrix.isRouted()) {
if (renderState.textureMatrix.isRoutedInDir(dir)) {
if (renderState.textureMatrix.isSubPowerInDir(dir)) {
texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(-2.5F / 10, 0), LogisticsNewRenderPipe.statusTexture) };
} else {
texture = new I3DOperation[] { LogisticsNewRenderPipe.statusTexture };
}
} else {
if (renderState.textureMatrix.isHasPowerUpgrade()) {
if (renderState.textureMatrix.getPointedOrientation() == dir) {
texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(+2.5F / 10, 0), LogisticsNewRenderPipe.statusTexture) };
} else {
texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(-2.5F / 10, 37F / 100), LogisticsNewRenderPipe.statusTexture) };
}
} else {
if (renderState.textureMatrix.getPointedOrientation() == dir) {
texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(+2.5F / 10, 37F / 100), LogisticsNewRenderPipe.statusTexture) };
} else {
texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(0, 37F / 100), LogisticsNewRenderPipe.statusTexture) };
}
}
}
}
for (IModel3D model : LogisticsNewRenderPipe.sideNormal.get(dir)) {
DoubleCoordinates coords = CoordinateUtils.add(new DoubleCoordinates((TileEntity) pipeTile), dir);
Block block = coords.getBlock(pipeTile.getWorld());
double[] bounds = { block.getBlockBoundsMinY(), block.getBlockBoundsMinZ(), block.getBlockBoundsMinX(), block.getBlockBoundsMaxY(), block.getBlockBoundsMaxZ(), block.getBlockBoundsMaxX() };
if (SimpleServiceLocator.enderIOProxy.isItemConduit(coords.getTileEntity(pipeTile.getWorld()), dir.getOpposite()) || SimpleServiceLocator.enderIOProxy.isFluidConduit(coords.getTileEntity(pipeTile.getWorld()), dir.getOpposite())) {
bounds = new double[] { 0.0249D, 0.0249D, 0.0249D, 0.9751D, 0.9751D, 0.9751D };
}
double bound = bounds[dir.ordinal() / 2 + (dir.ordinal() % 2 == 0 ? 3 : 0)];
ScaleObject key = new ScaleObject(model, bound);
IModel3D model2 = LogisticsNewRenderPipe.scaleMap.get(key);
if (model2 == null) {
model2 = model.copy();
IVec3 min = model2.bounds().min();
model2.apply(new LPTranslation(min).inverse());
double toAdd = 1;
if (dir.ordinal() % 2 == 1) {
toAdd = 1 + (bound / LPConstants.PIPE_MIN_POS);
model2.apply(new LPScale(dir.offsetX != 0 ? toAdd : 1, dir.offsetY != 0 ? toAdd : 1, dir.offsetZ != 0 ? toAdd : 1));
} else {
bound = 1 - bound;
toAdd = 1 + (bound / LPConstants.PIPE_MIN_POS);
model2.apply(new LPScale(dir.offsetX != 0 ? toAdd : 1, dir.offsetY != 0 ? toAdd : 1, dir.offsetZ != 0 ? toAdd : 1));
model2.apply(new LPTranslation(dir.offsetX * bound, dir.offsetY * bound, dir.offsetZ * bound));
}
model2.apply(new LPTranslation(min));
LogisticsNewRenderPipe.scaleMap.put(key, model2);
}
objectsToRender.add(new RenderEntry(model2, texture));
}
}
for (Edge edge : Edge.values()) {
if (edge.part1 == dir || edge.part2 == dir) {
edgesToRender.remove(edge);
for (PipeMount mount : PipeMount.values()) {
if ((mount.dir == edge.part1 && mount.side == edge.part2) || (mount.dir == edge.part2 && mount.side == edge.part1)) {
mountCanidates.remove(mount);
}
}
}
}
for (Corner corner : Corner.values()) {
if (corner.ew.dir == dir || corner.ns.dir == dir || corner.ud.dir == dir) {
if (!connectionAtCorner.containsKey(corner)) {
connectionAtCorner.put(corner, 1);
} else {
connectionAtCorner.put(corner, connectionAtCorner.get(corner) + 1);
}
}
}
}
}
for (Corner corner : Corner.values()) {
IIconTransformation cornerTexture = LogisticsNewRenderPipe.basicPipeTexture;
if (!renderState.textureMatrix.isHasPower() && renderState.textureMatrix.isRouted()) {
cornerTexture = LogisticsNewRenderPipe.inactiveTexture;
} else if (!renderState.textureMatrix.isRouted() && connectionCount > 2) {
cornerTexture = LogisticsNewRenderPipe.inactiveTexture;
}
int count = connectionAtCorner.containsKey(corner) ? connectionAtCorner.get(corner) : 0;
if (count == 0) {
for (IModel3D model : LogisticsNewRenderPipe.corners_M.get(corner)) {
objectsToRender.add(new RenderEntry(model, new I3DOperation[] { cornerTexture }));
}
} else if (count == 1) {
for (PipeTurnCorner turn : PipeTurnCorner.values()) {
if (turn.corner != corner) {
continue;
}
if (renderState.pipeConnectionMatrix.isConnected(turn.getPointer()) || pipeTile.pipe.hasSpecialPipeEndAt(turn.getPointer())) {
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.spacers.get(turn), new I3DOperation[] { cornerTexture }));
break;
}
}
} else if (count == 2) {
for (PipeTurnCorner turn : PipeTurnCorner.values()) {
if (turn.corner != corner) {
continue;
}
if (!renderState.pipeConnectionMatrix.isConnected(turn.getPointer()) || pipeTile.pipe.hasSpecialPipeEndAt(turn.getPointer())) {
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.corners_I.get(turn), new I3DOperation[] { cornerTexture }));
break;
}
}
} else if (count == 3) {
for (IModel3D model : LogisticsNewRenderPipe.corners_I3.get(corner)) {
objectsToRender.add(new RenderEntry(model, new I3DOperation[] { cornerTexture }));
}
}
}
objectsToRender.addAll(edgesToRender.stream().map(edge -> new RenderEntry(LogisticsNewRenderPipe.edges.get(edge), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture })).collect(Collectors.toList()));
for (int i = 0; i < 6; i += 2) {
ForgeDirection dir = ForgeDirection.getOrientation(i);
List<ForgeDirection> list = new ArrayList<>(Arrays.asList(ForgeDirection.VALID_DIRECTIONS));
list.remove(dir);
list.remove(dir.getOpposite());
if (renderState.pipeConnectionMatrix.isConnected(dir) && renderState.pipeConnectionMatrix.isConnected(dir.getOpposite())) {
boolean found = false;
for (ForgeDirection dir2 : list) {
if (renderState.pipeConnectionMatrix.isConnected(dir2)) {
found = true;
break;
}
}
if (!found) {
switch(dir) {
case DOWN:
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.EAST_SIDE), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.WEST_SIDE), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.NORTH_SIDE), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.SOUTH_SIDE), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
break;
case NORTH:
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.EAST_UP), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.WEST_UP), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.UP_SIDE), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.DOWN_SIDE), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
break;
case WEST:
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.UP_UP), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.DOWN_UP), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.NORTH_UP), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.SOUTH_UP), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
break;
default:
break;
}
}
}
}
boolean[] solidSides = new boolean[6];
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
DoubleCoordinates pos = CoordinateUtils.add(new DoubleCoordinates((TileEntity) pipeTile), dir);
Block blockSide = pos.getBlock(pipeTile.getWorldObj());
if (blockSide == null || !blockSide.isSideSolid(pipeTile.getWorldObj(), pos.getXInt(), pos.getYInt(), pos.getZInt(), dir.getOpposite()) || renderState.pipeConnectionMatrix.isConnected(dir)) {
Iterator<PipeMount> iter = mountCanidates.iterator();
while (iter.hasNext()) {
PipeMount mount = iter.next();
if (mount.dir == dir) {
iter.remove();
}
}
} else {
solidSides[dir.ordinal()] = true;
}
}
if (!mountCanidates.isEmpty()) {
if (solidSides[ForgeDirection.DOWN.ordinal()]) {
findOponentOnSameSide(mountCanidates, ForgeDirection.DOWN);
} else if (solidSides[ForgeDirection.UP.ordinal()]) {
findOponentOnSameSide(mountCanidates, ForgeDirection.UP);
} else {
removeFromSide(mountCanidates, ForgeDirection.DOWN);
removeFromSide(mountCanidates, ForgeDirection.UP);
if (mountCanidates.size() > 2) {
removeIfHasOponentSide(mountCanidates);
}
if (mountCanidates.size() > 2) {
removeIfHasConnectedSide(mountCanidates);
}
if (mountCanidates.size() > 2) {
findOponentOnSameSide(mountCanidates, mountCanidates.get(0).dir);
}
}
if (LPConstants.DEBUG && mountCanidates.size() > 2) {
new RuntimeException("Trying to render " + mountCanidates.size() + " Mounts").printStackTrace();
}
objectsToRender.addAll(mountCanidates.stream().map(mount -> new RenderEntry(LogisticsNewRenderPipe.mounts.get(mount), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture })).collect(Collectors.toList()));
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (!renderState.pipeConnectionMatrix.isConnected(dir)) {
for (IModel3D model : LogisticsNewRenderPipe.texturePlate_Outer.get(dir)) {
IIconTransformation icon = Textures.LPnewPipeIconProvider.getIcon(renderState.textureMatrix.getTextureIndex());
if (icon != null) {
objectsToRender.add(new RenderEntry(model, new I3DOperation[] { icon }));
}
}
}
}
if (renderState.textureMatrix.isFluid()) {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (!renderState.pipeConnectionMatrix.isConnected(dir)) {
objectsToRender.addAll(LogisticsNewRenderPipe.texturePlate_Inner.get(dir).stream().map(model -> new RenderEntry(model, new I3DOperation[] { LogisticsNewRenderPipe.glassCenterTexture })).collect(Collectors.toList()));
} else {
if (!renderState.textureMatrix.isRoutedInDir(dir)) {
objectsToRender.addAll(LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue1().stream().map(model -> new RenderEntry(model, new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture })).collect(Collectors.toList()));
}
}
}
}
}
use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.
the class PathFinder method getConnectedRoutingPipes.
private HashMap<CoreRoutedPipe, ExitRoute> getConnectedRoutingPipes(IPipeInformationProvider startPipe, EnumSet<PipeRoutingConnectionType> connectionFlags, ForgeDirection side) {
HashMap<CoreRoutedPipe, ExitRoute> foundPipes = new HashMap<>();
boolean root = setVisited.size() == 0;
//Reset visited count at top level
if (setVisited.size() == 1) {
pipesVisited = 0;
}
//Break recursion if we have visited a set number of pipes, to prevent client hang if pipes are weirdly configured
if (++pipesVisited > maxVisited) {
return foundPipes;
}
//Break recursion after certain amount of nodes visited
if (setVisited.size() > 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() && setVisited.size() != 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(), ForgeDirection.UNKNOWN, 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());
// 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<Pair<TileEntity, ForgeDirection>> connections = new ArrayDeque<>();
//Recurse in all directions
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (root && !ForgeDirection.UNKNOWN.equals(side) && !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 (OrientationsUtil.isSide(direction)) {
if (root && 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))));
}
}
if (root && 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 Pair<>(tile, direction));
}
while (!connections.isEmpty()) {
Pair<TileEntity, ForgeDirection> pair = connections.pollFirst();
TileEntity tile = pair.getValue1();
ForgeDirection direction = pair.getValue2();
EnumSet<PipeRoutingConnectionType> nextConnectionFlags = EnumSet.copyOf(connectionFlags);
boolean isDirectConnection = false;
int resistance = 0;
if (root) {
Collection<TileEntity> list = SimpleServiceLocator.specialtileconnection.getConnectedPipes(tile);
if (!list.isEmpty()) {
connections.addAll(list.stream().map(pipe -> new Pair<>(pipe, direction)).collect(Collectors.toList()));
listTileEntity(tile);
continue;
}
if (!startPipe.getRoutingPipe().getUpgradeManager().hasPowerPassUpgrade()) {
nextConnectionFlags.remove(PipeRoutingConnectionType.canPowerSubSystemFrom);
}
}
if (tile instanceof IInventory && startPipe.isRoutingPipe() && startPipe.getRoutingPipe() instanceof IDirectRoutingConnection && startPipe.canConnect(tile, direction, false)) {
if (SimpleServiceLocator.connectionManager.hasDirectConnection(startPipe.getRoutingPipe().getRouter())) {
CoreRoutedPipe CRP = SimpleServiceLocator.connectionManager.getConnectedPipe(startPipe.getRoutingPipe().getRouter());
if (CRP != null) {
tile = CRP.container;
isDirectConnection = true;
resistance = ((IDirectRoutingConnection) startPipe.getRoutingPipe()).getConnectionResistance();
}
}
}
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);
// DON'T USE THIS ANYMORE CAN CAUSE TROUBLE WITH MULTIBLOCKS
tile = null;
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 != pair.getValue2() && !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.isOutputOpen(direction)) {
nextConnectionFlags.remove(PipeRoutingConnectionType.canRouteTo);
}
}
if (currentPipe.isOnewayPipe()) {
nextConnectionFlags.remove(PipeRoutingConnectionType.canPowerSubSystemFrom);
if (!currentPipe.isOutputOpen(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() + 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;
}
use of network.rs485.logisticspipes.world.DoubleCoordinates 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);
}
Aggregations