Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3import java.util.ArrayList;
4import java.util.List;
5
6public class Vec3D {
7
8 private static List d = new ArrayList();
9 private static int e = 0;
10 public double a;
11 public double b;
12 public double c;
13
14 public static Vec3D a(double d0, double d1, double d2) {
15 return new Vec3D(d0, d1, d2);
16 }
17
18 public static void a() {
19 e = 0;
20 }
21
22 public static Vec3D create(double d0, double d1, double d2) {
23 if (e >= d.size()) {
24 d.add(a(0.0D, 0.0D, 0.0D));
25 }
26
27 return ((Vec3D) d.get(e++)).e(d0, d1, d2);
28 }
29
30 private Vec3D(double d0, double d1, double d2) {
31 if (d0 == -0.0D) {
32 d0 = 0.0D;
33 }
34
35 if (d1 == -0.0D) {
36 d1 = 0.0D;
37 }
38
39 if (d2 == -0.0D) {
40 d2 = 0.0D;
41 }
42
43 this.a = d0;
44 this.b = d1;
45 this.c = d2;
46 }
47
48 private Vec3D e(double d0, double d1, double d2) {
49 this.a = d0;
50 this.b = d1;
51 this.c = d2;
52 return this;
53 }
54
55 public Vec3D b() {
56 double d0 = (double) MathHelper.a(this.a * this.a + this.b * this.b + this.c * this.c);
57
58 return d0 < 1.0E-4D ? create(0.0D, 0.0D, 0.0D) : create(this.a / d0, this.b / d0, this.c / d0);
59 }
60
61 public Vec3D add(double d0, double d1, double d2) {
62 return create(this.a + d0, this.b + d1, this.c + d2);
63 }
64
65 public double a(Vec3D vec3d) {
66 double d0 = vec3d.a - this.a;
67 double d1 = vec3d.b - this.b;
68 double d2 = vec3d.c - this.c;
69
70 return (double) MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2);
71 }
72
73 public double b(Vec3D vec3d) {
74 double d0 = vec3d.a - this.a;
75 double d1 = vec3d.b - this.b;
76 double d2 = vec3d.c - this.c;
77
78 return d0 * d0 + d1 * d1 + d2 * d2;
79 }
80
81 public double d(double d0, double d1, double d2) {
82 double d3 = d0 - this.a;
83 double d4 = d1 - this.b;
84 double d5 = d2 - this.c;
85
86 return d3 * d3 + d4 * d4 + d5 * d5;
87 }
88
89 public double c() {
90 return (double) MathHelper.a(this.a * this.a + this.b * this.b + this.c * this.c);
91 }
92
93 public Vec3D a(Vec3D vec3d, double d0) {
94 double d1 = vec3d.a - this.a;
95 double d2 = vec3d.b - this.b;
96 double d3 = vec3d.c - this.c;
97
98 if (d1 * d1 < 1.0000000116860974E-7D) {
99 return null;
100 } else {
101 double d4 = (d0 - this.a) / d1;
102
103 return d4 >= 0.0D && d4 <= 1.0D ? create(this.a + d1 * d4, this.b + d2 * d4, this.c + d3 * d4) : null;
104 }
105 }
106
107 public Vec3D b(Vec3D vec3d, double d0) {
108 double d1 = vec3d.a - this.a;
109 double d2 = vec3d.b - this.b;
110 double d3 = vec3d.c - this.c;
111
112 if (d2 * d2 < 1.0000000116860974E-7D) {
113 return null;
114 } else {
115 double d4 = (d0 - this.b) / d2;
116
117 return d4 >= 0.0D && d4 <= 1.0D ? create(this.a + d1 * d4, this.b + d2 * d4, this.c + d3 * d4) : null;
118 }
119 }
120
121 public Vec3D c(Vec3D vec3d, double d0) {
122 double d1 = vec3d.a - this.a;
123 double d2 = vec3d.b - this.b;
124 double d3 = vec3d.c - this.c;
125
126 if (d3 * d3 < 1.0000000116860974E-7D) {
127 return null;
128 } else {
129 double d4 = (d0 - this.c) / d3;
130
131 return d4 >= 0.0D && d4 <= 1.0D ? create(this.a + d1 * d4, this.b + d2 * d4, this.c + d3 * d4) : null;
132 }
133 }
134
135 public String toString() {
136 return "(" + this.a + ", " + this.b + ", " + this.c + ")";
137 }
138}