Example #1
0
  @Override
  public byte getLeafSidesInNetwork(NetworkNode networkNode) {
    if (!hasLeafNode(networkNode))
      throw new IllegalArgumentException("Cannot test nodes not in network");

    if (networkingNodes.size() == 0) {
      // Degenerated network
      for (Side connectingOnSide : SideBitFlag.getSides(networkNode.connectionSides)) {
        Vector3i possibleLocation = networkNode.location.toVector3i();
        possibleLocation.add(connectingOnSide.getVector3i());
        for (NetworkNode node : leafNodes.get(new ImmutableBlockLocation(possibleLocation))) {
          if (SideBitFlag.hasSide(node.connectionSides, connectingOnSide.reverse())) {
            return SideBitFlag.getSide(connectingOnSide);
          }
        }
      }

      return 0;
    } else {
      byte result = 0;
      for (Side connectingOnSide : SideBitFlag.getSides(networkNode.connectionSides)) {
        Vector3i possibleLocation = networkNode.location.toVector3i();
        possibleLocation.add(connectingOnSide.getVector3i());
        for (NetworkNode node : networkingNodes.get(new ImmutableBlockLocation(possibleLocation))) {
          if (SideBitFlag.hasSide(node.connectionSides, connectingOnSide.reverse())) {
            result += SideBitFlag.getSide(connectingOnSide);
          }
        }
      }

      return result;
    }
  }
Example #2
0
 public static boolean areNodesConnecting(NetworkNode node1, NetworkNode node2) {
   for (Side side : SideBitFlag.getSides(node1.connectionSides)) {
     final ImmutableBlockLocation possibleConnectedLocation = node1.location.move(side);
     if (node2.location.equals(possibleConnectedLocation)
         && SideBitFlag.hasSide(node2.connectionSides, side.reverse())) return true;
   }
   return false;
 }
Example #3
0
 private boolean canConnectToNetworkingNode(NetworkNode networkNode) {
   for (Side connectingOnSide : SideBitFlag.getSides(networkNode.connectionSides)) {
     final ImmutableBlockLocation possibleConnectionLocation =
         networkNode.location.move(connectingOnSide);
     for (NetworkNode possibleConnectedNode : networkingNodes.get(possibleConnectionLocation)) {
       if (SideBitFlag.hasSide(possibleConnectedNode.connectionSides, connectingOnSide.reverse()))
         return true;
     }
   }
   return false;
 }
Example #4
0
 private void listConnectedNotVisitedNetworkingNodes(
     Set<NetworkNode> visitedNodes, NetworkNode location, Collection<NetworkNode> result) {
   for (Side connectingOnSide : SideBitFlag.getSides(location.connectionSides)) {
     final ImmutableBlockLocation possibleConnectionLocation =
         location.location.move(connectingOnSide);
     for (NetworkNode possibleConnection : networkingNodes.get(possibleConnectionLocation)) {
       if (!visitedNodes.contains(possibleConnection)
           && SideBitFlag.hasSide(possibleConnection.connectionSides, connectingOnSide.reverse()))
         result.add(possibleConnection);
     }
   }
 }