Program: 171565
Project: 171565
Buggy source:
public Vec3d nextPosition(Vec3d position,float trainYaw,Vec3d delta){
  TileRail rail=closeEnoughRailPosition(position,trainYaw);
  if (rail == null) {
    if (!world.isRemote) {
      System.out.println("String_Node_Str");
      System.out.println(position);
      System.out.println(world.getBlockState(new BlockPos(position)).getBlock().getLocalizedName());
      this.position.isOffTrack=true;
      return position;
    }
 else {
      return position.add(delta);
    }
  }
  double distance=delta.lengthVector();
  if (rail.getType().isTurn()) {
    Vec3d posDelta=rail.getCenter().subtractReverse(position);
    double posRelYaw=MathHelper.atan2(posDelta.x,-posDelta.z);
    double radius=rail.getRadius() - 0.5;
    double yawDelt=distance / radius;
    Vec3d nextPos=position.add(delta);
    Vec3d newpos=rail.getCenter().addVector(Math.sin(posRelYaw + yawDelt) * radius,0,-Math.cos(posRelYaw + yawDelt) * radius);
    Vec3d newneg=rail.getCenter().addVector(Math.sin(posRelYaw - yawDelt) * radius,0,-Math.cos(posRelYaw - yawDelt) * radius);
    if (newpos.subtract(nextPos).lengthVector() < newneg.subtract(nextPos).lengthVector()) {
      return newpos;
    }
 else {
      return newneg;
    }
  }
 else   if (rail.getType() == TrackItems.CROSSING) {
    delta=VecUtil.fromYaw(distance,EnumFacing.fromAngle(trainYaw).getHorizontalAngle());
    return position.add(delta);
  }
 else {
    delta=VecUtil.fromYaw(distance,trainYaw);
    float angle=rail.getRotationQuarter() / 4f * 90 + rail.getFacing().getHorizontalAngle();
    Vec3d center=rail.getPlacementPosition();
    double toCenter=center.distanceTo(position);
    Vec3d possiblePositive=center.add(VecUtil.fromYaw(toCenter,angle));
    Vec3d possibleNegative=center.add(VecUtil.fromYaw(-toCenter,angle));
    double angularDistance=0;
    if (possiblePositive.distanceTo(position) < possibleNegative.distanceTo(position)) {
      angularDistance=toCenter;
    }
 else {
      angularDistance=-toCenter;
    }
    possiblePositive=center.add(VecUtil.fromYaw(angularDistance + distance,angle));
    possibleNegative=center.add(VecUtil.fromYaw(angularDistance - distance,angle));
    Vec3d outPosition;
    if (possiblePositive.distanceTo(position.add(delta)) < possibleNegative.distanceTo(position.add(delta))) {
      outPosition=possiblePositive;
    }
 else {
      outPosition=possibleNegative;
    }
    TileRailBase directRail=directRailFromPosition(outPosition);
    if (directRail != null) {
      outPosition=new Vec3d(outPosition.x,directRail.getPos().getY() + directRail.getHeight(),outPosition.z);
    }
 else {
      outPosition=new Vec3d(outPosition.x,position.y,outPosition.z);
    }
    return outPosition;
  }
}

Fixed version (ground truth):
public Vec3d nextPosition(Vec3d position,float trainYaw,Vec3d delta){
  TileRail rail=closeEnoughRailPosition(position,trainYaw);
  if (rail == null) {
    if (!world.isRemote) {
      this.position.isOffTrack=true;
      return position;
    }
 else {
      return position.add(delta);
    }
  }
  double distance=delta.lengthVector();
  if (rail.getType().isTurn()) {
    Vec3d posDelta=rail.getCenter().subtractReverse(position);
    double posRelYaw=MathHelper.atan2(posDelta.x,-posDelta.z);
    double radius=rail.getRadius() - 0.5;
    double yawDelt=distance / radius;
    Vec3d nextPos=position.add(delta);
    Vec3d newpos=rail.getCenter().addVector(Math.sin(posRelYaw + yawDelt) * radius,0,-Math.cos(posRelYaw + yawDelt) * radius);
    Vec3d newneg=rail.getCenter().addVector(Math.sin(posRelYaw - yawDelt) * radius,0,-Math.cos(posRelYaw - yawDelt) * radius);
    if (newpos.subtract(nextPos).lengthVector() < newneg.subtract(nextPos).lengthVector()) {
      return newpos;
    }
 else {
      return newneg;
    }
  }
 else   if (rail.getType() == TrackItems.CROSSING) {
    delta=VecUtil.fromYaw(distance,EnumFacing.fromAngle(trainYaw).getHorizontalAngle());
    return position.add(delta);
  }
 else {
    delta=VecUtil.fromYaw(distance,trainYaw);
    float angle=rail.getRotationQuarter() / 4f * 90 + rail.getFacing().getHorizontalAngle();
    Vec3d center=rail.getPlacementPosition();
    double toCenter=center.distanceTo(position);
    Vec3d possiblePositive=center.add(VecUtil.fromYaw(toCenter,angle));
    Vec3d possibleNegative=center.add(VecUtil.fromYaw(-toCenter,angle));
    double angularDistance=0;
    if (possiblePositive.distanceTo(position) < possibleNegative.distanceTo(position)) {
      angularDistance=toCenter;
    }
 else {
      angularDistance=-toCenter;
    }
    possiblePositive=center.add(VecUtil.fromYaw(angularDistance + distance,angle));
    possibleNegative=center.add(VecUtil.fromYaw(angularDistance - distance,angle));
    Vec3d outPosition;
    if (possiblePositive.distanceTo(position.add(delta)) < possibleNegative.distanceTo(position.add(delta))) {
      outPosition=possiblePositive;
    }
 else {
      outPosition=possibleNegative;
    }
    TileRailBase directRail=directRailFromPosition(outPosition);
    if (directRail != null) {
      outPosition=new Vec3d(outPosition.x,directRail.getPos().getY() + directRail.getHeight(),outPosition.z);
    }
 else {
      outPosition=new Vec3d(outPosition.x,position.y,outPosition.z);
    }
    return outPosition;
  }
}