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