Beispiel #1
0
  public void refreshOxygenTiles() {
    try {
      Iterator<ITransmitter> it = this.pipes.iterator();

      while (it.hasNext()) {
        ITransmitter transmitter = it.next();

        if (transmitter == null
            || ((TileEntity) transmitter).isInvalid()
            || ((TileEntity) transmitter).getWorldObj() == null) {
          it.remove();
          continue;
        }

        // This causes problems with Sealed Oxygen Pipes (and maybe also unwanted chunk loading)
        /*                if (!(((TileEntity) transmitter).getWorldObj().getBlock(((TileEntity) transmitter).xCoord, ((TileEntity) transmitter).yCoord, ((TileEntity) transmitter).zCoord) instanceof BlockTransmitter))
                        {
                            it.remove();
                            continue;
                        }
        */
        for (int i = 0; i < transmitter.getAdjacentConnections().length; i++) {
          TileEntity acceptor = transmitter.getAdjacentConnections()[i];

          if (!(acceptor instanceof ITransmitter) && acceptor instanceof IConnector) {
            this.oxygenTiles.put(acceptor, ForgeDirection.getOrientation(i));
          }
        }
      }
    } catch (Exception e) {
      FMLLog.severe("Failed to refresh oxygen pipe network.");
      e.printStackTrace();
    }
  }
Beispiel #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();
              }
            }
          }
        }
      }
    }
  }