Advertisement
Guest User

Untitled

a guest
Sep 14th, 2011
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.56 KB | None | 0 0
  1.     private PathEntity createEntityPathTo(Entity entity, double d, double d1,
  2.             double d2, float f) {
  3.         path.clearPath();
  4.         pointMap.clearMap();
  5.         PathPoint pathpoint = openPoint(
  6.                 MathHelper.floor_double(entity.boundingBox.minX),
  7.                 MathHelper.floor_double(entity.boundingBox.minY),
  8.                 MathHelper.floor_double(entity.boundingBox.minZ));
  9.         PathPoint pathpoint1 = openPoint(
  10.                 MathHelper.floor_double(d - (entity.width / 2.0F)),
  11.                 MathHelper.floor_double(d1),
  12.                 MathHelper.floor_double(d2 - (entity.width / 2.0F)));
  13.         PathPoint pathpoint2 = new PathPoint(
  14.                 MathHelper.floor_float(entity.width + 1.0F),
  15.                 MathHelper.floor_float(entity.height + 1.0F),
  16.                 MathHelper.floor_float(entity.width + 1.0F));
  17.         PathEntity pathentity = addToPath(entity, pathpoint, pathpoint1,
  18.                 pathpoint2, f);
  19.         return pathentity;
  20.     }
  21.  
  22.     private PathEntity addToPath(Entity entity, PathPoint pathpoint,
  23.             PathPoint pathpoint1, PathPoint pathpoint2, float f) {
  24.         pathpoint.totalPathDistance = 0.0F;
  25.         pathpoint.distanceToNext = pathpoint.distanceTo(pathpoint1);
  26.         pathpoint.distanceToTarget = pathpoint.distanceToNext;
  27.         path.clearPath();
  28.         path.addPoint(pathpoint);
  29.         PathPoint pathpoint3 = pathpoint;
  30.         while (!path.isPathEmpty()) {
  31.             PathPoint pathpoint4 = path.dequeue();
  32.             if (pathpoint4.equals(pathpoint1)) {
  33.                 return createEntityPath(pathpoint, pathpoint1);
  34.             }
  35.             if (pathpoint4.distanceTo(pathpoint1) < pathpoint3
  36.                     .distanceTo(pathpoint1)) {
  37.                 pathpoint3 = pathpoint4;
  38.             }
  39.             pathpoint4.isFirst = true;
  40.             int i = findPathOptions(entity, pathpoint4, pathpoint2, pathpoint1,
  41.                     f);
  42.             int j = 0;
  43.             while (j < i) {
  44.                 PathPoint pathpoint5 = pathOptions[j];
  45.                 float f1 = pathpoint4.totalPathDistance
  46.                         + pathpoint4.distanceTo(pathpoint5);
  47.                 if (!pathpoint5.isAssigned()
  48.                         || f1 < pathpoint5.totalPathDistance) {
  49.                     pathpoint5.previous = pathpoint4;
  50.                     pathpoint5.totalPathDistance = f1;
  51.                     pathpoint5.distanceToNext = pathpoint5
  52.                             .distanceTo(pathpoint1);
  53.                     if (pathpoint5.isAssigned()) {
  54.                         path.changeDistance(pathpoint5,
  55.                                 pathpoint5.totalPathDistance
  56.                                         + pathpoint5.distanceToNext);
  57.                     } else {
  58.                         pathpoint5.distanceToTarget = pathpoint5.totalPathDistance
  59.                                 + pathpoint5.distanceToNext;
  60.                         path.addPoint(pathpoint5);
  61.                     }
  62.                 }
  63.                 j++;
  64.             }
  65.         }
  66.         if (pathpoint3 == pathpoint) {
  67.             return null;
  68.         } else {
  69.             return createEntityPath(pathpoint, pathpoint3);
  70.         }
  71.     }
  72.  
  73.     private int findPathOptions(Entity entity, PathPoint pathpoint,
  74.             PathPoint pathpoint1, PathPoint pathpoint2, float f) {
  75.         int i = 0;
  76.         int j = 0;
  77.         if (getVerticalOffset(entity, pathpoint.xCoord, pathpoint.yCoord + 1,
  78.                 pathpoint.zCoord, pathpoint1) == 1) {
  79.             j = 1;
  80.         }
  81.         PathPoint pathpoint3 = getSafePoint(entity, pathpoint.xCoord,
  82.                 pathpoint.yCoord, pathpoint.zCoord + 1, pathpoint1, j);
  83.         PathPoint pathpoint4 = getSafePoint(entity, pathpoint.xCoord - 1,
  84.                 pathpoint.yCoord, pathpoint.zCoord, pathpoint1, j);
  85.         PathPoint pathpoint5 = getSafePoint(entity, pathpoint.xCoord + 1,
  86.                 pathpoint.yCoord, pathpoint.zCoord, pathpoint1, j);
  87.         PathPoint pathpoint6 = getSafePoint(entity, pathpoint.xCoord,
  88.                 pathpoint.yCoord, pathpoint.zCoord - 1, pathpoint1, j);
  89.         if (pathpoint3 != null && !pathpoint3.isFirst
  90.                 && pathpoint3.distanceTo(pathpoint2) < f) {
  91.             pathOptions[i++] = pathpoint3;
  92.         }
  93.         if (pathpoint4 != null && !pathpoint4.isFirst
  94.                 && pathpoint4.distanceTo(pathpoint2) < f) {
  95.             pathOptions[i++] = pathpoint4;
  96.         }
  97.         if (pathpoint5 != null && !pathpoint5.isFirst
  98.                 && pathpoint5.distanceTo(pathpoint2) < f) {
  99.             pathOptions[i++] = pathpoint5;
  100.         }
  101.         if (pathpoint6 != null && !pathpoint6.isFirst
  102.                 && pathpoint6.distanceTo(pathpoint2) < f) {
  103.             pathOptions[i++] = pathpoint6;
  104.         }
  105.         return i;
  106.     }
  107.  
  108.     private PathPoint getSafePoint(Entity entity, int i, int j, int k,
  109.             PathPoint pathpoint, int l) {
  110.         PathPoint pathpoint1 = null;
  111.         if (getVerticalOffset(entity, i, j, k, pathpoint) == 1) {
  112.             pathpoint1 = openPoint(i, j, k);
  113.         }
  114.         if (pathpoint1 == null && l > 0
  115.                 && getVerticalOffset(entity, i, j + l, k, pathpoint) == 1) {
  116.             pathpoint1 = openPoint(i, j + l, k);
  117.             j += l;
  118.         }
  119.         if (pathpoint1 != null) {
  120.             int i1 = 0;
  121.             int j1 = 0;
  122.             do {
  123.                 if (j <= 0
  124.                         || (j1 = getVerticalOffset(entity, i, j - 1, k,
  125.                                 pathpoint)) != 1) {
  126.                     break;
  127.                 }
  128.                 if (++i1 >= 4) {
  129.                     return null;
  130.                 }
  131.                 if (--j > 0) {
  132.                     pathpoint1 = openPoint(i, j, k);
  133.                 }
  134.             } while (true);
  135.             if (j1 == -2) {
  136.                 return null;
  137.             }
  138.         }
  139.         return pathpoint1;
  140.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement