Commits

md_5 authored 438556243d9
SPIGOT-4571: EntityCombustEvent not firing for phantoms
No tags

nms-patches/Entity.patch

Modified
177 177 this.world.methodProfiler.enter("portal");
178 178 if (this.an) {
179 179 @@ -287,6 +419,7 @@
180 180 this.E();
181 181 this.world.methodProfiler.exit();
182 182 }
183 183 + */
184 184
185 185 this.av();
186 186 this.r();
187 -@@ -337,7 +470,23 @@
187 +@@ -337,12 +470,44 @@
188 188
189 189 protected void burnFromLava() {
190 190 if (!this.fireProof) {
191 191 - this.setOnFire(15);
192 192 + // CraftBukkit start - Fallen in lava TODO: this event spams!
193 193 + if (this instanceof EntityLiving && fireTicks <= 0) {
194 194 + // not on fire yet
195 195 + // TODO: shouldn't be sending null for the block
196 196 + org.bukkit.block.Block damager = null; // ((WorldServer) this.l).getWorld().getBlockAt(i, j, k);
197 197 + org.bukkit.entity.Entity damagee = this.getBukkitEntity();
198 198 + EntityCombustEvent combustEvent = new org.bukkit.event.entity.EntityCombustByBlockEvent(damager, damagee, 15);
199 199 + this.world.getServer().getPluginManager().callEvent(combustEvent);
200 200 +
201 201 + if (!combustEvent.isCancelled()) {
202 -+ this.setOnFire(combustEvent.getDuration());
202 ++ this.setOnFire(combustEvent.getDuration(), false);
203 203 + }
204 204 + } else {
205 205 + // This will be called every single tick the entity is in lava, so don't throw an event
206 -+ this.setOnFire(15);
206 ++ this.setOnFire(15, false);
207 207 + }
208 208 + // CraftBukkit end - we also don't throw an event unless the object in lava is living, to save on some event calls
209 209 this.damageEntity(DamageSource.LAVA, 4.0F);
210 210 }
211 211 }
212 -@@ -503,7 +652,7 @@
212 +
213 + public void setOnFire(int i) {
214 ++ // CraftBukkit start
215 ++ this.setOnFire(i, true);
216 ++ }
217 ++
218 ++ public void setOnFire(int i, boolean callEvent) {
219 ++ if (callEvent) {
220 ++ EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), i);
221 ++ this.world.getServer().getPluginManager().callEvent(event);
222 ++
223 ++ if (event.isCancelled()) {
224 ++ return;
225 ++ }
226 ++
227 ++ i = event.getDuration();
228 ++ }
229 ++ // CraftBukkit end
230 + int j = i * 20;
231 +
232 + if (this instanceof EntityLiving) {
233 +@@ -503,7 +668,7 @@
213 234 }
214 235 }
215 236
216 237 - boolean flag = this.onGround || d1 != d1 && d1 < 0.0D;
217 238 + boolean flag = this.onGround || d1 != d8 && d1 < 0.0D; // CraftBukkit - decompile error
218 239 double d11;
219 240
220 241 if (this.Q > 0.0F && flag && (d7 != d0 || d9 != d2)) {
221 -@@ -590,7 +739,7 @@
242 +@@ -590,7 +755,7 @@
222 243 this.world.methodProfiler.enter("rest");
223 244 this.recalcPosition();
224 245 this.positionChanged = d7 != d0 || d9 != d2;
225 246 - this.C = d1 != d1;
226 247 + this.C = d1 != d8; // CraftBukkit - decompile error
227 248 this.onGround = this.C && d8 < 0.0D;
228 249 this.D = this.positionChanged || this.C;
229 250 int k = MathHelper.floor(this.locX);
230 -@@ -625,6 +774,28 @@
251 +@@ -625,6 +790,28 @@
231 252 block1.a((IBlockAccess) this.world, this);
232 253 }
233 254
234 255 + // CraftBukkit start
235 256 + if (positionChanged && getBukkitEntity() instanceof Vehicle) {
236 257 + Vehicle vehicle = (Vehicle) this.getBukkitEntity();
237 258 + org.bukkit.block.Block bl = this.world.getWorld().getBlockAt(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ));
238 259 +
239 260 + if (d7 > d0) {
240 261 + bl = bl.getRelative(BlockFace.EAST);
249 270 + if (bl.getType() != org.bukkit.Material.AIR) {
250 271 + VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl);
251 272 + world.getServer().getPluginManager().callEvent(event);
252 273 + }
253 274 + }
254 275 + // CraftBukkit end
255 276 +
256 277 if (this.playStepSound() && (!this.onGround || !this.isSneaking() || !(this instanceof EntityHuman)) && !this.isPassenger()) {
257 278 double d22 = this.locX - d4;
258 279 double d23 = this.locY - d5;
259 -@@ -676,7 +847,14 @@
280 +@@ -676,7 +863,14 @@
260 281 if (!flag1) {
261 282 ++this.fireTicks;
262 283 if (this.fireTicks == 0) {
263 284 - this.setOnFire(8);
264 285 + // CraftBukkit start
265 286 + EntityCombustEvent event = new org.bukkit.event.entity.EntityCombustByBlockEvent(null, getBukkitEntity(), 8);
266 287 + world.getServer().getPluginManager().callEvent(event);
267 288 +
268 289 + if (!event.isCancelled()) {
269 290 + this.setOnFire(event.getDuration());
270 291 + }
271 292 + // CraftBukkit end
272 293 }
273 294 }
274 295
275 -@@ -704,6 +882,7 @@
296 +@@ -704,6 +898,7 @@
276 297 this.locX = (axisalignedbb.minX + axisalignedbb.maxX) / 2.0D;
277 298 this.locY = axisalignedbb.minY;
278 299 this.locZ = (axisalignedbb.minZ + axisalignedbb.maxZ) / 2.0D;
279 300 + if (valid) world.entityJoinedWorld(this, false); // CraftBukkit
280 301 }
281 302
282 303 protected SoundEffect ad() {
283 -@@ -874,7 +1053,7 @@
304 +@@ -874,7 +1069,7 @@
284 305 return null;
285 306 }
286 307
287 308 - protected void burn(int i) {
288 309 + protected void burn(float i) { // CraftBukkit - int -> float
289 310 if (!this.fireProof) {
290 311 this.damageEntity(DamageSource.FIRE, (float) i);
291 312 }
292 -@@ -1093,6 +1272,13 @@
313 +@@ -1093,6 +1288,13 @@
293 314 }
294 315
295 316 public void spawnIn(World world) {
296 317 + // CraftBukkit start
297 318 + if (world == null) {
298 319 + die();
299 320 + this.world = ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle();
300 321 + return;
301 322 + }
302 323 + // CraftBukkit end
303 324 this.world = world;
304 325 }
305 326
306 -@@ -1118,6 +1304,7 @@
327 +@@ -1118,6 +1320,7 @@
307 328 this.lastYaw -= 360.0F;
308 329 }
309 330
310 331 + world.getChunkAt((int) Math.floor(this.locX) >> 4, (int) Math.floor(this.locZ) >> 4); // CraftBukkit
311 332 this.setPosition(this.locX, this.locY, this.locZ);
312 333 this.setYawPitch(f, f1);
313 334 }
314 -@@ -1300,7 +1487,7 @@
335 +@@ -1300,7 +1503,7 @@
315 336 public boolean c(NBTTagCompound nbttagcompound) {
316 337 String s = this.getSaveID();
317 338
318 339 - if (!this.dead && s != null) {
319 340 + if (this.persist && !this.dead && s != null) { // CraftBukkit - persist flag
320 341 nbttagcompound.setString("id", s);
321 342 this.save(nbttagcompound);
322 343 return true;
323 -@@ -1317,6 +1504,18 @@
344 +@@ -1317,6 +1520,18 @@
324 345 try {
325 346 nbttagcompound.set("Pos", this.a(this.locX, this.locY, this.locZ));
326 347 nbttagcompound.set("Motion", this.a(this.motX, this.motY, this.motZ));
327 348 +
328 349 + // CraftBukkit start - Checking for NaN pitch/yaw and resetting to zero
329 350 + // TODO: make sure this is the best way to address this.
330 351 + if (Float.isNaN(this.yaw)) {
331 352 + this.yaw = 0;
332 353 + }
333 354 +
334 355 + if (Float.isNaN(this.pitch)) {
335 356 + this.pitch = 0;
336 357 + }
337 358 + // CraftBukkit end
338 359 +
339 360 nbttagcompound.set("Rotation", this.a(this.yaw, this.pitch));
340 361 nbttagcompound.setFloat("FallDistance", this.fallDistance);
341 362 nbttagcompound.setShort("Fire", (short) this.fireTicks);
342 -@@ -1326,6 +1525,12 @@
363 +@@ -1326,6 +1541,12 @@
343 364 nbttagcompound.setBoolean("Invulnerable", this.invulnerable);
344 365 nbttagcompound.setInt("PortalCooldown", this.portalCooldown);
345 366 nbttagcompound.a("UUID", this.getUniqueID());
346 367 + // CraftBukkit start
347 368 + // PAIL: Check above UUID reads 1.8 properly, ie: UUIDMost / UUIDLeast
348 369 + nbttagcompound.setLong("WorldUUIDLeast", this.world.getDataManager().getUUID().getLeastSignificantBits());
349 370 + nbttagcompound.setLong("WorldUUIDMost", this.world.getDataManager().getUUID().getMostSignificantBits());
350 371 + nbttagcompound.setInt("Bukkit.updateLevel", CURRENT_LEVEL);
351 372 + // CraftBukkit end
352 373 IChatBaseComponent ichatbasecomponent = this.getCustomName();
353 374
354 375 if (ichatbasecomponent != null) {
355 -@@ -1402,6 +1607,8 @@
376 +@@ -1402,6 +1623,8 @@
356 377 this.motX = nbttaglist1.k(0);
357 378 this.motY = nbttaglist1.k(1);
358 379 this.motZ = nbttaglist1.k(2);
359 380 +
360 381 + /* CraftBukkit start - Moved section down
361 382 if (Math.abs(this.motX) > 10.0D) {
362 383 this.motX = 0.0D;
363 384 }
364 -@@ -1413,6 +1620,7 @@
385 +@@ -1413,6 +1636,7 @@
365 386 if (Math.abs(this.motZ) > 10.0D) {
366 387 this.motZ = 0.0D;
367 388 }
368 389 + // CraftBukkit end */
369 390
370 391 this.locX = nbttaglist.k(0);
371 392 this.locY = nbttaglist.k(1);
372 -@@ -1469,6 +1677,56 @@
393 +@@ -1469,6 +1693,56 @@
373 394 this.setPosition(this.locX, this.locY, this.locZ);
374 395 }
375 396
376 397 + // CraftBukkit start
377 398 + if (this instanceof EntityLiving) {
378 399 + EntityLiving entity = (EntityLiving) this;
379 400 +
380 401 + // Reset the persistence for tamed animals
381 402 + if (entity instanceof EntityTameableAnimal && !isLevelAtLeast(nbttagcompound, 2) && !nbttagcompound.getBoolean("PersistenceRequired")) {
382 403 + EntityInsentient entityinsentient = (EntityInsentient) entity;
419 440 + bworld = ((org.bukkit.craftbukkit.CraftServer) server).getServer().getWorldServer(DimensionManager.OVERWORLD).getWorld();
420 441 + }
421 442 +
422 443 + spawnIn(bworld == null? null : ((CraftWorld) bworld).getHandle());
423 444 + }
424 445 + // CraftBukkit end
425 446 +
426 447 } catch (Throwable throwable) {
427 448 CrashReport crashreport = CrashReport.a(throwable, "Loading entity NBT");
428 449 CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being loaded");
429 -@@ -1542,9 +1800,22 @@
450 +@@ -1542,9 +1816,22 @@
430 451 if (itemstack.isEmpty()) {
431 452 return null;
432 453 } else {
433 454 + // CraftBukkit start - Capture drops for death event
434 455 + if (this instanceof EntityLiving && !((EntityLiving) this).forceDrops) {
435 456 + ((EntityLiving) this).drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack));
436 457 + return null;
437 458 + }
438 459 + // CraftBukkit end
439 460 EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY + (double) f, this.locZ, itemstack);
442 463 + // CraftBukkit start
443 464 + EntityDropItemEvent event = new EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity());
444 465 + Bukkit.getPluginManager().callEvent(event);
445 466 + if (event.isCancelled()) {
446 467 + return null;
447 468 + }
448 469 + // CraftBukkit end
449 470 this.world.addEntity(entityitem);
450 471 return entityitem;
451 472 }
452 -@@ -1656,7 +1927,7 @@
473 +@@ -1656,7 +1943,7 @@
453 474 }
454 475
455 476 this.vehicle = entity;
456 477 - this.vehicle.addPassenger(this);
457 478 + if (!this.vehicle.addPassenger(this)) this.vehicle = null; // CraftBukkit
458 479 return true;
459 480 }
460 481 }
461 -@@ -1677,15 +1948,33 @@
482 +@@ -1677,15 +1964,33 @@
462 483 Entity entity = this.vehicle;
463 484
464 485 this.vehicle = null;
465 486 - entity.removePassenger(this);
466 487 + if (!entity.removePassenger(this)) this.vehicle = entity; // CraftBukkit
467 488 }
468 489
469 490 }
470 491
471 492 - protected void addPassenger(Entity entity) {
487 508 + CraftEntity craftn = (CraftEntity) entity.getBukkitEntity().getVehicle();
488 509 + Entity n = craftn == null ? null : craftn.getHandle();
489 510 + if (event.isCancelled() || n != orig) {
490 511 + return false;
491 512 + }
492 513 + }
493 514 + // CraftBukkit end
494 515 if (!this.world.isClientSide && entity instanceof EntityHuman && !(this.bO() instanceof EntityHuman)) {
495 516 this.passengers.add(0, entity);
496 517 } else {
497 -@@ -1693,15 +1982,33 @@
518 +@@ -1693,15 +1998,33 @@
498 519 }
499 520
500 521 }
501 522 + return true; // CraftBukkit
502 523 }
503 524
504 525 - protected void removePassenger(Entity entity) {
505 526 + protected boolean removePassenger(Entity entity) { // CraftBukkit
506 527 if (entity.getVehicle() == this) {
507 528 throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)");
522 543 + }
523 544 + }
524 545 + // CraftBukkit end
525 546 this.passengers.remove(entity);
526 547 entity.k = 60;
527 548 }
528 549 + return true; // CraftBukkit
529 550 }
530 551
531 552 protected boolean q(Entity entity) {
532 -@@ -1798,6 +2105,13 @@
553 +@@ -1798,6 +2121,13 @@
533 554 }
534 555
535 556 public void setSwimming(boolean flag) {
536 557 + // CraftBukkit start
537 558 + if (this.isSwimming() != flag && this instanceof EntityLiving) {
538 559 + if (CraftEventFactory.callToggleSwimEvent((EntityLiving) this, flag).isCancelled()) {
539 560 + return;
540 561 + }
541 562 + }
542 563 + // CraftBukkit end
543 564 this.setFlag(4, flag);
544 565 }
545 566
546 -@@ -1858,16 +2172,53 @@
567 +@@ -1858,16 +2188,53 @@
547 568 }
548 569
549 570 public void setAirTicks(int i) {
550 571 - this.datawatcher.set(Entity.aD, i);
551 572 + // CraftBukkit start
552 573 + EntityAirChangeEvent event = new EntityAirChangeEvent(this.getBukkitEntity(), i);
553 574 + event.getEntity().getServer().getPluginManager().callEvent(event);
554 575 + if (event.isCancelled()) {
555 576 + return;
556 577 + }
593 614 + }
594 615 + CraftEventFactory.entityDamage = entitylightning;
595 616 + if (!this.damageEntity(DamageSource.LIGHTNING, 5.0F)) {
596 617 + CraftEventFactory.entityDamage = null;
597 618 + return;
598 619 + }
599 620 + // CraftBukkit end
600 621 }
601 622
602 623 public void j(boolean flag) {
603 -@@ -2034,19 +2385,72 @@
624 +@@ -2034,19 +2401,72 @@
604 625 if (!this.world.isClientSide && !this.dead) {
605 626 this.world.methodProfiler.enter("changeDimension");
606 627 MinecraftServer minecraftserver = this.bK();
607 628 - DimensionManager dimensionmanager1 = this.dimension;
608 629 - WorldServer worldserver = minecraftserver.getWorldServer(dimensionmanager1);
609 630 - WorldServer worldserver1 = minecraftserver.getWorldServer(dimensionmanager);
610 631 + // CraftBukkit start - Move logic into new function "teleportTo(Location,boolean)"
611 632 + // DimensionManager dimensionmanager1 = this.dimension;
612 633 + // WorldServer worldserver = minecraftserver.getWorldServer(dimensionmanager1);
613 634 + // WorldServer worldserver1 = minecraftserver.getWorldServer(dimensionmanager);
669 690 }
670 691 + // CraftBukkit end */
671 692
672 693 this.world.kill(this);
673 694 this.dead = false;
674 695 this.world.methodProfiler.enter("reposition");
675 696 + /* CraftBukkit start - Handled in calculateTarget
676 697 BlockPosition blockposition;
677 698
678 699 if (dimensionmanager == DimensionManager.THE_END) {
679 -@@ -2075,12 +2479,18 @@
700 +@@ -2075,12 +2495,18 @@
680 701 blockposition = new BlockPosition(this);
681 702 }
682 703
683 704 - worldserver.entityJoinedWorld(this, false);
684 705 + // CraftBukkit end */
685 706 + // CraftBukkit start - Ensure chunks are loaded in case TravelAgent is not used which would initially cause chunks to load during find/create
686 707 + // minecraftserver.getPlayerList().changeWorld(this, j, worldserver, worldserver1);
687 708 + worldserver1.getMinecraftServer().getPlayerList().repositionEntity(this, exit, portal);
688 709 + // worldserver.entityJoinedWorld(this, false); // Handled in repositionEntity
689 710 + // CraftBukkit end
690 711 this.world.methodProfiler.exitEnter("reloading");
691 712 Entity entity = this.P().a((World) worldserver1);
692 713
693 714 if (entity != null) {
694 715 entity.v(this);
695 716 + /* CraftBukkit start - We need to do this...
696 717 if (dimensionmanager1 == DimensionManager.THE_END && dimensionmanager == DimensionManager.THE_END) {
697 718 BlockPosition blockposition1 = worldserver1.getHighestBlockYAt(HeightMap.Type.MOTION_BLOCKING_NO_LEAVES, worldserver1.getSpawn());
698 719
699 -@@ -2088,6 +2498,7 @@
720 +@@ -2088,6 +2514,7 @@
700 721 } else {
701 722 entity.setPositionRotation(blockposition, entity.yaw, entity.pitch);
702 723 }
703 724 + // CraftBukkit end */
704 725
705 726 boolean flag = entity.attachedToPlayer;
706 727
707 -@@ -2095,13 +2506,21 @@
728 +@@ -2095,13 +2522,21 @@
708 729 worldserver1.addEntity(entity);
709 730 entity.attachedToPlayer = flag;
710 731 worldserver1.entityJoinedWorld(entity, false);
711 732 + // CraftBukkit start - Forward the CraftEntity to the new entity
712 733 + this.getBukkitEntity().setHandle(entity);
713 734 + entity.bukkitEntity = this.getBukkitEntity();
714 735 +
715 736 + if (this instanceof EntityInsentient) {
716 737 + ((EntityInsentient)this).unleash(true, false); // Unleash to prevent duping of leads.
717 738 + }
720 741
721 742 this.dead = true;
722 743 this.world.methodProfiler.exit();
723 744 worldserver.p();
724 745 worldserver1.p();
725 746 - this.world.methodProfiler.exit();
726 747 + // this.world.methodProfiler.exit(); // CraftBukkit: Moved up to keep balanced
727 748 return entity;
728 749 } else {
729 750 return null;
730 -@@ -2241,7 +2660,26 @@
751 +@@ -2241,7 +2676,26 @@
731 752 }
732 753
733 754 public void a(AxisAlignedBB axisalignedbb) {
734 755 - this.boundingBox = axisalignedbb;
735 756 + // CraftBukkit start - block invalid bounding boxes
736 757 + double minX = axisalignedbb.minX,
737 758 + minY = axisalignedbb.minY,
738 759 + minZ = axisalignedbb.minZ,
739 760 + maxX = axisalignedbb.maxX,
740 761 + maxY = axisalignedbb.maxY,

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut