Commits

Phoenix616 authored and md_5 committed 74a5cc8a782
#994: Fix changing world in portal events not updating used world border

Also clamp the event's target location to the world border
No tags

nms-patches/net/minecraft/world/entity/Entity.patch

Modified
655 655 + this.getBukkitEntity().setHandle(entity);
656 656 + entity.bukkitEntity = this.getBukkitEntity();
657 657 +
658 658 + if (this instanceof EntityInsentient) {
659 659 + ((EntityInsentient) this).dropLeash(true, false); // Unleash to prevent duping of leads.
660 660 }
661 661 + // CraftBukkit end
662 662 }
663 663
664 664 this.removeAfterChangingDimensions();
665 -@@ -2389,20 +2774,33 @@
665 +@@ -2389,20 +2774,34 @@
666 666
667 667 @Nullable
668 668 protected ShapeDetectorShape findDimensionEntryPoint(WorldServer worldserver) {
669 669 - boolean flag = this.level.dimension() == World.END && worldserver.dimension() == World.OVERWORLD;
670 670 - boolean flag1 = worldserver.dimension() == World.END;
671 671 + // CraftBukkit start
672 672 + if (worldserver == null) {
673 673 + return null;
674 674 + }
675 675 + boolean flag = this.level.getTypeKey() == WorldDimension.END && worldserver.getTypeKey() == WorldDimension.OVERWORLD; // fromEndToOverworld
686 686 } else {
687 687 WorldBorder worldborder = worldserver.getWorldBorder();
688 688 double d0 = DimensionManager.getTeleportationScale(this.level.dimensionType(), worldserver.dimensionType());
689 689 BlockPosition blockposition = worldborder.clampToBounds(this.getX() * d0, this.getY(), this.getZ() * d0);
690 690 + // CraftBukkit start
691 691 + CraftPortalEvent event = callPortalEvent(this, worldserver, blockposition, PlayerTeleportEvent.TeleportCause.NETHER_PORTAL, flag2 ? 16 : 128, 16);
692 692 + if (event == null) {
693 693 + return null;
694 694 + }
695 695 + final WorldServer worldserverFinal = worldserver = ((CraftWorld) event.getTo().getWorld()).getHandle();
696 -+ blockposition = new BlockPosition(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ());
696 ++ worldborder = worldserverFinal.getWorldBorder();
697 ++ blockposition = worldborder.clampToBounds(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ());
697 698
698 699 - return (ShapeDetectorShape) this.getExitPortal(worldserver, blockposition, flag2, worldborder).map((blockutil_rectangle) -> {
699 700 + return (ShapeDetectorShape) this.getExitPortal(worldserver, blockposition, flag2, worldborder, event.getSearchRadius(), event.getCanCreatePortal(), event.getCreationRadius()).map((blockutil_rectangle) -> {
700 701 + // CraftBukkit end
701 702 IBlockData iblockdata = this.level.getBlockState(this.portalEntrancePos);
702 703 EnumDirection.EnumAxis enumdirection_enumaxis;
703 704 Vec3D vec3d;
704 -@@ -2419,8 +2817,8 @@
705 +@@ -2419,8 +2818,8 @@
705 706 vec3d = new Vec3D(0.5D, 0.0D, 0.0D);
706 707 }
707 708
708 709 - return BlockPortalShape.createPortalInfo(worldserver, blockutil_rectangle, enumdirection_enumaxis, vec3d, this.getDimensions(this.getPose()), this.getDeltaMovement(), this.getYRot(), this.getXRot());
709 710 - }).orElse((Object) null);
710 711 + return BlockPortalShape.createPortalInfo(worldserverFinal, blockutil_rectangle, enumdirection_enumaxis, vec3d, this.getDimensions(this.getPose()), this.getDeltaMovement(), this.getYRot(), this.getXRot(), event); // CraftBukkit
711 712 + }).orElse(null); // CraftBuukkit - decompile error
712 713 }
713 714 } else {
714 715 BlockPosition blockposition1;
715 -@@ -2430,8 +2828,15 @@
716 +@@ -2430,8 +2829,15 @@
716 717 } else {
717 718 blockposition1 = worldserver.getHeightmapPos(HeightMap.Type.MOTION_BLOCKING_NO_LEAVES, worldserver.getSharedSpawnPos());
718 719 }
719 720 + // CraftBukkit start
720 721 + CraftPortalEvent event = callPortalEvent(this, worldserver, blockposition1, PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0);
721 722 + if (event == null) {
722 723 + return null;
723 724 + }
724 725 + blockposition1 = new BlockPosition(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ());
725 726
726 727 - return new ShapeDetectorShape(new Vec3D((double) blockposition1.getX() + 0.5D, (double) blockposition1.getY(), (double) blockposition1.getZ() + 0.5D), this.getDeltaMovement(), this.getYRot(), this.getXRot());
727 728 + return new ShapeDetectorShape(new Vec3D((double) blockposition1.getX() + 0.5D, (double) blockposition1.getY(), (double) blockposition1.getZ() + 0.5D), this.getDeltaMovement(), this.getYRot(), this.getXRot(), ((CraftWorld) event.getTo().getWorld()).getHandle(), event);
728 729 + // CraftBukkit end
729 730 }
730 731 }
731 732
732 -@@ -2439,8 +2844,23 @@
733 +@@ -2439,8 +2845,23 @@
733 734 return BlockPortalShape.getRelativePosition(blockutil_rectangle, enumdirection_enumaxis, this.position(), this.getDimensions(this.getPose()));
734 735 }
735 736
736 737 - protected Optional<BlockUtil.Rectangle> getExitPortal(WorldServer worldserver, BlockPosition blockposition, boolean flag, WorldBorder worldborder) {
737 738 - return worldserver.getPortalForcer().findPortalAround(blockposition, flag, worldborder);
738 739 + // CraftBukkit start
739 740 + protected CraftPortalEvent callPortalEvent(Entity entity, WorldServer exitWorldServer, BlockPosition exitPosition, PlayerTeleportEvent.TeleportCause cause, int searchRadius, int creationRadius) {
740 741 + org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity();
741 742 + Location enter = bukkitEntity.getLocation();
742 743 + Location exit = new Location(exitWorldServer.getWorld(), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ());
748 749 + }
749 750 + return new CraftPortalEvent(event);
750 751 + }
751 752 +
752 753 + protected Optional<BlockUtil.Rectangle> getExitPortal(WorldServer worldserver, BlockPosition blockposition, boolean flag, WorldBorder worldborder, int searchRadius, boolean canCreatePortal, int createRadius) {
753 754 + return worldserver.getPortalForcer().findPortalAround(blockposition, worldborder, searchRadius);
754 755 + // CraftBukkit end
755 756 }
756 757
757 758 public boolean canChangeDimensions() {
758 -@@ -2649,7 +3069,26 @@
759 +@@ -2649,7 +3070,26 @@
759 760 }
760 761
761 762 public final void setBoundingBox(AxisAlignedBB axisalignedbb) {
762 763 - this.bb = axisalignedbb;
763 764 + // CraftBukkit start - block invalid bounding boxes
764 765 + double minX = axisalignedbb.minX,
765 766 + minY = axisalignedbb.minY,
766 767 + minZ = axisalignedbb.minZ,
767 768 + maxX = axisalignedbb.maxX,
768 769 + maxY = axisalignedbb.maxY,
776 777 + if (len > 64) maxY = minY + 64.0;
777 778 +
778 779 + len = axisalignedbb.maxZ - axisalignedbb.minZ;
779 780 + if (len < 0) maxZ = minZ;
780 781 + if (len > 64) maxZ = minZ + 64.0;
781 782 + this.bb = new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ);
782 783 + // CraftBukkit end
783 784 }
784 785
785 786 protected float getEyeHeight(EntityPose entitypose, EntitySize entitysize) {
786 -@@ -2933,6 +3372,11 @@
787 +@@ -2933,6 +3373,11 @@
787 788 vec3d = vec3d.add(vec3d1);
788 789 ++k1;
789 790 }
790 791 + // CraftBukkit start - store last lava contact location
791 792 + if (tag == TagsFluid.LAVA) {
792 793 + this.lastLavaContact = blockposition_mutableblockposition.immutable();
793 794 + }
794 795 + // CraftBukkit end
795 796 }
796 797 }
797 798 }

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

Add shortcut