Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3import org.bukkit.Location;
4import org.bukkit.entity.Vehicle;
5import org.bukkit.event.vehicle.*;
6
7import uk.betacraft.uberbukkit.UberbukkitConfig;
8
9import java.util.List;
10
11// CraftBukkit start
12// CraftBukkit end
13
14public class EntityMinecart extends Entity implements IInventory {
15
16 private ItemStack[] items;
17 public int damage;
18 public int b;
19 public int c;
20 private boolean i;
21 public int type;
22 public int e;
23 public double f;
24 public double g;
25 private static final int[][][] matrix = new int[][][] { { { 0, 0, -1 }, { 0, 0, 1 } }, { { -1, 0, 0 }, { 1, 0, 0 } }, { { -1, -1, 0 }, { 1, 0, 0 } }, { { -1, 0, 0 }, { 1, -1, 0 } }, { { 0, 0, -1 }, { 0, -1, 1 } }, { { 0, -1, -1 }, { 0, 0, 1 } }, { { 0, 0, 1 }, { 1, 0, 0 } }, { { 0, 0, 1 }, { -1, 0, 0 } }, { { 0, 0, -1 }, { -1, 0, 0 } }, { { 0, 0, -1 }, { 1, 0, 0 } } };
26 private int k;
27 private double l;
28 private double m;
29 private double n;
30 private double o;
31 private double p;
32
33 // CraftBukkit start
34 public boolean slowWhenEmpty = true;
35 public double derailedX = 0.5;
36 public double derailedY = 0.5;
37 public double derailedZ = 0.5;
38 public double flyingX = 0.95;
39 public double flyingY = 0.95;
40 public double flyingZ = 0.95;
41 public double maxSpeed = 0.4D;
42
43 public ItemStack[] getContents() {
44 return this.items;
45 }
46 // CraftBukkit end
47
48 public EntityMinecart(World world) {
49 super(world);
50 this.items = new ItemStack[27]; // CraftBukkit
51 this.damage = 0;
52 this.b = 0;
53 this.c = 1;
54 this.i = false;
55 this.aI = true;
56 this.b(0.98F, 0.7F);
57 this.height = this.width / 2.0F;
58 }
59
60 protected boolean n() {
61 return false;
62 }
63
64 protected void b() {
65 }
66
67 public AxisAlignedBB a_(Entity entity) {
68 return entity.boundingBox;
69 }
70
71 public AxisAlignedBB e_() {
72 return null;
73 }
74
75 public boolean d_() {
76 return true;
77 }
78
79 public EntityMinecart(World world, double d0, double d1, double d2, int i) {
80 this(world);
81 this.setPosition(d0, d1 + (double) this.height, d2);
82 this.motX = 0.0D;
83 this.motY = 0.0D;
84 this.motZ = 0.0D;
85 this.lastX = d0;
86 this.lastY = d1;
87 this.lastZ = d2;
88 this.type = i;
89
90 this.world.getServer().getPluginManager().callEvent(new VehicleCreateEvent((Vehicle) this.getBukkitEntity())); // CraftBukkit
91 }
92
93 public double m() {
94 return (double) this.width * 0.0D - 0.30000001192092896D;
95 }
96
97 public boolean damageEntity(Entity entity, int i) {
98 if (!this.world.isStatic && !this.dead) {
99 // CraftBukkit start
100 Vehicle vehicle = (Vehicle) this.getBukkitEntity();
101 org.bukkit.entity.Entity passenger = (entity == null) ? null : entity.getBukkitEntity();
102
103 VehicleDamageEvent event = new VehicleDamageEvent(vehicle, passenger, i);
104 this.world.getServer().getPluginManager().callEvent(event);
105
106 if (event.isCancelled()) {
107 return true;
108 }
109
110 i = event.getDamage();
111 // CraftBukkit end
112
113 this.c = -this.c;
114 this.b = 10;
115 this.af();
116 this.damage += i * 10;
117 if (this.damage > 40) {
118 if (this.passenger != null) {
119 this.passenger.mount(this);
120 }
121
122 // CraftBukkit start
123 VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, passenger);
124 this.world.getServer().getPluginManager().callEvent(destroyEvent);
125
126 if (destroyEvent.isCancelled()) {
127 this.damage = 40; // Maximize damage so this doesn't get triggered again right away
128 return true;
129 }
130 // CraftBukkit end
131
132 this.die();
133 this.a(Item.MINECART.id, 1, 0.0F);
134 if (this.type == 1) {
135 EntityMinecart entityminecart = this;
136
137 for (int j = 0; j < entityminecart.getSize(); ++j) {
138 ItemStack itemstack = entityminecart.getItem(j);
139
140 if (itemstack != null) {
141 float f = this.random.nextFloat() * 0.8F + 0.1F;
142 float f1 = this.random.nextFloat() * 0.8F + 0.1F;
143 float f2 = this.random.nextFloat() * 0.8F + 0.1F;
144
145 while (itemstack.count > 0) {
146 int k = this.random.nextInt(21) + 10;
147
148 if (k > itemstack.count) {
149 k = itemstack.count;
150 }
151
152 itemstack.count -= k;
153 EntityItem entityitem = new EntityItem(this.world, this.locX + (double) f, this.locY + (double) f1, this.locZ + (double) f2, new ItemStack(itemstack.id, k, itemstack.getData()));
154 float f3 = 0.05F;
155
156 entityitem.motX = (double) ((float) this.random.nextGaussian() * f3);
157 entityitem.motY = (double) ((float) this.random.nextGaussian() * f3 + 0.2F);
158 entityitem.motZ = (double) ((float) this.random.nextGaussian() * f3);
159 this.world.addEntity(entityitem);
160 }
161 entityminecart.setItem(j, null);
162 }
163 }
164
165 this.a(Block.CHEST.id, 1, 0.0F);
166 } else if (this.type == 2) {
167 this.a(Block.FURNACE.id, 1, 0.0F);
168 }
169 }
170
171 return true;
172 } else {
173 return true;
174 }
175 }
176
177 public boolean l_() {
178 return !this.dead;
179 }
180
181 public void die() {
182 for (int i = 0; i < this.getSize(); ++i) {
183 ItemStack itemstack = this.getItem(i);
184
185 if (itemstack != null) {
186 float f = this.random.nextFloat() * 0.8F + 0.1F;
187 float f1 = this.random.nextFloat() * 0.8F + 0.1F;
188 float f2 = this.random.nextFloat() * 0.8F + 0.1F;
189
190 while (itemstack.count > 0) {
191 int j = this.random.nextInt(21) + 10;
192
193 if (j > itemstack.count) {
194 j = itemstack.count;
195 }
196
197 itemstack.count -= j;
198 EntityItem entityitem = new EntityItem(this.world, this.locX + (double) f, this.locY + (double) f1, this.locZ + (double) f2, new ItemStack(itemstack.id, j, itemstack.getData()));
199 float f3 = 0.05F;
200
201 entityitem.motX = (double) ((float) this.random.nextGaussian() * f3);
202 entityitem.motY = (double) ((float) this.random.nextGaussian() * f3 + 0.2F);
203 entityitem.motZ = (double) ((float) this.random.nextGaussian() * f3);
204 this.world.addEntity(entityitem);
205 }
206 }
207 }
208
209 super.die();
210 }
211
212 public void m_() {
213 // CraftBukkit start
214 double prevX = this.locX;
215 double prevY = this.locY;
216 double prevZ = this.locZ;
217 float prevYaw = this.yaw;
218 float prevPitch = this.pitch;
219 // CraftBukkit end
220
221 if (this.b > 0) {
222 --this.b;
223 }
224
225 if (this.damage > 0) {
226 --this.damage;
227 }
228
229 double d0;
230
231 if (this.world.isStatic && this.k > 0) {
232 if (this.k > 0) {
233 double d1 = this.locX + (this.l - this.locX) / (double) this.k;
234 double d2 = this.locY + (this.m - this.locY) / (double) this.k;
235 double d3 = this.locZ + (this.n - this.locZ) / (double) this.k;
236
237 for (d0 = this.o - (double) this.yaw; d0 < -180.0D; d0 += 360.0D) {
238 ;
239 }
240
241 while (d0 >= 180.0D) {
242 d0 -= 360.0D;
243 }
244
245 this.yaw = (float) ((double) this.yaw + d0 / (double) this.k);
246 this.pitch = (float) ((double) this.pitch + (this.p - (double) this.pitch) / (double) this.k);
247 --this.k;
248 this.setPosition(d1, d2, d3);
249 this.c(this.yaw, this.pitch);
250 } else {
251 this.setPosition(this.locX, this.locY, this.locZ);
252 this.c(this.yaw, this.pitch);
253 }
254 } else {
255 this.lastX = this.locX;
256 this.lastY = this.locY;
257 this.lastZ = this.locZ;
258 this.motY -= 0.03999999910593033D;
259 int i = MathHelper.floor(this.locX);
260 int j = MathHelper.floor(this.locY);
261 int k = MathHelper.floor(this.locZ);
262
263 if (BlockMinecartTrack.g(this.world, i, j - 1, k)) {
264 --j;
265 }
266
267 // CraftBukkit
268 double d4 = this.maxSpeed;
269 boolean flag = false;
270
271 d0 = 0.0078125D;
272 int l = this.world.getTypeId(i, j, k);
273
274 if (BlockMinecartTrack.c(l)) {
275 Vec3D vec3d = this.h(this.locX, this.locY, this.locZ);
276 int i1 = this.world.getData(i, j, k);
277
278 this.locY = (double) j;
279 boolean flag1 = false;
280 boolean flag2 = false;
281
282 if (l == Block.GOLDEN_RAIL.id) {
283 flag1 = (i1 & 8) != 0;
284 flag2 = !flag1;
285 }
286
287 if (((BlockMinecartTrack) Block.byId[l]).f()) {
288 i1 &= 7;
289 }
290
291 if (i1 >= 2 && i1 <= 5) {
292 this.locY = (double) (j + 1);
293 }
294
295 if (i1 == 2) {
296 this.motX -= d0;
297 }
298
299 if (i1 == 3) {
300 this.motX += d0;
301 }
302
303 if (i1 == 4) {
304 this.motZ += d0;
305 }
306
307 if (i1 == 5) {
308 this.motZ -= d0;
309 }
310
311 int[][] aint = matrix[i1];
312 double d5 = (double) (aint[1][0] - aint[0][0]);
313 double d6 = (double) (aint[1][2] - aint[0][2]);
314 double d7 = Math.sqrt(d5 * d5 + d6 * d6);
315 double d8 = this.motX * d5 + this.motZ * d6;
316
317 if (d8 < 0.0D) {
318 d5 = -d5;
319 d6 = -d6;
320 }
321
322 double d9 = Math.sqrt(this.motX * this.motX + this.motZ * this.motZ);
323
324 this.motX = d9 * d5 / d7;
325 this.motZ = d9 * d6 / d7;
326 double d10;
327
328 if (flag2) {
329 d10 = Math.sqrt(this.motX * this.motX + this.motZ * this.motZ);
330 if (d10 < 0.03D) {
331 this.motX *= 0.0D;
332 this.motY *= 0.0D;
333 this.motZ *= 0.0D;
334 } else {
335 this.motX *= 0.5D;
336 this.motY *= 0.0D;
337 this.motZ *= 0.5D;
338 }
339 }
340
341 d10 = 0.0D;
342 double d11 = (double) i + 0.5D + (double) aint[0][0] * 0.5D;
343 double d12 = (double) k + 0.5D + (double) aint[0][2] * 0.5D;
344 double d13 = (double) i + 0.5D + (double) aint[1][0] * 0.5D;
345 double d14 = (double) k + 0.5D + (double) aint[1][2] * 0.5D;
346
347 d5 = d13 - d11;
348 d6 = d14 - d12;
349 double d15;
350 double d16;
351 double d17;
352
353 if (d5 == 0.0D) {
354 this.locX = (double) i + 0.5D;
355 d10 = this.locZ - (double) k;
356 } else if (d6 == 0.0D) {
357 this.locZ = (double) k + 0.5D;
358 d10 = this.locX - (double) i;
359 } else {
360 d16 = this.locX - d11;
361 d15 = this.locZ - d12;
362 d17 = (d16 * d5 + d15 * d6) * 2.0D;
363 d10 = d17;
364 }
365
366 this.locX = d11 + d5 * d10;
367 this.locZ = d12 + d6 * d10;
368 this.setPosition(this.locX, this.locY + (double) this.height, this.locZ);
369 d16 = this.motX;
370 d15 = this.motZ;
371 if (this.passenger != null) {
372 d16 *= 0.75D;
373 d15 *= 0.75D;
374 }
375
376 if (d16 < -d4) {
377 d16 = -d4;
378 }
379
380 if (d16 > d4) {
381 d16 = d4;
382 }
383
384 if (d15 < -d4) {
385 d15 = -d4;
386 }
387
388 if (d15 > d4) {
389 d15 = d4;
390 }
391
392 this.move(d16, 0.0D, d15);
393 if (aint[0][1] != 0 && MathHelper.floor(this.locX) - i == aint[0][0] && MathHelper.floor(this.locZ) - k == aint[0][2]) {
394 this.setPosition(this.locX, this.locY + (double) aint[0][1], this.locZ);
395 } else if (aint[1][1] != 0 && MathHelper.floor(this.locX) - i == aint[1][0] && MathHelper.floor(this.locZ) - k == aint[1][2]) {
396 this.setPosition(this.locX, this.locY + (double) aint[1][1], this.locZ);
397 }
398
399 // CraftBukkit
400 if (this.passenger != null || !this.slowWhenEmpty) {
401 this.motX *= 0.996999979019165D;
402 this.motY *= 0.0D;
403 this.motZ *= 0.996999979019165D;
404 } else {
405 if (this.type == 2) {
406 d17 = (double) MathHelper.a(this.f * this.f + this.g * this.g);
407 if (d17 > 0.01D) {
408 flag = true;
409 this.f /= d17;
410 this.g /= d17;
411 double d18 = 0.04D;
412
413 this.motX *= 0.800000011920929D;
414 this.motY *= 0.0D;
415 this.motZ *= 0.800000011920929D;
416 this.motX += this.f * d18;
417 this.motZ += this.g * d18;
418 } else {
419 this.motX *= 0.8999999761581421D;
420 this.motY *= 0.0D;
421 this.motZ *= 0.8999999761581421D;
422 }
423 }
424
425 this.motX *= 0.9599999785423279D;
426 this.motY *= 0.0D;
427 this.motZ *= 0.9599999785423279D;
428 }
429
430 Vec3D vec3d1 = this.h(this.locX, this.locY, this.locZ);
431
432 if (vec3d1 != null && vec3d != null) {
433 double d19 = (vec3d.b - vec3d1.b) * 0.05D;
434
435 d9 = Math.sqrt(this.motX * this.motX + this.motZ * this.motZ);
436 if (d9 > 0.0D) {
437 this.motX = this.motX / d9 * (d9 + d19);
438 this.motZ = this.motZ / d9 * (d9 + d19);
439 }
440
441 this.setPosition(this.locX, vec3d1.b, this.locZ);
442 }
443
444 int j1 = MathHelper.floor(this.locX);
445 int k1 = MathHelper.floor(this.locZ);
446
447 if (j1 != i || k1 != k) {
448 d9 = Math.sqrt(this.motX * this.motX + this.motZ * this.motZ);
449 this.motX = d9 * (double) (j1 - i);
450 this.motZ = d9 * (double) (k1 - k);
451 }
452
453 double d20;
454
455 if (this.type == 2) {
456 d20 = (double) MathHelper.a(this.f * this.f + this.g * this.g);
457 if (d20 > 0.01D && this.motX * this.motX + this.motZ * this.motZ > 0.0010D) {
458 this.f /= d20;
459 this.g /= d20;
460 if (this.f * this.motX + this.g * this.motZ < 0.0D) {
461 this.f = 0.0D;
462 this.g = 0.0D;
463 } else {
464 this.f = this.motX;
465 this.g = this.motZ;
466 }
467 }
468 }
469
470 if (flag1) {
471 d20 = Math.sqrt(this.motX * this.motX + this.motZ * this.motZ);
472 if (d20 > 0.01D) {
473 double d21 = 0.06D;
474
475 this.motX += this.motX / d20 * d21;
476 this.motZ += this.motZ / d20 * d21;
477 } else if (i1 == 1) {
478 if (this.world.e(i - 1, j, k)) {
479 this.motX = 0.02D;
480 } else if (this.world.e(i + 1, j, k)) {
481 this.motX = -0.02D;
482 }
483 } else if (i1 == 0) {
484 if (this.world.e(i, j, k - 1)) {
485 this.motZ = 0.02D;
486 } else if (this.world.e(i, j, k + 1)) {
487 this.motZ = -0.02D;
488 }
489 }
490 }
491 } else {
492 if (this.motX < -d4) {
493 this.motX = -d4;
494 }
495
496 if (this.motX > d4) {
497 this.motX = d4;
498 }
499
500 if (this.motZ < -d4) {
501 this.motZ = -d4;
502 }
503
504 if (this.motZ > d4) {
505 this.motZ = d4;
506 }
507
508 if (this.onGround) {
509 // CraftBukkit start
510 this.motX *= this.derailedX;
511 this.motY *= this.derailedY;
512 this.motZ *= this.derailedZ;
513 // CraftBukkit start
514 }
515
516 this.move(this.motX, this.motY, this.motZ);
517 if (!this.onGround) {
518 // CraftBukkit start
519 this.motX *= this.flyingX;
520 this.motY *= this.flyingY;
521 this.motZ *= this.flyingZ;
522 // CraftBukkit start
523 }
524 }
525
526 this.pitch = 0.0F;
527 double d22 = this.lastX - this.locX;
528 double d23 = this.lastZ - this.locZ;
529
530 if (d22 * d22 + d23 * d23 > 0.0010D) {
531 this.yaw = (float) (Math.atan2(d23, d22) * 180.0D / 3.141592653589793D);
532 if (this.i) {
533 this.yaw += 180.0F;
534 }
535 }
536
537 double d24;
538
539 for (d24 = (double) (this.yaw - this.lastYaw); d24 >= 180.0D; d24 -= 360.0D) {
540 ;
541 }
542
543 while (d24 < -180.0D) {
544 d24 += 360.0D;
545 }
546
547 if (d24 < -170.0D || d24 >= 170.0D) {
548 this.yaw += 180.0F;
549 this.i = !this.i;
550 }
551
552 this.c(this.yaw, this.pitch);
553
554 // CraftBukkit start
555 org.bukkit.World bworld = this.world.getWorld();
556 Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch);
557 Location to = new Location(bworld, this.locX, this.locY, this.locZ, this.yaw, this.pitch);
558 Vehicle vehicle = (Vehicle) this.getBukkitEntity();
559
560 this.world.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(vehicle));
561
562 if (!from.equals(to)) {
563 this.world.getServer().getPluginManager().callEvent(new VehicleMoveEvent(vehicle, from, to));
564 }
565 // CraftBukkit end
566
567 List list = this.world.b((Entity) this, this.boundingBox.b(0.20000000298023224D, 0.0D, 0.20000000298023224D));
568
569 if (list != null && list.size() > 0) {
570 for (int l1 = 0; l1 < list.size(); ++l1) {
571 Entity entity = (Entity) list.get(l1);
572
573 if (entity != this.passenger && entity.d_() && entity instanceof EntityMinecart) {
574 entity.collide(this);
575 }
576 }
577 }
578
579 if (this.passenger != null && this.passenger.dead) {
580 this.passenger.vehicle = null; // CraftBukkit
581 this.passenger = null;
582 }
583
584 if (flag && this.random.nextInt(4) == 0) {
585 --this.e;
586 if (this.e < 0) {
587 this.f = this.g = 0.0D;
588 }
589
590 this.world.a("largesmoke", this.locX, this.locY + 0.8D, this.locZ, 0.0D, 0.0D, 0.0D);
591 }
592 }
593 }
594
595 public Vec3D h(double d0, double d1, double d2) {
596 int i = MathHelper.floor(d0);
597 int j = MathHelper.floor(d1);
598 int k = MathHelper.floor(d2);
599
600 if (BlockMinecartTrack.g(this.world, i, j - 1, k)) {
601 --j;
602 }
603
604 int l = this.world.getTypeId(i, j, k);
605
606 if (BlockMinecartTrack.c(l)) {
607 int i1 = this.world.getData(i, j, k);
608
609 d1 = (double) j;
610 if (((BlockMinecartTrack) Block.byId[l]).f()) {
611 i1 &= 7;
612 }
613
614 if (i1 >= 2 && i1 <= 5) {
615 d1 = (double) (j + 1);
616 }
617
618 int[][] aint = matrix[i1];
619 double d3 = 0.0D;
620 double d4 = (double) i + 0.5D + (double) aint[0][0] * 0.5D;
621 double d5 = (double) j + 0.5D + (double) aint[0][1] * 0.5D;
622 double d6 = (double) k + 0.5D + (double) aint[0][2] * 0.5D;
623 double d7 = (double) i + 0.5D + (double) aint[1][0] * 0.5D;
624 double d8 = (double) j + 0.5D + (double) aint[1][1] * 0.5D;
625 double d9 = (double) k + 0.5D + (double) aint[1][2] * 0.5D;
626 double d10 = d7 - d4;
627 double d11 = (d8 - d5) * 2.0D;
628 double d12 = d9 - d6;
629
630 if (d10 == 0.0D) {
631 d0 = (double) i + 0.5D;
632 d3 = d2 - (double) k;
633 } else if (d12 == 0.0D) {
634 d2 = (double) k + 0.5D;
635 d3 = d0 - (double) i;
636 } else {
637 double d13 = d0 - d4;
638 double d14 = d2 - d6;
639 double d15 = (d13 * d10 + d14 * d12) * 2.0D;
640
641 d3 = d15;
642 }
643
644 d0 = d4 + d10 * d3;
645 d1 = d5 + d11 * d3;
646 d2 = d6 + d12 * d3;
647 if (d11 < 0.0D) {
648 ++d1;
649 }
650
651 if (d11 > 0.0D) {
652 d1 += 0.5D;
653 }
654
655 return Vec3D.create(d0, d1, d2);
656 } else {
657 return null;
658 }
659 }
660
661 protected void b(NBTTagCompound nbttagcompound) {
662 nbttagcompound.a("Type", this.type);
663 if (this.type == 2) {
664 nbttagcompound.a("PushX", this.f);
665 nbttagcompound.a("PushZ", this.g);
666 nbttagcompound.a("Fuel", (short) this.e);
667 } else if (this.type == 1) {
668 NBTTagList nbttaglist = new NBTTagList();
669
670 for (int i = 0; i < this.items.length; ++i) {
671 if (this.items[i] != null) {
672 NBTTagCompound nbttagcompound1 = new NBTTagCompound();
673
674 nbttagcompound1.a("Slot", (byte) i);
675 this.items[i].a(nbttagcompound1);
676 nbttaglist.a((NBTBase) nbttagcompound1);
677 }
678 }
679
680 nbttagcompound.a("Items", (NBTBase) nbttaglist);
681 }
682 }
683
684 protected void a(NBTTagCompound nbttagcompound) {
685 this.type = nbttagcompound.e("Type");
686 if (this.type == 2) {
687 this.f = nbttagcompound.h("PushX");
688 this.g = nbttagcompound.h("PushZ");
689 this.e = nbttagcompound.d("Fuel");
690 } else if (this.type == 1) {
691 NBTTagList nbttaglist = nbttagcompound.l("Items");
692
693 this.items = new ItemStack[this.getSize()];
694
695 for (int i = 0; i < nbttaglist.c(); ++i) {
696 NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(i);
697 int j = nbttagcompound1.c("Slot") & 255;
698
699 if (j >= 0 && j < this.items.length) {
700 this.items[j] = new ItemStack(nbttagcompound1);
701 }
702 }
703 }
704 }
705
706 public void collide(Entity entity) {
707 if (!this.world.isStatic) {
708 if (entity != this.passenger) {
709 // CraftBukkit start
710 Vehicle vehicle = (Vehicle) this.getBukkitEntity();
711 org.bukkit.entity.Entity hitEntity = (entity == null) ? null : entity.getBukkitEntity();
712
713 VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, hitEntity);
714 this.world.getServer().getPluginManager().callEvent(collisionEvent);
715
716 if (collisionEvent.isCancelled()) {
717 return;
718 }
719
720 if (entity instanceof EntityLiving && !(entity instanceof EntityHuman) && this.type == 0 && this.motX * this.motX + this.motZ * this.motZ > 0.01D && this.passenger == null && entity.vehicle == null) {
721 if (!collisionEvent.isPickupCancelled()) {
722 VehicleEnterEvent enterEvent = new VehicleEnterEvent(vehicle, hitEntity);
723 this.world.getServer().getPluginManager().callEvent(enterEvent);
724
725 if (!enterEvent.isCancelled()) {
726 entity.mount(this);
727 }
728 }
729 }
730 // CraftBukkit end
731
732 double d0 = entity.locX - this.locX;
733 double d1 = entity.locZ - this.locZ;
734 double d2 = d0 * d0 + d1 * d1;
735
736 // CraftBukkit - Collision
737 if (d2 >= 9.999999747378752E-5D && !collisionEvent.isCollisionCancelled()) {
738 d2 = (double) MathHelper.a(d2);
739 d0 /= d2;
740 d1 /= d2;
741 double d3 = 1.0D / d2;
742
743 if (d3 > 1.0D) {
744 d3 = 1.0D;
745 }
746
747 d0 *= d3;
748 d1 *= d3;
749 d0 *= 0.10000000149011612D;
750 d1 *= 0.10000000149011612D;
751 d0 *= (double) (1.0F - this.bu);
752 d1 *= (double) (1.0F - this.bu);
753 d0 *= 0.5D;
754 d1 *= 0.5D;
755 if (entity instanceof EntityMinecart) {
756 // uberbukkit
757 if (!UberbukkitConfig.getInstance().getBoolean("mechanics.allow_minecart_boosters", false)) {
758 double d4 = entity.locX - this.locX;
759 double d5 = entity.locZ - this.locZ;
760 double d6 = d4 * entity.motZ + d5 * entity.lastX;
761
762 d6 *= d6;
763 if (d6 > 5.0D) {
764 return;
765 }
766 }
767
768 double d7 = entity.motX + this.motX;
769 double d8 = entity.motZ + this.motZ;
770
771 if (((EntityMinecart) entity).type == 2 && this.type != 2) {
772 this.motX *= 0.20000000298023224D;
773 this.motZ *= 0.20000000298023224D;
774 this.b(entity.motX - d0, 0.0D, entity.motZ - d1);
775 entity.motX *= 0.699999988079071D;
776 entity.motZ *= 0.699999988079071D;
777 } else if (((EntityMinecart) entity).type != 2 && this.type == 2) {
778 entity.motX *= 0.20000000298023224D;
779 entity.motZ *= 0.20000000298023224D;
780 entity.b(this.motX + d0, 0.0D, this.motZ + d1);
781 this.motX *= 0.699999988079071D;
782 this.motZ *= 0.699999988079071D;
783 } else {
784 d7 /= 2.0D;
785 d8 /= 2.0D;
786 this.motX *= 0.20000000298023224D;
787 this.motZ *= 0.20000000298023224D;
788 this.b(d7 - d0, 0.0D, d8 - d1);
789 entity.motX *= 0.20000000298023224D;
790 entity.motZ *= 0.20000000298023224D;
791 entity.b(d7 + d0, 0.0D, d8 + d1);
792 }
793 } else {
794 this.b(-d0, 0.0D, -d1);
795 entity.b(d0 / 4.0D, 0.0D, d1 / 4.0D);
796 }
797 }
798 }
799 }
800 }
801
802 public int getSize() {
803 return 27;
804 }
805
806 public ItemStack getItem(int i) {
807 return this.items[i];
808 }
809
810 public ItemStack splitStack(int i, int j) {
811 if (this.items[i] != null) {
812 ItemStack itemstack;
813
814 if (this.items[i].count <= j) {
815 itemstack = this.items[i];
816 this.items[i] = null;
817 return itemstack;
818 } else {
819 itemstack = this.items[i].a(j);
820 if (this.items[i].count == 0) {
821 this.items[i] = null;
822 }
823
824 return itemstack;
825 }
826 } else {
827 return null;
828 }
829 }
830
831 public void setItem(int i, ItemStack itemstack) {
832 this.items[i] = itemstack;
833 if (itemstack != null && itemstack.count > this.getMaxStackSize()) {
834 itemstack.count = this.getMaxStackSize();
835 }
836 }
837
838 public String getName() {
839 return "Minecart";
840 }
841
842 public int getMaxStackSize() {
843 return 64;
844 }
845
846 public void update() {
847 }
848
849 public boolean a(EntityHuman entityhuman) {
850 if (this.type == 0) {
851 if (this.passenger != null && this.passenger instanceof EntityHuman && this.passenger != entityhuman) {
852 return true;
853 }
854
855 if (!this.world.isStatic) {
856 // CraftBukkit start
857 org.bukkit.entity.Entity player = (entityhuman == null) ? null : entityhuman.getBukkitEntity();
858
859 VehicleEnterEvent event = new VehicleEnterEvent((Vehicle) this.getBukkitEntity(), player);
860 this.world.getServer().getPluginManager().callEvent(event);
861
862 if (event.isCancelled()) {
863 return true;
864 }
865 // CraftBukkit end
866
867 entityhuman.mount(this);
868 }
869 } else if (this.type == 1) {
870 if (!this.world.isStatic) {
871 entityhuman.a((IInventory) this);
872 }
873 } else if (this.type == 2) {
874 ItemStack itemstack = entityhuman.inventory.getItemInHand();
875
876 if (itemstack != null && itemstack.id == Item.COAL.id) {
877 if (--itemstack.count == 0) {
878 entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, (ItemStack) null);
879 }
880
881 this.e += 1200;
882 }
883
884 this.f = this.locX - entityhuman.locX;
885 this.g = this.locZ - entityhuman.locZ;
886 }
887
888 return true;
889 }
890
891 public boolean a_(EntityHuman entityhuman) {
892 return this.dead ? false : entityhuman.g(this) <= 64.0D;
893 }
894}