3 import org.bukkit.block.Block;
4 import org.bukkit.util.NumberConversions;
5 import org.bukkit.util.Vector;
26 public Location(
final World world,
final double x,
final double y,
final double z) {
27 this(world, x, y, z, 0, 0);
40 public Location(
final World world,
final double x,
final double y,
final double z,
final float yaw,
final float pitch) {
90 public void setX(
double x) {
213 double rotX = this.
getYaw();
216 vector.
setY(-Math.sin(Math.toRadians(rotY)));
218 double h = Math.cos(Math.toRadians(rotY));
220 vector.
setX(-h * Math.sin(Math.toRadians(rotX)));
221 vector.
setZ(h * Math.cos(Math.toRadians(rotX)));
236 throw new IllegalArgumentException(
"Cannot add Locations of differing worlds");
253 this.x += vec.
getX();
254 this.y += vec.
getY();
255 this.z += vec.
getZ();
285 throw new IllegalArgumentException(
"Cannot add Locations of differing worlds");
302 this.x -= vec.
getX();
303 this.y -= vec.
getY();
304 this.z -= vec.
getZ();
337 return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2));
348 return Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2);
377 throw new IllegalArgumentException(
"Cannot measure distance to a null location");
379 throw new IllegalArgumentException(
"Cannot measure distance to a null world");
381 throw new IllegalArgumentException(
"Cannot measure distance between " +
getWorld().getName() +
" and " + o.
getWorld().
getName());
384 return Math.pow(x - o.x, 2) + Math.pow(y - o.y, 2) + Math.pow(z - o.z, 2);
420 if (getClass() != obj.getClass()) {
425 if (this.world != other.world && (
this.world == null || !
this.world.equals(other.world))) {
428 if (Double.doubleToLongBits(
this.x) != Double.doubleToLongBits(other.x)) {
431 if (Double.doubleToLongBits(
this.y) != Double.doubleToLongBits(other.y)) {
434 if (Double.doubleToLongBits(
this.z) != Double.doubleToLongBits(other.z)) {
437 if (Float.floatToIntBits(
this.pitch) != Float.floatToIntBits(other.pitch)) {
440 if (Float.floatToIntBits(
this.yaw) != Float.floatToIntBits(other.yaw)) {
450 hash = 19 * hash + (this.world != null ? this.world.hashCode() : 0);
451 hash = 19 * hash + (int) (Double.doubleToLongBits(
this.x) ^ (Double.doubleToLongBits(this.x) >>> 32));
452 hash = 19 * hash + (int) (Double.doubleToLongBits(
this.y) ^ (Double.doubleToLongBits(this.y) >>> 32));
453 hash = 19 * hash + (int) (Double.doubleToLongBits(
this.z) ^ (Double.doubleToLongBits(this.z) >>> 32));
454 hash = 19 * hash + Float.floatToIntBits(this.pitch);
455 hash = 19 * hash + Float.floatToIntBits(this.yaw);
461 return "Location{" +
"world=" + world +
",x=" + x +
",y=" + y +
",z=" + z +
",pitch=" + pitch +
",yaw=" + yaw +
'}';
470 return new Vector(x, y, z);
477 }
catch (CloneNotSupportedException e) {