Esempio n. 1
0
  @Override
  public IOxygenNetwork merge(IOxygenNetwork network) {
    if (network != null && network != this) {
      OxygenNetwork newNetwork = new OxygenNetwork();
      newNetwork.pipes.addAll(this.pipes);
      newNetwork.pipes.addAll(network.getTransmitters());
      newNetwork.refresh();
      return newNetwork;
    }

    return this;
  }
Esempio n. 2
0
  @Override
  public void split(ITransmitter 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).getWorldObj(),
                      (INetworkConnection) connectedBlockB,
                      NetworkType.OXYGEN,
                      splitPoint);
              finder.init(new BlockVec3(connectedBlockA));

              if (finder.results.size() > 0) {
                /**
                 * The connections A and B are still intact elsewhere. Set all references of wire
                 * connection into one network.
                 */
                for (BlockVec3 node : finder.closedSet) {
                  TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).getWorldObj());

                  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.
                 */
                IOxygenNetwork newNetwork = new OxygenNetwork();

                for (BlockVec3 node : finder.closedSet) {
                  TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).getWorldObj());

                  if (nodeTile instanceof INetworkProvider) {
                    if (nodeTile != splitPoint) {
                      newNetwork.getTransmitters().add((ITransmitter) nodeTile);
                    }
                  }
                }

                newNetwork.refresh();
              }
            }
          }
        }
      }
    }
  }