Package com.bergerkiller.bukkit.tc.utils

Examples of com.bergerkiller.bukkit.tc.utils.TrackIterator


   * the Minecart is moving.
   *
   * @return forward track iterator
   */
  public TrackIterator getTrackIterator() {
    return new TrackIterator(this.block, this.owner.getDirectionTo());
  }
View Full Code Here


    private final TrackIterator iter;
    private final BlockFace startDir;
    private final PathNode startNode;

    public PathFindOperation(PathNode startNode, Block startBlock, BlockFace startFace) {
      this.iter = new TrackIterator(startBlock, startFace);
      this.startDir = startFace;
      this.startNode = startNode;
    }
View Full Code Here

  private CartToStationInfo getCartToStationInfo() {
    MinecartMember<?> member = getCenterCart();
    CartToStationInfo info = new CartToStationInfo();
    info.cartBlock = member.getBlock();
    BlockFace[] possible = RailType.getType(info.cartBlock).getPossibleDirections(info.cartBlock);
    TrackIterator iter = new TrackIterator(null, null, (int) member.getGroup().length(), true);
    info.distance = Integer.MAX_VALUE;
    for (BlockFace dir : possible) {
      iter.reset(info.cartBlock, dir);
      if (iter.tryFind(this.info.getRails()) && iter.getCartDistance() < info.distance) {
        info.distance = iter.getCartDistance();
        info.cartDir = dir;
        info.centerDir = iter.currentDirection();
      }
    }
    // Adjust the distance based on member-block position
    if (info.cartDir != null) {
      // Adjust for the small offset of the cart from the original block
View Full Code Here

              }
              continue;
            }
          }
          // Curve or other logic - use a Block Iterator for this
          TrackIterator iter = toMember.getRailTracker().getTrackIterator();
          if (iter.hasNext()) {
            // Skip the first block
            iter.next();

            // Go and find the other blocks
            final int maxLength = Math.abs(diff.x) + Math.abs(diff.y) + Math.abs(diff.z);
            for (k = 0; k < maxLength && iter.hasNext(); k++) {
              final Block block = iter.next();
              if (from.x == block.getX() && from.y == block.getY() && from.z == block.getZ()) {
                // Found the end block
                break;
              }
              // Put the member
View Full Code Here

  public boolean handleOccupied() {
    return handleOccupied(this.start, this.direction, this.getMember(), this.maxsize);
  }
  public static boolean handleOccupied(Block start, BlockFace direction, MinecartMember<?> ignore, int maxdistance) {
    TrackIterator iter = new TrackIterator(start, direction);
    while (iter.hasNext() && --maxdistance >= 0) {
      MinecartMember<?> mm = MinecartMemberStore.getAt(iter.next());
      if (mm != null && mm.getGroup() != ignore.getGroup()) {
        ignore.setIgnoreCollisions(true);
        return true;
      }
    }
View Full Code Here

      toCheck = type.getPossibleDirections(railsBlock);
    } else {
      toCheck = new BlockFace[] {direction};
    }
    double length = 0.0;
    TrackIterator iter = new TrackIterator(null, null, 20, false);

    // Check all directions
    for (BlockFace face : toCheck) {
      double trackLength = 0.0;
      iter.reset(railsBlock, face);
      // Skip the start block, abort if no start block was found
      if (iter.hasNext()) {
        iter.next();
      } else {
        continue;
      }
      // Two modes: diagonal and straight
      if (diagonal) {
        // Diagonal mode
        BlockFace lastFace = null;
        int lastAngle = Integer.MAX_VALUE;
        while (iter.hasNext()) {
          iter.next();
          // Check that the direction alternates
          if (lastFace == null) {
            // Start block: store it's information
            lastFace = iter.currentDirection();
          } else {
            BlockFace newFace = iter.currentDirection();
            int newAngle = MathUtil.wrapAngle(FaceUtil.faceToYaw(newFace) - FaceUtil.faceToYaw(lastFace));
            if (Math.abs(newAngle) != 90) {
              // Not a 90-degree angle!
              break;
            }
            if (lastAngle != Integer.MAX_VALUE && newAngle != -lastAngle) {
              // Not the exact opposite from last time
              break;
            }
            lastFace = newFace;
            lastAngle = newAngle;
          }
          trackLength += MathUtil.HALFROOTOFTWO;
        }
      } else {
        // Straight mode
        while (iter.hasNext()) {
          iter.next();
          // Check that the direction stays the same
          if (iter.currentDirection() != face) {
            break;
          }
          trackLength++;
        }
      }
View Full Code Here

        locs[0] = info.getCenterLocation();
        if (MinecartMemberStore.getAt(locs[0]) == null) {
          for (BlockFace direction : info.getWatchedDirections()) {
            direction = direction.getOppositeFace();
            spawnDirection = direction;
            TrackIterator iter = new TrackIterator(info.getRails(), direction);
            // Ignore the starting block
            iter.next();
            // Next block available?
            if (iter.hasNext()) {
              break;
            }
          }
        }
      } else {
        // Multiple-minecart spawning logic
        for (BlockFace direction : info.getWatchedDirections()) {
          direction = direction.getOppositeFace();
          TrackWalkIterator iter = new TrackWalkIterator(info.getCenterLocation(), direction);
          boolean occupied = false;
          for (int i = 0; i < types.size(); i++) {
            if (!iter.hasNext()) {
              occupied = true;
              break;
            }
            locs[i] = iter.next();
            //not taken?
            if (MinecartMemberStore.getAt(locs[i]) != null) {
              occupied = true;
              break;
            }
View Full Code Here

    //find out which direction is best for this occasion
    BlockFace rval = possible[0];
    int dist = 0;
    int i = 0;
    for (BlockFace f : possible) {
      TrackIterator iter = new TrackIterator(destrail, f);
      final int lim = 4;
      for (i = 0; i < lim && iter.hasNext(); i++) iter.next();
      if (i > dist) {
        rval = f;
        dist = i;
      }
    }
View Full Code Here

TOP

Related Classes of com.bergerkiller.bukkit.tc.utils.TrackIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.