Commits
Brokkonaut authored and md_5 committed 049120068de
299 299 | + } |
300 300 | + |
301 301 | + if (Float.isNaN(this.pitch)) { |
302 302 | + this.pitch = 0; |
303 303 | + } |
304 304 | + // CraftBukkit end |
305 305 | + |
306 306 | nbttagcompound.set("Rotation", this.a(this.yaw, this.pitch)); |
307 307 | nbttagcompound.setFloat("FallDistance", this.fallDistance); |
308 308 | nbttagcompound.setShort("Fire", (short) this.fireTicks); |
309 - | |
309 + | |
310 310 | nbttagcompound.setBoolean("Invulnerable", this.invulnerable); |
311 311 | nbttagcompound.setInt("PortalCooldown", this.portalCooldown); |
312 312 | nbttagcompound.a("UUID", this.getUniqueID()); |
313 313 | + // CraftBukkit start |
314 314 | + // PAIL: Check above UUID reads 1.8 properly, ie: UUIDMost / UUIDLeast |
315 315 | + nbttagcompound.setLong("WorldUUIDLeast", ((WorldServer) this.world).getWorld().getUID().getLeastSignificantBits()); |
316 316 | + nbttagcompound.setLong("WorldUUIDMost", ((WorldServer) this.world).getWorld().getUID().getMostSignificantBits()); |
317 317 | + nbttagcompound.setInt("Bukkit.updateLevel", CURRENT_LEVEL); |
318 + | + if (!this.persist) { |
319 + | + nbttagcompound.setBoolean("Bukkit.persist", this.persist); |
320 + | + } |
318 321 | + // CraftBukkit end |
319 322 | IChatBaseComponent ichatbasecomponent = this.getCustomName(); |
320 323 | |
321 324 | if (ichatbasecomponent != null) { |
322 - | |
325 + | |
323 326 | } |
324 327 | } |
325 328 | |
326 329 | + // CraftBukkit start - stores eventually existing bukkit values |
327 330 | + if (this.bukkitEntity != null) { |
328 331 | + this.bukkitEntity.storeBukkitValues(nbttagcompound); |
329 332 | + } |
330 333 | + // CraftBukkit end |
331 334 | return nbttagcompound; |
332 335 | } catch (Throwable throwable) { |
333 336 | CrashReport crashreport = CrashReport.a(throwable, "Saving entity NBT"); |
334 - | |
337 + | |
335 338 | } else { |
336 339 | throw new IllegalStateException("Entity has invalid position"); |
337 340 | } |
338 341 | + |
339 342 | + // CraftBukkit start |
340 343 | + if (this instanceof EntityLiving) { |
341 344 | + EntityLiving entity = (EntityLiving) this; |
342 345 | + |
343 346 | + // Reset the persistence for tamed animals |
344 347 | + if (entity instanceof EntityTameableAnimal && !isLevelAtLeast(nbttagcompound, 2) && !nbttagcompound.getBoolean("PersistenceRequired")) { |
345 348 | + EntityInsentient entityinsentient = (EntityInsentient) entity; |
346 349 | + entityinsentient.persistent = !entityinsentient.isTypeNotPersistent(0); |
347 350 | + } |
348 351 | + } |
352 + | + this.persist = !nbttagcompound.hasKey("Bukkit.persist") || nbttagcompound.getBoolean("Bukkit.persist"); |
349 353 | + // CraftBukkit end |
350 354 | + |
351 355 | + // CraftBukkit start - Reset world |
352 356 | + if (this instanceof EntityPlayer) { |
353 357 | + Server server = Bukkit.getServer(); |
354 358 | + org.bukkit.World bworld = null; |
355 359 | + |
356 360 | + // TODO: Remove World related checks, replaced with WorldUID |
357 361 | + String worldName = nbttagcompound.getString("world"); |
358 362 | + |
368 372 | + } |
369 373 | + |
370 374 | + spawnIn(bworld == null ? null : ((CraftWorld) bworld).getHandle()); |
371 375 | + } |
372 376 | + this.getBukkitEntity().readBukkitValues(nbttagcompound); |
373 377 | + // CraftBukkit end |
374 378 | + |
375 379 | } catch (Throwable throwable) { |
376 380 | CrashReport crashreport = CrashReport.a(throwable, "Loading entity NBT"); |
377 381 | CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being loaded"); |
378 - | |
382 + | |
379 383 | } else if (this.world.isClientSide) { |
380 384 | return null; |
381 385 | } else { |
382 386 | + // CraftBukkit start - Capture drops for death event |
383 387 | + if (this instanceof EntityLiving && !((EntityLiving) this).forceDrops) { |
384 388 | + ((EntityLiving) this).drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); |
385 389 | + return null; |
386 390 | + } |
387 391 | + // CraftBukkit end |
388 392 | EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + (double) f, this.locZ(), itemstack); |
391 395 | + // CraftBukkit start |
392 396 | + EntityDropItemEvent event = new EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity()); |
393 397 | + Bukkit.getPluginManager().callEvent(event); |
394 398 | + if (event.isCancelled()) { |
395 399 | + return null; |
396 400 | + } |
397 401 | + // CraftBukkit end |
398 402 | this.world.addEntity(entityitem); |
399 403 | return entityitem; |
400 404 | } |
401 - | |
405 + | |
402 406 | |
403 407 | this.setPose(EntityPose.STANDING); |
404 408 | this.vehicle = entity; |
405 409 | - this.vehicle.addPassenger(this); |
406 410 | + if (!this.vehicle.addPassenger(this)) this.vehicle = null; // CraftBukkit |
407 411 | return true; |
408 412 | } |
409 413 | } |
410 - | |
414 + | |
411 415 | Entity entity = this.vehicle; |
412 416 | |
413 417 | this.vehicle = null; |
414 418 | - entity.removePassenger(this); |
415 419 | + if (!entity.removePassenger(this)) this.vehicle = entity; // CraftBukkit |
416 420 | } |
417 421 | |
418 422 | } |
419 - | |
423 + | |
420 424 | this.be(); |
421 425 | } |
422 426 | |
423 427 | - protected void addPassenger(Entity entity) { |
424 428 | + protected boolean addPassenger(Entity entity) { // CraftBukkit |
425 429 | if (entity.getVehicle() != this) { |
426 430 | throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)"); |
427 431 | } else { |
428 432 | + // CraftBukkit start |
429 433 | + com.google.common.base.Preconditions.checkState(!entity.passengers.contains(this), "Circular entity riding! %s %s", this, entity); |
442 446 | + CraftEntity craftn = (CraftEntity) entity.getBukkitEntity().getVehicle(); |
443 447 | + Entity n = craftn == null ? null : craftn.getHandle(); |
444 448 | + if (event.isCancelled() || n != orig) { |
445 449 | + return false; |
446 450 | + } |
447 451 | + } |
448 452 | + // CraftBukkit end |
449 453 | if (!this.world.isClientSide && entity instanceof EntityHuman && !(this.getRidingPassenger() instanceof EntityHuman)) { |
450 454 | this.passengers.add(0, entity); |
451 455 | } else { |
452 - | |
456 + | |
453 457 | } |
454 458 | |
455 459 | } |
456 460 | + return true; // CraftBukkit |
457 461 | } |
458 462 | |
459 463 | - protected void removePassenger(Entity entity) { |
460 464 | + protected boolean removePassenger(Entity entity) { // CraftBukkit |
461 465 | if (entity.getVehicle() == this) { |
462 466 | throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)"); |
480 484 | + } |
481 485 | + } |
482 486 | + // CraftBukkit end |
483 487 | this.passengers.remove(entity); |
484 488 | entity.j = 60; |
485 489 | } |
486 490 | + return true; // CraftBukkit |
487 491 | } |
488 492 | |
489 493 | protected boolean q(Entity entity) { |
490 - | |
494 + | |
491 495 | ResourceKey<World> resourcekey = this.world.getDimensionKey() == World.THE_NETHER ? World.OVERWORLD : World.THE_NETHER; |
492 496 | WorldServer worldserver1 = minecraftserver.getWorldServer(resourcekey); |
493 497 | |
494 498 | - if (worldserver1 != null && minecraftserver.getAllowNether() && !this.isPassenger() && this.portalTicks++ >= i) { |
495 499 | + if (true && !this.isPassenger() && this.portalTicks++ >= i) { // CraftBukkit |
496 500 | this.world.getMethodProfiler().enter("portal"); |
497 501 | this.portalTicks = i; |
498 502 | this.resetPortalCooldown(); |
499 503 | - this.b(worldserver1); |
500 504 | + // CraftBukkit start |
501 505 | + if (this instanceof EntityPlayer) { |
502 506 | + ((EntityPlayer) this).b(worldserver1, PlayerTeleportEvent.TeleportCause.NETHER_PORTAL); |
503 507 | + } else { |
504 508 | + this.b(worldserver1); |
505 509 | + } |
506 510 | + // CraftBukkit end |
507 511 | this.world.getMethodProfiler().exit(); |
508 512 | } |
509 513 | |
510 - | |
514 + | |
511 515 | } |
512 516 | |
513 517 | public void setSwimming(boolean flag) { |
514 518 | + // CraftBukkit start |
515 519 | + if (this.isSwimming() != flag && this instanceof EntityLiving) { |
516 520 | + if (CraftEventFactory.callToggleSwimEvent((EntityLiving) this, flag).isCancelled()) { |
517 521 | + return; |
518 522 | + } |
519 523 | + } |
520 524 | + // CraftBukkit end |
521 525 | this.setFlag(4, flag); |
522 526 | } |
523 527 | |
524 - | |
528 + | |
525 529 | } |
526 530 | |
527 531 | public void setAirTicks(int i) { |
528 532 | - this.datawatcher.set(Entity.AIR_TICKS, i); |
529 533 | + // CraftBukkit start |
530 534 | + EntityAirChangeEvent event = new EntityAirChangeEvent(this.getBukkitEntity(), i); |
531 535 | + // Suppress during worldgen |
532 536 | + if (this.valid) { |
533 537 | + event.getEntity().getServer().getPluginManager().callEvent(event); |
534 538 | + } |
574 578 | + } |
575 579 | + CraftEventFactory.entityDamage = entitylightning; |
576 580 | + if (!this.damageEntity(DamageSource.LIGHTNING, 5.0F)) { |
577 581 | + CraftEventFactory.entityDamage = null; |
578 582 | + return; |
579 583 | + } |
580 584 | + // CraftBukkit end |
581 585 | } |
582 586 | |
583 587 | public void k(boolean flag) { |
584 - | |
588 + | |
585 589 | |
586 590 | @Nullable |
587 591 | public Entity b(WorldServer worldserver) { |
588 592 | + // CraftBukkit start |
589 593 | + return teleportTo(worldserver, null); |
590 594 | + } |
591 595 | + |
592 596 | + @Nullable |
593 597 | + public Entity teleportTo(WorldServer worldserver, BlockPosition location) { |
594 598 | + // CraftBukkit end |
609 613 | return null; |
610 614 | } else { |
611 615 | + // CraftBukkit start |
612 616 | + worldserver = shapedetectorshape.world; |
613 617 | + this.decouple(); |
614 618 | + // CraftBukkit end |
615 619 | + |
616 620 | this.world.getMethodProfiler().exitEnter("reloading"); |
617 621 | Entity entity = this.getEntityType().a((World) worldserver); |
618 622 | |
619 - | |
623 + | |
620 624 | entity.setPositionRotation(shapedetectorshape.position.x, shapedetectorshape.position.y, shapedetectorshape.position.z, shapedetectorshape.yaw, entity.pitch); |
621 625 | entity.setMot(shapedetectorshape.velocity); |
622 626 | worldserver.addEntityTeleport(entity); |
623 627 | - if (worldserver.getDimensionKey() == World.THE_END) { |
624 628 | - WorldServer.a(worldserver); |
625 629 | + if (worldserver.getTypeKey() == DimensionManager.THE_END) { // CraftBukkit |
626 630 | + WorldServer.a(worldserver, this); // CraftBukkit |
627 631 | + } |
628 632 | + // CraftBukkit start - Forward the CraftEntity to the new entity |
629 633 | + this.getBukkitEntity().setHandle(entity); |
630 634 | + entity.bukkitEntity = this.getBukkitEntity(); |
631 635 | + |
632 636 | + if (this instanceof EntityInsentient) { |
633 637 | + ((EntityInsentient) this).unleash(true, false); // Unleash to prevent duping of leads. |
634 638 | } |
635 639 | + // CraftBukkit end |
636 640 | } |
637 641 | |
638 642 | this.bM(); |
639 - | |
643 + | |
640 644 | |
641 645 | @Nullable |
642 646 | protected ShapeDetectorShape a(WorldServer worldserver) { |
643 647 | - boolean flag = this.world.getDimensionKey() == World.THE_END && worldserver.getDimensionKey() == World.OVERWORLD; |
644 648 | - boolean flag1 = worldserver.getDimensionKey() == World.THE_END; |
645 649 | + // CraftBukkit start |
646 650 | + if (worldserver == null) { |
647 651 | + return null; |
648 652 | + } |
649 653 | + boolean flag = this.world.getTypeKey() == DimensionManager.THE_END && worldserver.getTypeKey() == DimensionManager.OVERWORLD; // fromEndToOverworld |
652 656 | |
653 657 | if (!flag && !flag1) { |
654 658 | - boolean flag2 = worldserver.getDimensionKey() == World.THE_NETHER; |
655 659 | + boolean flag2 = worldserver.getTypeKey() == DimensionManager.THE_NETHER; // CraftBukkit |
656 660 | |
657 661 | - if (this.world.getDimensionKey() != World.THE_NETHER && !flag2) { |
658 662 | + if (this.world.getTypeKey() != DimensionManager.THE_NETHER && !flag2) { |
659 663 | return null; |
660 664 | } else { |
661 665 | WorldBorder worldborder = worldserver.getWorldBorder(); |
662 - | |
666 + | |
663 667 | double d3 = Math.min(2.9999872E7D, worldborder.h() - 16.0D); |
664 668 | double d4 = DimensionManager.a(this.world.getDimensionManager(), worldserver.getDimensionManager()); |
665 669 | BlockPosition blockposition = new BlockPosition(MathHelper.a(this.locX() * d4, d0, d2), this.locY(), MathHelper.a(this.locZ() * d4, d1, d3)); |
666 670 | + // CraftBukkit start |
667 671 | + CraftPortalEvent event = callPortalEvent(this, worldserver, blockposition, PlayerTeleportEvent.TeleportCause.NETHER_PORTAL, flag2 ? 16 : 128, 16); |
668 672 | + if (event == null) { |
669 673 | + return null; |
670 674 | + } |
671 675 | + final WorldServer worldserverFinal = worldserver = ((CraftWorld) event.getTo().getWorld()).getHandle(); |
672 676 | + blockposition = new BlockPosition(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()); |
673 677 | |
674 678 | - return (ShapeDetectorShape) this.a(worldserver, blockposition, flag2).map((blockutil_rectangle) -> { |
675 679 | + return (ShapeDetectorShape) this.a(worldserver, blockposition, flag2, event.getSearchRadius(), event.getCanCreatePortal(), event.getCreationRadius()).map((blockutil_rectangle) -> { |
676 680 | + // CraftBukkit end |
677 681 | IBlockData iblockdata = this.world.getType(this.ac); |
678 682 | EnumDirection.EnumAxis enumdirection_enumaxis; |
679 683 | Vec3D vec3d; |
680 - | |
684 + | |
681 685 | vec3d = new Vec3D(0.5D, 0.0D, 0.0D); |
682 686 | } |
683 687 | |
684 688 | - return BlockPortalShape.a(worldserver, blockutil_rectangle, enumdirection_enumaxis, vec3d, this.a(this.getPose()), this.getMot(), this.yaw, this.pitch); |
685 689 | - }).orElse((Object) null); |
686 690 | + return BlockPortalShape.a(worldserverFinal, blockutil_rectangle, enumdirection_enumaxis, vec3d, this.a(this.getPose()), this.getMot(), this.yaw, this.pitch, event); // CraftBukkit |
687 691 | + }).orElse(null); // CraftBuukkit - decompile error |
688 692 | } |
689 693 | } else { |
690 694 | BlockPosition blockposition1; |
691 - | |
695 + | |
692 696 | } else { |
693 697 | blockposition1 = worldserver.getHighestBlockYAt(HeightMap.Type.MOTION_BLOCKING_NO_LEAVES, worldserver.getSpawn()); |
694 698 | } |
695 699 | + // CraftBukkit start |
696 700 | + CraftPortalEvent event = callPortalEvent(this, worldserver, blockposition1, PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0); |
697 701 | + if (event == null) { |
698 702 | + return null; |
699 703 | + } |
700 704 | + blockposition1 = new BlockPosition(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()); |
701 705 | |
702 706 | - return new ShapeDetectorShape(new Vec3D((double) blockposition1.getX() + 0.5D, (double) blockposition1.getY(), (double) blockposition1.getZ() + 0.5D), this.getMot(), this.yaw, this.pitch); |
703 707 | + return new ShapeDetectorShape(new Vec3D((double) blockposition1.getX() + 0.5D, (double) blockposition1.getY(), (double) blockposition1.getZ() + 0.5D), this.getMot(), this.yaw, this.pitch, ((CraftWorld) event.getTo().getWorld()).getHandle(), event); |
704 708 | + // CraftBukkit end |
705 709 | } |
706 710 | } |
707 711 | |
708 - | |
712 + | |
709 713 | return BlockPortalShape.a(blockutil_rectangle, enumdirection_enumaxis, this.getPositionVector(), this.a(this.getPose())); |
710 714 | } |
711 715 | |
712 716 | - protected Optional<BlockUtil.Rectangle> a(WorldServer worldserver, BlockPosition blockposition, boolean flag) { |
713 717 | - return worldserver.getTravelAgent().findPortal(blockposition, flag); |
714 718 | + // CraftBukkit start |
715 719 | + protected CraftPortalEvent callPortalEvent(Entity entity, WorldServer exitWorldServer, BlockPosition exitPosition, PlayerTeleportEvent.TeleportCause cause, int searchRadius, int creationRadius) { |
716 720 | + org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity(); |
717 721 | + Location enter = bukkitEntity.getLocation(); |
718 722 | + Location exit = new Location(exitWorldServer.getWorld(), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()); |
724 728 | + } |
725 729 | + return new CraftPortalEvent(event); |
726 730 | + } |
727 731 | + |
728 732 | + protected Optional<BlockUtil.Rectangle> a(WorldServer worldserver, BlockPosition blockposition, boolean flag, int searchRadius, boolean canCreatePortal, int createRadius) { // PAIL rename findOrCreatePortal |
729 733 | + return worldserver.getTravelAgent().findPortal(blockposition, searchRadius); |
730 734 | + // CraftBukkit end |
731 735 | } |
732 736 | |
733 737 | public boolean canPortal() { |
734 - | |
738 + | |
735 739 | } |
736 740 | |
737 741 | public void a(AxisAlignedBB axisalignedbb) { |
738 742 | - this.boundingBox = axisalignedbb; |
739 743 | + // CraftBukkit start - block invalid bounding boxes |
740 744 | + double minX = axisalignedbb.minX, |
741 745 | + minY = axisalignedbb.minY, |
742 746 | + minZ = axisalignedbb.minZ, |
743 747 | + maxX = axisalignedbb.maxX, |
744 748 | + maxY = axisalignedbb.maxY, |