Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3import org.bukkit.BlockChangeDelegate;
4
5import java.util.Random;
6
7public class WorldGenBigTree extends WorldGenerator {
8
9 static final byte[] a = new byte[] { (byte) 2, (byte) 0, (byte) 0, (byte) 1, (byte) 2, (byte) 1 };
10 Random b = new Random();
11 BlockChangeDelegate c; // CraftBukkit
12 int[] d = new int[] { 0, 0, 0 };
13 int e = 0;
14 int f;
15 double g = 0.618D;
16 double h = 1.0D;
17 double i = 0.381D;
18 double j = 1.0D;
19 double k = 1.0D;
20 int l = 1;
21 int m = 12;
22 int n = 4;
23 int[][] o;
24
25 public WorldGenBigTree() {
26 }
27
28 void a() {
29 this.f = (int) ((double) this.e * this.g);
30 if (this.f >= this.e) {
31 this.f = this.e - 1;
32 }
33
34 int i = (int) (1.382D + Math.pow(this.k * (double) this.e / 13.0D, 2.0D));
35
36 if (i < 1) {
37 i = 1;
38 }
39
40 int[][] aint = new int[i * this.e][4];
41 int j = this.d[1] + this.e - this.n;
42 int k = 1;
43 int l = this.d[1] + this.f;
44 int i1 = j - this.d[1];
45
46 aint[0][0] = this.d[0];
47 aint[0][1] = j;
48 aint[0][2] = this.d[2];
49 aint[0][3] = l;
50 --j;
51
52 while (i1 >= 0) {
53 int j1 = 0;
54 float f = this.a(i1);
55
56 if (f < 0.0F) {
57 --j;
58 --i1;
59 } else {
60 for (double d0 = 0.5D; j1 < i; ++j1) {
61 double d1 = this.j * (double) f * ((double) this.b.nextFloat() + 0.328D);
62 double d2 = (double) this.b.nextFloat() * 2.0D * 3.14159D;
63 int k1 = MathHelper.floor(d1 * Math.sin(d2) + (double) this.d[0] + d0);
64 int l1 = MathHelper.floor(d1 * Math.cos(d2) + (double) this.d[2] + d0);
65 int[] aint1 = new int[] { k1, j, l1 };
66 int[] aint2 = new int[] { k1, j + this.n, l1 };
67
68 if (this.a(aint1, aint2) == -1) {
69 int[] aint3 = new int[] { this.d[0], this.d[1], this.d[2] };
70 double d3 = Math.sqrt(Math.pow((double) Math.abs(this.d[0] - aint1[0]), 2.0D) + Math.pow((double) Math.abs(this.d[2] - aint1[2]), 2.0D));
71 double d4 = d3 * this.i;
72
73 if ((double) aint1[1] - d4 > (double) l) {
74 aint3[1] = l;
75 } else {
76 aint3[1] = (int) ((double) aint1[1] - d4);
77 }
78
79 if (this.a(aint3, aint1) == -1) {
80 aint[k][0] = k1;
81 aint[k][1] = j;
82 aint[k][2] = l1;
83 aint[k][3] = aint3[1];
84 ++k;
85 }
86 }
87 }
88
89 --j;
90 --i1;
91 }
92 }
93
94 this.o = new int[k][4];
95 System.arraycopy(aint, 0, this.o, 0, k);
96 }
97
98 void a(int i, int j, int k, float f, byte b0, int l) {
99 int i1 = (int) ((double) f + 0.618D);
100 byte b1 = a[b0];
101 byte b2 = a[b0 + 3];
102 int[] aint = new int[] { i, j, k };
103 int[] aint1 = new int[] { 0, 0, 0 };
104 int j1 = -i1;
105 int k1 = -i1;
106
107 for (aint1[b0] = aint[b0]; j1 <= i1; ++j1) {
108 aint1[b1] = aint[b1] + j1;
109 k1 = -i1;
110
111 while (k1 <= i1) {
112 double d0 = Math.sqrt(Math.pow((double) Math.abs(j1) + 0.5D, 2.0D) + Math.pow((double) Math.abs(k1) + 0.5D, 2.0D));
113
114 if (d0 > (double) f) {
115 ++k1;
116 } else {
117 aint1[b2] = aint[b2] + k1;
118 int l1 = this.c.getTypeId(aint1[0], aint1[1], aint1[2]);
119
120 if (l1 != 0 && l1 != 18) {
121 ++k1;
122 } else {
123 this.c.setRawTypeId(aint1[0], aint1[1], aint1[2], l);
124 ++k1;
125 }
126 }
127 }
128 }
129 }
130
131 float a(int i) {
132 if ((double) i < (double) ((float) this.e) * 0.3D) {
133 return -1.618F;
134 } else {
135 float f = (float) this.e / 2.0F;
136 float f1 = (float) this.e / 2.0F - (float) i;
137 float f2;
138
139 if (f1 == 0.0F) {
140 f2 = f;
141 } else if (Math.abs(f1) >= f) {
142 f2 = 0.0F;
143 } else {
144 f2 = (float) Math.sqrt(Math.pow((double) Math.abs(f), 2.0D) - Math.pow((double) Math.abs(f1), 2.0D));
145 }
146
147 f2 *= 0.5F;
148 return f2;
149 }
150 }
151
152 float b(int i) {
153 return i >= 0 && i < this.n ? (i != 0 && i != this.n - 1 ? 3.0F : 2.0F) : -1.0F;
154 }
155
156 void a(int i, int j, int k) {
157 int l = j;
158
159 for (int i1 = j + this.n; l < i1; ++l) {
160 float f = this.b(l - j);
161
162 this.a(i, l, k, f, (byte) 1, 18);
163 }
164 }
165
166 void a(int[] aint, int[] aint1, int i) {
167 int[] aint2 = new int[] { 0, 0, 0 };
168 byte b0 = 0;
169
170 byte b1;
171
172 for (b1 = 0; b0 < 3; ++b0) {
173 aint2[b0] = aint1[b0] - aint[b0];
174 if (Math.abs(aint2[b0]) > Math.abs(aint2[b1])) {
175 b1 = b0;
176 }
177 }
178
179 if (aint2[b1] != 0) {
180 byte b2 = a[b1];
181 byte b3 = a[b1 + 3];
182 byte b4;
183
184 if (aint2[b1] > 0) {
185 b4 = 1;
186 } else {
187 b4 = -1;
188 }
189
190 double d0 = (double) aint2[b2] / (double) aint2[b1];
191 double d1 = (double) aint2[b3] / (double) aint2[b1];
192 int[] aint3 = new int[] { 0, 0, 0 };
193 int j = 0;
194
195 for (int k = aint2[b1] + b4; j != k; j += b4) {
196 aint3[b1] = MathHelper.floor((double) (aint[b1] + j) + 0.5D);
197 aint3[b2] = MathHelper.floor((double) aint[b2] + (double) j * d0 + 0.5D);
198 aint3[b3] = MathHelper.floor((double) aint[b3] + (double) j * d1 + 0.5D);
199 this.c.setRawTypeId(aint3[0], aint3[1], aint3[2], i);
200 }
201 }
202 }
203
204 void b() {
205 int i = 0;
206
207 for (int j = this.o.length; i < j; ++i) {
208 int k = this.o[i][0];
209 int l = this.o[i][1];
210 int i1 = this.o[i][2];
211
212 this.a(k, l, i1);
213 }
214 }
215
216 boolean c(int i) {
217 return (double) i >= (double) this.e * 0.2D;
218 }
219
220 void c() {
221 int i = this.d[0];
222 int j = this.d[1];
223 int k = this.d[1] + this.f;
224 int l = this.d[2];
225 int[] aint = new int[] { i, j, l };
226 int[] aint1 = new int[] { i, k, l };
227
228 this.a(aint, aint1, 17);
229 if (this.l == 2) {
230 ++aint[0];
231 ++aint1[0];
232 this.a(aint, aint1, 17);
233 ++aint[2];
234 ++aint1[2];
235 this.a(aint, aint1, 17);
236 aint[0] += -1;
237 aint1[0] += -1;
238 this.a(aint, aint1, 17);
239 }
240 }
241
242 void d() {
243 int i = 0;
244 int j = this.o.length;
245
246 for (int[] aint = new int[] { this.d[0], this.d[1], this.d[2] }; i < j; ++i) {
247 int[] aint1 = this.o[i];
248 int[] aint2 = new int[] { aint1[0], aint1[1], aint1[2] };
249
250 aint[1] = aint1[3];
251 int k = aint[1] - this.d[1];
252
253 if (this.c(k)) {
254 this.a(aint, aint2, 17);
255 }
256 }
257 }
258
259 int a(int[] aint, int[] aint1) {
260 int[] aint2 = new int[] { 0, 0, 0 };
261 byte b0 = 0;
262
263 byte b1;
264
265 for (b1 = 0; b0 < 3; ++b0) {
266 aint2[b0] = aint1[b0] - aint[b0];
267 if (Math.abs(aint2[b0]) > Math.abs(aint2[b1])) {
268 b1 = b0;
269 }
270 }
271
272 if (aint2[b1] == 0) {
273 return -1;
274 } else {
275 byte b2 = a[b1];
276 byte b3 = a[b1 + 3];
277 byte b4;
278
279 if (aint2[b1] > 0) {
280 b4 = 1;
281 } else {
282 b4 = -1;
283 }
284
285 double d0 = (double) aint2[b2] / (double) aint2[b1];
286 double d1 = (double) aint2[b3] / (double) aint2[b1];
287 int[] aint3 = new int[] { 0, 0, 0 };
288 int i = 0;
289
290 int j;
291
292 for (j = aint2[b1] + b4; i != j; i += b4) {
293 aint3[b1] = aint[b1] + i;
294 aint3[b2] = MathHelper.floor((double) aint[b2] + (double) i * d0);
295 aint3[b3] = MathHelper.floor((double) aint[b3] + (double) i * d1);
296 int k = this.c.getTypeId(aint3[0], aint3[1], aint3[2]);
297
298 if (k != 0 && k != 18) {
299 break;
300 }
301 }
302
303 return i == j ? -1 : Math.abs(i);
304 }
305 }
306
307 boolean e() {
308 int[] aint = new int[] { this.d[0], this.d[1], this.d[2] };
309 int[] aint1 = new int[] { this.d[0], this.d[1] + this.e - 1, this.d[2] };
310 int i = this.c.getTypeId(this.d[0], this.d[1] - 1, this.d[2]);
311
312 if (i != 2 && i != 3) {
313 return false;
314 } else {
315 int j = this.a(aint, aint1);
316
317 if (j == -1) {
318 return true;
319 } else if (j < 6) {
320 return false;
321 } else {
322 this.e = j;
323 return true;
324 }
325 }
326 }
327
328 public void a(double d0, double d1, double d2) {
329 this.m = (int) (d0 * 12.0D);
330 if (d0 > 0.5D) {
331 this.n = 5;
332 }
333
334 this.j = d1;
335 this.k = d2;
336 }
337
338 public boolean a(World world, Random random, int i, int j, int k) {
339 // CraftBukkit start
340 // sk: The idea is to have (our) WorldServer implement
341 // BlockChangeDelegate and then we can implicitly cast World to
342 // WorldServer (a safe cast, AFAIK) and no code will be broken. This
343 // then allows plugins to catch manually-invoked generation events
344 return this.generate((BlockChangeDelegate) world, random, i, j, k);
345 }
346
347 public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k) {
348 // CraftBukkit end
349 this.c = world;
350 long l = random.nextLong();
351
352 this.b.setSeed(l);
353 this.d[0] = i;
354 this.d[1] = j;
355 this.d[2] = k;
356 if (this.e == 0) {
357 this.e = 5 + this.b.nextInt(this.m);
358 }
359
360 if (!this.e()) {
361 return false;
362 } else {
363 this.a();
364 this.b();
365 this.c();
366 this.d();
367 return true;
368 }
369 }
370}