use of micdoodle8.mods.galacticraft.api.transmission.grid.Pathfinder in project Galacticraft by micdoodle8.
the class FluidNetwork method split.
@Override
public void split(IBufferTransmitter<FluidStack> splitPoint) {
if (splitPoint instanceof TileEntity) {
this.pipes.remove(splitPoint);
/**
* Loop through the connected blocks and attempt to see if there are
* connections between the two points elsewhere.
*/
TileEntity[] connectedBlocks = splitPoint.getAdjacentConnections();
for (TileEntity connectedBlockA : connectedBlocks) {
if (connectedBlockA instanceof INetworkConnection) {
for (final TileEntity connectedBlockB : connectedBlocks) {
if (connectedBlockA != connectedBlockB && connectedBlockB instanceof INetworkConnection) {
Pathfinder finder = new PathfinderChecker(((TileEntity) splitPoint).getWorld(), (INetworkConnection) connectedBlockB, NetworkType.FLUID, splitPoint);
finder.init(new BlockVec3(connectedBlockA));
if (finder.results.size() > 0) {
for (BlockVec3 node : finder.closedSet) {
TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).getWorld());
if (nodeTile instanceof INetworkProvider) {
if (nodeTile != splitPoint) {
((INetworkProvider) nodeTile).setNetwork(this);
}
}
}
} else {
/**
* The connections A and B are not connected
* anymore. Give both of them a new network.
*/
FluidNetwork newNetwork = new FluidNetwork();
for (BlockVec3 node : finder.closedSet) {
TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).getWorld());
if (nodeTile instanceof IBufferTransmitter) {
if (nodeTile != splitPoint) {
newNetwork.pipes.add((IBufferTransmitter<FluidStack>) nodeTile);
newNetwork.pipesAdded.add((IBufferTransmitter<FluidStack>) nodeTile);
newNetwork.onTransmitterAdded((IBufferTransmitter<FluidStack>) nodeTile);
this.pipes.remove(nodeTile);
}
}
}
newNetwork.refresh();
newNetwork.register();
}
}
}
}
}
if (this.pipes.isEmpty()) {
this.unregister();
} else {
this.updateCapacity();
}
}
}
Aggregations