コード例 #1
0
 @Override
 public void updateEntity() {
   if (worldObj.isRemote) return;
   if (_network != null && _network.isInvalid()) {
     _network = null;
     _needsNetworkUpdate = true;
   }
   if (_needsNetworkUpdate) {
     _needsNetworkUpdate = false;
     updateNetwork();
   }
   _network.tick();
 }
コード例 #2
0
  private void updateNearbyNode(BlockPosition bp) {
    int subnet = getSideColor(bp.orientation);
    RedNetConnectionType connectionType = getConnectionState(bp.orientation);

    if (!worldObj.isAirBlock(bp.x, bp.y, bp.z)) {
      if (connectionType.isAllSubnets) {
        _network.addOrUpdateNode(bp);
      } else if (connectionType.isCable) {
        _network.addOrUpdateNode(bp, subnet, false);
      } else if (connectionType.isPlate) {
        _network.addOrUpdateNode(bp, subnet, true);
      } else {
        _network.removeNode(bp);
      }
    } else {
      _network.removeNode(bp);
    }
  }
コード例 #3
0
  private void updateNetwork() {
    if (worldObj.isRemote) {
      return;
    }

    BlockPosition ourbp = new BlockPosition(this);
    RedstoneNetwork.log("Cable at %s updating network", ourbp.toString());

    if (_network == null) {
      for (BlockPosition bp : ourbp.getAdjacent(true)) {
        TileEntity te = bp.getTileEntity(worldObj);
        if (te instanceof TileEntityRedNetCable) {
          TileEntityRedNetCable cable = ((TileEntityRedNetCable) te);
          if (cable.getNetwork() != null && !cable.getNetwork().isInvalid()) {
            _network = cable.getNetwork();
            break;
          }
        }
      }
    }
    if (_network == null) {
      RedstoneNetwork.log("Initializing new network at %s", ourbp.toString());
      setNetwork(new RedstoneNetwork(worldObj));
    }
    for (BlockPosition bp : ourbp.getAdjacent(true)) {
      TileEntity te = bp.getTileEntity(worldObj);
      if (te instanceof TileEntityRedNetCable) {
        TileEntityRedNetCable cable = ((TileEntityRedNetCable) te);
        if (cable.getNetwork() == null) {
          cable.setNetwork(_network);
        } else if (cable.getNetwork() != _network
            && cable.getNetwork() != null
            && !cable.getNetwork().isInvalid()) {
          _network.mergeNetwork(cable.getNetwork());
        }
      } else {
        updateNearbyNode(bp);
      }
    }
  }
コード例 #4
0
 public void setNetwork(RedstoneNetwork network) {
   _network = network;
   _network.addCable(new BlockPosition(this));
 }