| 1 | package net.minecraft.util;
|
| 2 |
|
| 3 | import com.google.common.base.Objects;
|
| 4 |
|
| 5 | public class Vec3i implements Comparable<Vec3i>
|
| 6 | {
|
| 7 | /** The Null vector constant (0, 0, 0) */
|
| 8 | public static final Vec3i NULL_VECTOR = new Vec3i(0, 0, 0);
|
| 9 |
|
| 10 | /** X coordinate */
|
| 11 | private final int x;
|
| 12 |
|
| 13 | /** Y coordinate */
|
| 14 | private final int y;
|
| 15 |
|
| 16 | /** Z coordinate */
|
| 17 | private final int z;
|
| 18 |
|
| 19 | public Vec3i(int xIn, int yIn, int zIn)
|
| 20 | {
|
| 21 | this.x = xIn;
|
| 22 | this.y = yIn;
|
| 23 | this.z = zIn;
|
| 24 | }
|
| 25 |
|
| 26 | public Vec3i(double xIn, double yIn, double zIn)
|
| 27 | {
|
| 28 | this(MathHelper.floor_double(xIn), MathHelper.floor_double(yIn), MathHelper.floor_double(zIn));
|
| 29 | }
|
| 30 |
|
| 31 | public boolean equals(Object p_equals_1_)
|
| 32 | {
|
| 33 | if (this == p_equals_1_)
|
| 34 | {
|
| 35 | return true;
|
| 36 | }
|
| 37 | else if (!(p_equals_1_ instanceof Vec3i))
|
| 38 | {
|
| 39 | return false;
|
| 40 | }
|
| 41 | else
|
| 42 | {
|
| 43 | Vec3i vec3i = (Vec3i)p_equals_1_;
|
| 44 | return this.getX() != vec3i.getX() ? false : (this.getY() != vec3i.getY() ? false : this.getZ() == vec3i.getZ());
|
| 45 | }
|
| 46 | }
|
| 47 |
|
| 48 | public int hashCode()
|
| 49 | {
|
| 50 | return (this.getY() + this.getZ() * 31) * 31 + this.getX();
|
| 51 | }
|
| 52 |
|
| 53 | public int compareTo(Vec3i p_compareTo_1_)
|
| 54 | {
|
| 55 | return this.getY() == p_compareTo_1_.getY() ? (this.getZ() == p_compareTo_1_.getZ() ? this.getX() - p_compareTo_1_.getX() : this.getZ() - p_compareTo_1_.getZ()) : this.getY() - p_compareTo_1_.getY();
|
| 56 | }
|
| 57 |
|
| 58 | /**
|
| 59 | * Get the X coordinate
|
| 60 | */
|
| 61 | public int getX()
|
| 62 | {
|
| 63 | return this.x;
|
| 64 | }
|
| 65 |
|
| 66 | /**
|
| 67 | * Get the Y coordinate
|
| 68 | */
|
| 69 | public int getY()
|
| 70 | {
|
| 71 | return this.y;
|
| 72 | }
|
| 73 |
|
| 74 | /**
|
| 75 | * Get the Z coordinate
|
| 76 | */
|
| 77 | public int getZ()
|
| 78 | {
|
| 79 | return this.z;
|
| 80 | }
|
| 81 |
|
| 82 | /**
|
| 83 | * Calculate the cross product of this and the given Vector
|
| 84 | */
|
| 85 | public Vec3i crossProduct(Vec3i vec)
|
| 86 | {
|
| 87 | return new Vec3i(this.getY() * vec.getZ() - this.getZ() * vec.getY(), this.getZ() * vec.getX() - this.getX() * vec.getZ(), this.getX() * vec.getY() - this.getY() * vec.getX());
|
| 88 | }
|
| 89 |
|
| 90 | /**
|
| 91 | * Calculate squared distance to the given coordinates
|
| 92 | */
|
| 93 | public double distanceSq(double toX, double toY, double toZ)
|
| 94 | {
|
| 95 | double d0 = (double)this.getX() - toX;
|
| 96 | double d1 = (double)this.getY() - toY;
|
| 97 | double d2 = (double)this.getZ() - toZ;
|
| 98 | return d0 * d0 + d1 * d1 + d2 * d2;
|
| 99 | }
|
| 100 |
|
| 101 | /**
|
| 102 | * Compute square of distance from point x, y, z to center of this Block
|
| 103 | */
|
| 104 | public double distanceSqToCenter(double xIn, double yIn, double zIn)
|
| 105 | {
|
| 106 | double d0 = (double)this.getX() + 0.5D - xIn;
|
| 107 | double d1 = (double)this.getY() + 0.5D - yIn;
|
| 108 | double d2 = (double)this.getZ() + 0.5D - zIn;
|
| 109 | return d0 * d0 + d1 * d1 + d2 * d2;
|
| 110 | }
|
| 111 |
|
| 112 | /**
|
| 113 | * Calculate squared distance to the given Vector
|
| 114 | */
|
| 115 | public double distanceSq(Vec3i to)
|
| 116 | {
|
| 117 | return this.distanceSq((double)to.getX(), (double)to.getY(), (double)to.getZ());
|
| 118 | }
|
| 119 |
|
| 120 | public String toString()
|
| 121 | {
|
| 122 | return Objects.toStringHelper(this).add("x", this.getX()).add("y", this.getY()).add("z", this.getZ()).toString();
|
| 123 | }
|
| 124 | }
|
| 125 |
|