Bukkit  1.4.7-R1.0
 All Classes Namespaces Files Functions Variables Enumerator Pages
BlockVector.java
Go to the documentation of this file.
1 package org.bukkit.util;
2 
3 import java.util.Map;
4 import org.bukkit.configuration.serialization.SerializableAs;
5 
12 @SerializableAs("BlockVector")
13 public class BlockVector extends Vector {
14 
18  public BlockVector() {
19  this.x = 0;
20  this.y = 0;
21  this.z = 0;
22  }
23 
29  public BlockVector(Vector vec) {
30  this.x = vec.getX();
31  this.y = vec.getY();
32  this.z = vec.getZ();
33  }
34 
42  public BlockVector(int x, int y, int z) {
43  this.x = x;
44  this.y = y;
45  this.z = z;
46  }
47 
55  public BlockVector(double x, double y, double z) {
56  this.x = x;
57  this.y = y;
58  this.z = z;
59  }
60 
68  public BlockVector(float x, float y, float z) {
69  this.x = x;
70  this.y = y;
71  this.z = z;
72  }
73 
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 
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 
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 }