@@ -91,7 +91,7 @@ public void swing() {
9191 }
9292
9393 public void centerPosition () {
94- //return;
94+ // return;
9595 double dx = pos .x > 0 ? Math .floor (pos .x ) + 0.5d : Math .round (pos .x ) - 0.5d ;
9696 double dy = Math .floor (pos .y );
9797 double dz = pos .z > 0 ? Math .floor (pos .z ) + 0.5d : Math .round (pos .z ) - 0.5d ;
@@ -248,7 +248,12 @@ private boolean isDiagonal(double x, double y, double z) {
248248 return false ;
249249 }
250250
251- public void breakBlock (int rx , int ry , int rz ) {
251+ public void breakBlockAbsolute (Vector3d a ) {
252+ Vector3d r = absoluteToRelative (a );
253+ breakBlock (r .x , r .y , r .z );
254+ }
255+
256+ public void breakBlock (double rx , double ry , double rz ) {
252257 final Position p = new Position ((int ) Math .floor (pos .x + rx ), (int ) Math .floor (pos .y + ry ),
253258 (int ) Math .floor (pos .z + rz ));
254259 // PhaseBot.getConsole().println("Digging at: " + p.getX() + " " +
@@ -266,6 +271,10 @@ public Vector3d relativeToAbsolute(Vector3d d) {
266271 return new Vector3d (pos .x + d .x , pos .y + d .y , pos .z + d .z );
267272 }
268273
274+ public Vector3d absoluteToRelative (Vector3d a ) {
275+ return new Vector3d (pos .x - a .x , pos .y - a .y , pos .z - a .z );
276+ }
277+
269278 public Face getPlaceFace (Vector3d d ) {
270279 for (int x = -1 ; x < 2 ; x ++) {
271280 for (int y = -1 ; y < 2 ; y ++) {
@@ -285,6 +294,10 @@ public Face getPlaceFace(Vector3d d) {
285294 return Face .INVALID ;
286295 }
287296
297+ public void placeBlockAbsolute (Vector3d location ) {
298+ placeBlock (absoluteToRelative (location ));
299+ }
300+
288301 public void placeBlock (Vector3d location ) {
289302 Face face = Face .INVALID ;
290303 Vector3d blockLocation = null ;
@@ -398,7 +411,82 @@ public void setSlot(int i) {
398411 look (yaw , pitch );
399412 }
400413
414+ public void getCloseToAbsolute (Vector3d a ) {
415+ getCloseTo (absoluteToRelative (a ));
416+ }
417+
418+ public void getCloseTo (Vector3d r ) {
419+ double tx = pos .x + r .x ;
420+ double ty = pos .y + r .y ;
421+ double tz = pos .z + r .z ;
422+ double distance = Math .sqrt (Math .pow (pos .x - tx , 2 ) + Math .pow (pos .y - ty , 2 ) + Math .pow (pos .z - tz , 2 ));
423+ if (distance > 4 ) {
424+ move (r .x , r .y , r .z );
425+ /*
426+ * @formatter:off
427+ * try {
428+ System.out.println(tx + " " + ty + " " + tz);
429+ AStar path = new AStar(new Vector3d(pos.x, pos.y, pos.z), new Vector3d(tx, ty, tz), 100);
430+ ArrayList<Tile> route = path.iterate();
431+ PathingResult result = path.getPathingResult();
432+ switch (result) {
433+ case SUCCESS:
434+ // Path was successful. Do something here.
435+ PhaseBot.getBot().moveAlong(route);
436+ break;
437+ case NO_PATH:
438+ default:
439+ break;
440+ }
441+ }
442+ catch (Exception e) {
443+ e.printStackTrace();
444+ }
445+ @formatter:on
446+ */
447+ }
448+ }
449+
401450 public void openChest () {
402451 // client.getSession().send(new Client);
403452 }
404- }
453+
454+ public double getRelativeDistanceAway (Vector3d r ) {
455+ return getDistanceAway (relativeToAbsolute (r ));
456+ }
457+
458+ public double getDistanceAway (Vector3d l ) {
459+ return Math .sqrt (Math .pow (pos .x - l .x , 2 ) + Math .pow (pos .y - l .y , 2 ) + Math .pow (pos .z - l .z , 2 ));
460+ }
461+
462+ public Block getClosestBlock (Material material , int range ) {
463+ ArrayList <Block > matches = new ArrayList <Block >();
464+ for (int x = 0 ; x < range ; x ++) {
465+ for (int y = 0 ; y < range ; y ++) {
466+ for (int z = 0 ; z < range ; z ++) {
467+ Block b ; // cache
468+ if ((b = Block .getBlock (pos .x + x , pos .y + x , pos .z + z )).getMaterial () == material ) {
469+ matches .add (b );
470+ }
471+ }
472+ }
473+ }
474+ double shortestDistance = range ;
475+ Block best = null ;
476+ for (Block g : matches ) {
477+ if (shortestDistance == range ) {
478+ best = g ;
479+ shortestDistance = getDistanceAway (g .getPos ());
480+ }
481+ else {
482+ double d ; // cache
483+ if ((d = getDistanceAway (g .getPos ())) < shortestDistance ) {
484+ best = g ;
485+ shortestDistance = d ;
486+ }
487+ }
488+ }
489+ System .out .println (best .getPos ());
490+ return best ;
491+ }
492+ }
0 commit comments