Exemplo n.º 1
0
  /**
   * Set the values, all constructors uses this function
   *
   * @param loc location of the view
   * @param maxDistance how far it checks for blocks
   * @param viewHeight where the view is positioned in y-axis
   * @param checkDistance how often to check for blocks, the smaller the more precise
   */
  private void setValues(
      Location loc,
      int maxDistance,
      double viewHeight,
      double checkDistance,
      TIntHashSet transparent) {
    this.maxDistance = maxDistance;
    this.checkDistance = checkDistance;
    curDistance = 0;
    int xRotation = (int) (loc.getYaw() + 90) % 360;
    int yRotation = (int) loc.getPitch() * -1;

    double h = checkDistance * Math.cos(Math.toRadians(yRotation));

    offset =
        new Vector(
            (h * Math.cos(Math.toRadians(xRotation))),
            (checkDistance * Math.sin(Math.toRadians(yRotation))),
            (h * Math.sin(Math.toRadians(xRotation))));

    targetPosDouble = loc.add(0, viewHeight, 0).toVector();
    targetPos = targetPosDouble.toBlockVector();
    prevPos = targetPos;
    transparentBlocks = transparent;
    if (transparentBlocks == null) {
      transparentBlocks = new TIntHashSet(new int[] {0});
    }
  }
Exemplo n.º 2
0
  /**
   * Get next block
   *
   * @return next block position
   */
  public boolean getNextBlock() {
    prevPos = targetPos;
    do {
      curDistance += checkDistance;

      targetPosDouble.add(offset);
      targetPos = targetPosDouble.toBlockVector();
    } while (curDistance <= maxDistance
        && targetPos.getBlockX() == prevPos.getBlockX()
        && targetPos.getBlockY() == prevPos.getBlockY()
        && targetPos.getBlockZ() == prevPos.getBlockZ());

    if (curDistance > maxDistance) {
      return false;
    }

    return true;
  }