Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package org.bukkit.util;
2
3/**
4 * A vector with a hash function that floors the X, Y, Z components, a la
5 * BlockVector in WorldEdit. BlockVectors can be used in hash sets and
6 * hash maps. Be aware that BlockVectors are mutable, but it is important
7 * that BlockVectors are never changed once put into a hash set or hash map.
8 *
9 * @author sk89q
10 */
11public class BlockVector extends Vector {
12
13 /**
14 * Construct the vector with all components as 0.
15 */
16 public BlockVector() {
17 this.x = 0;
18 this.y = 0;
19 this.z = 0;
20 }
21
22 /**
23 * Construct the vector with another vector.
24 */
25 public BlockVector(Vector vec) {
26 this.x = vec.getX();
27 this.y = vec.getY();
28 this.z = vec.getZ();
29 }
30
31 /**
32 * Construct the vector with provided integer components.
33 *
34 * @param x
35 * @param y
36 * @param z
37 */
38 public BlockVector(int x, int y, int z) {
39 this.x = x;
40 this.y = y;
41 this.z = z;
42 }
43
44 /**
45 * Construct the vector with provided double components.
46 *
47 * @param x
48 * @param y
49 * @param z
50 */
51 public BlockVector(double x, double y, double z) {
52 this.x = x;
53 this.y = y;
54 this.z = z;
55 }
56
57 /**
58 * Construct the vector with provided float components.
59 *
60 * @param x
61 * @param y
62 * @param z
63 */
64 public BlockVector(float x, float y, float z) {
65 this.x = x;
66 this.y = y;
67 this.z = z;
68 }
69
70 /**
71 * Checks if another object is equivalent.
72 *
73 * @param obj
74 * @return whether the other object is equivalent
75 */
76 @Override
77 public boolean equals(Object obj) {
78 if (!(obj instanceof BlockVector)) {
79 return false;
80 }
81 BlockVector other = (BlockVector) obj;
82
83 return (int) other.getX() == (int) this.x && (int) other.getY() == (int) this.y && (int) other.getZ() == (int) this.z;
84
85 }
86
87 /**
88 * Returns a hash code for this vector.
89 *
90 * @return hash code
91 */
92 @Override
93 public int hashCode() {
94 return (Integer.valueOf((int) x).hashCode() >> 13) ^ (Integer.valueOf((int) y).hashCode() >> 7) ^ Integer.valueOf((int) z).hashCode();
95 }
96
97 /**
98 * Get a new block vector.
99 *
100 * @return vector
101 */
102 @Override
103 public BlockVector clone() {
104 BlockVector v = (BlockVector) super.clone();
105
106 v.x = x;
107 v.y = y;
108 v.z = z;
109 return v;
110 }
111}