コード例 #1
0
ファイル: SimpleNetwork.java プロジェクト: rooma92/Terasology
 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;
 }
コード例 #2
0
ファイル: SimpleNetwork.java プロジェクト: rooma92/Terasology
 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;
 }
コード例 #3
0
ファイル: SimpleNetwork.java プロジェクト: rooma92/Terasology
 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);
     }
   }
 }
コード例 #4
0
 private boolean processOutputForSetResetGate(EntityRef blockEntity) {
   SignalConsumerAdvancedStatusComponent consumerAdvancedStatusComponent =
       blockEntity.getComponent(SignalConsumerAdvancedStatusComponent.class);
   EnumSet<Side> signals = SideBitFlag.getSides(consumerAdvancedStatusComponent.sidesWithSignals);
   SignalProducerComponent producerComponent =
       blockEntity.getComponent(SignalProducerComponent.class);
   int resultSignal = producerComponent.signalStrength;
   if (signals.contains(Side.TOP) || signals.contains(Side.BOTTOM)) {
     resultSignal = 0;
   } else if (signals.size() > 0) {
     resultSignal = -1;
   }
   if (producerComponent.signalStrength != resultSignal) {
     producerComponent.signalStrength = resultSignal;
     blockEntity.saveComponent(producerComponent);
     if (resultSignal != 0) {
       if (!blockEntity.hasComponent(SignalProducerModifiedComponent.class)) {
         blockEntity.addComponent(new SignalProducerModifiedComponent());
       }
     } else if (blockEntity.hasComponent(SignalProducerModifiedComponent.class)) {
       blockEntity.removeComponent(SignalProducerModifiedComponent.class);
     }
     return true;
   }
   return false;
 }
コード例 #5
0
ファイル: SimpleNetwork.java プロジェクト: rooma92/Terasology
  @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;
    }
  }