Example #1
0
  private double calcHorizontalLength() {
    double length = 0.0;
    // Count the amount of horizontal tracks
    final BlockFace[] toCheck;
    if (this.instruction == BlockFace.SELF) {
      toCheck = FaceUtil.getFaces(this.railDirection);
    } else {
      toCheck = new BlockFace[] {this.instruction};
    }
    for (BlockFace face : toCheck) {
      int tlength = 0;
      // Get the type of rail required
      BlockFace checkface = face;
      if (checkface == BlockFace.NORTH) checkface = BlockFace.SOUTH;
      if (checkface == BlockFace.EAST) checkface = BlockFace.WEST;

      Block b = this.railsBlock;
      for (int i = 0; i < 20; i++) {
        // Next until invalid
        b = b.getRelative(face);
        Rails rr = BlockUtil.getRails(b);
        if (rr == null || rr.getDirection() != checkface) {
          break;
        }
        tlength++;
      }
      // Update the length
      if (tlength > length) {
        length = tlength;
      }
    }
    return length;
  }
Example #2
0
  private double calcDiagonalLength() {
    double length = 0.0;
    // Count the amount of zig-zagging curved tracks
    final BlockFace[] toCheck;
    if (this.instruction == BlockFace.SELF) {
      toCheck =
          new BlockFace[] {
            FaceUtil.rotate(this.railDirection, -2), FaceUtil.rotate(this.railDirection, 2)
          };
    } else {
      toCheck = new BlockFace[] {this.instruction};
    }
    for (BlockFace direction : toCheck) {
      double tlength = 0.0;
      // Find out the starting offset
      final BlockFace[] dirs = FaceUtil.getFaces(direction);
      BlockFace[] railDirs = FaceUtil.getFaces(this.railDirection);
      BlockFace railDirection = this.railDirection;

      Block b = this.railsBlock;
      for (int i = 0; i < 20; i++) {
        // Invert the direction
        railDirection = railDirection.getOppositeFace();
        railDirs[0] = railDirs[0].getOppositeFace();
        railDirs[1] = railDirs[1].getOppositeFace();
        // Obtain the new offset
        final BlockFace offset;
        if (LogicUtil.contains(railDirs[0], dirs)) {
          offset = railDirs[0];
        } else {
          offset = railDirs[1];
        }
        // Check if the new block is the expected curve direction
        b = b.getRelative(offset);
        Rails rr = BlockUtil.getRails(b);
        if (rr == null || rr.getDirection() != railDirection) {
          break;
        }
        tlength += MathUtil.HALFROOTOFTWO;
      }

      // Update the length
      if (tlength > length) {
        length = tlength;
      }
    }
    return length;
  }