Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EndPortal teleport entity's delta movement #11884

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23552,7 +23552,7 @@ index 2b46ca9a2a046063cad422bec00d76107537b091..9aa664537cc37e44db46d5a2a64ae311
thread1 -> {
DedicatedServer dedicatedServer1 = new DedicatedServer(
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index b92a3da5c325e69f5601416d4205fb33429742b3..d967d605c2e4227ae980c30f1c8b86edbc680d6d 100644
index 5ef7a016a0c7bc09d5cd24f14124b15b99d5e18d..2769b3cb17b8101dd90fb95d3853d6083fd0c3e2 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -173,7 +173,7 @@ import net.minecraft.world.phys.Vec2;
Expand Down Expand Up @@ -27496,7 +27496,7 @@ index 192977dd661ee795ada13db895db770293e9b402..95a4e37a3c93f9b3c56c7a7376ed521c
}

diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index 097ec55166b9e9269142be58992c29687122fe28..aeabb79512aabd7a9e8af1be72e1745f0e7eefe4 100644
index 472693a7d10dc67b116db02e3e4472adbc5a4d62..422db52e8a0a08350542670bfc9ba94ad9481d0c 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -178,7 +178,7 @@ import net.minecraft.world.scores.Team;
Expand Down Expand Up @@ -28372,7 +28372,7 @@ index 8cc5c0716392ba06501542ff5cbe71ee43979e5d..09fd99c9cbd23b5f3c899bfb00c9b896
+ // Paper end - block counting
}
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 189385600b9094291152035b17df869eaccc0428..25a1089a7376f0cbd96bb43b5c203640c88fc282 100644
index b23d3fd56d0c796047bef39fb562e41b993b3d8e..518e28965b9fcd31f42e29cfbdddfa1a7e34bf82 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -135,7 +135,7 @@ import net.minecraft.world.scores.ScoreHolder;
Expand Down Expand Up @@ -28849,7 +28849,7 @@ index 189385600b9094291152035b17df869eaccc0428..25a1089a7376f0cbd96bb43b5c203640
}

public InteractionResult interact(Player player, InteractionHand hand) {
@@ -4102,15 +4337,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4110,15 +4345,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}

public Iterable<Entity> getIndirectPassengers() {
Expand All @@ -28875,7 +28875,7 @@ index 189385600b9094291152035b17df869eaccc0428..25a1089a7376f0cbd96bb43b5c203640
}

public int countPlayerPassengers() {
@@ -4248,77 +4485,136 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4256,77 +4493,136 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return Mth.lerp(partialTick, this.yRotO, this.yRot);
}

Expand Down Expand Up @@ -29066,7 +29066,7 @@ index 189385600b9094291152035b17df869eaccc0428..25a1089a7376f0cbd96bb43b5c203640

public boolean touchingUnloadedChunk() {
AABB aabb = this.getBoundingBox().inflate(1.0);
@@ -4471,6 +4767,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4479,6 +4775,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.setPosRaw(x, y, z, false);
}
public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) {
Expand All @@ -29082,7 +29082,7 @@ index 189385600b9094291152035b17df869eaccc0428..25a1089a7376f0cbd96bb43b5c203640
if (!checkPosition(this, x, y, z)) {
return;
}
@@ -4601,6 +4906,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4609,6 +4914,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess

@Override
public final void setRemoved(Entity.RemovalReason removalReason, org.bukkit.event.entity.EntityRemoveEvent.Cause cause) {
Expand All @@ -29095,7 +29095,7 @@ index 189385600b9094291152035b17df869eaccc0428..25a1089a7376f0cbd96bb43b5c203640
org.bukkit.craftbukkit.event.CraftEventFactory.callEntityRemoveEvent(this, cause);
// CraftBukkit end
final boolean alreadyRemoved = this.removalReason != null; // Paper - Folia schedulers
@@ -4612,7 +4923,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4620,7 +4931,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.stopRiding();
}

Expand All @@ -29104,7 +29104,7 @@ index 189385600b9094291152035b17df869eaccc0428..25a1089a7376f0cbd96bb43b5c203640
this.levelCallback.onRemove(removalReason);
this.onRemoval(removalReason);
// Paper start - Folia schedulers
@@ -4646,7 +4957,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4654,7 +4965,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
public boolean shouldBeSaved() {
return (this.removalReason == null || this.removalReason.shouldSave())
&& !this.isPassenger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@
CompoundTag compoundTag = entity.saveWithoutId(new CompoundTag());
compoundTag.remove("Dimension");
this.load(compoundTag);
@@ -2688,7 +_,56 @@
@@ -2688,7 +_,64 @@

@Nullable
public Entity teleport(TeleportTransition teleportTransition) {
Expand Down Expand Up @@ -1394,17 +1394,25 @@
+ }
+ if (this.portalProcess != null) { // if in a portal
+ org.bukkit.craftbukkit.entity.CraftEntity bukkitEntity = this.getBukkitEntity();
+ org.bukkit.util.Vector after = org.bukkit.craftbukkit.util.CraftVector.toBukkit(velocity);
+ org.bukkit.event.entity.EntityPortalExitEvent event = new org.bukkit.event.entity.EntityPortalExitEvent(
+ bukkitEntity,
+ bukkitEntity.getLocation(), to.clone(),
+ bukkitEntity.getVelocity(), org.bukkit.craftbukkit.util.CraftVector.toBukkit(velocity)
+ bukkitEntity.getVelocity(), after
+ );
+ event.callEvent();
+
+ // Only change the target if actually needed, since we reset relative flags
+ if (!event.isCancelled() && event.getTo() != null && (!event.getTo().equals(event.getFrom()) || !event.getAfter().equals(event.getBefore()))) {
+ to = event.getTo().clone();
+ velocity = org.bukkit.craftbukkit.util.CraftVector.toNMS(event.getAfter());
+ if (event.isCancelled() || (!to.equals(event.getTo()) || !after.equals(event.getAfter()))) {
+ if (!event.isCancelled()) {
+ if (event.getTo() != null) {
+ to = event.getTo().clone();
+ }
+ velocity = org.bukkit.craftbukkit.util.CraftVector.toNMS(event.getAfter());
+ } else {
+ to = event.getFrom().clone();
+ velocity = Vec3.ZERO;
+ }
+ teleportTransition = new TeleportTransition(((org.bukkit.craftbukkit.CraftWorld) to.getWorld()).getHandle(), org.bukkit.craftbukkit.util.CraftLocation.toVec3D(to), velocity, to.getYaw(), to.getPitch(), teleportTransition.missingRespawnBlock(), teleportTransition.asPassenger(), Set.of(), teleportTransition.postTeleportTransition(), teleportTransition.cause());
+ }
+ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
- level1, bottomCenter, Vec3.ZERO, f, 0.0F, set, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET)
- );
+ // CraftBukkit start
+ org.bukkit.craftbukkit.event.CraftPortalEvent event = entity.callPortalEvent(entity, org.bukkit.craftbukkit.util.CraftLocation.toBukkit(bottomCenter, level1.getWorld(), f, entity.getXRot()), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0);
+ org.bukkit.craftbukkit.event.CraftPortalEvent event = entity.callPortalEvent(entity, org.bukkit.craftbukkit.util.CraftLocation.toBukkit(bottomCenter, level1.getWorld(), f, 0.0F), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0); // Paper - default vanilla
+ if (event == null) {
+ return null;
+ }
+ org.bukkit.Location to = event.getTo();
+
+ return new TeleportTransition(((org.bukkit.craftbukkit.CraftWorld) to.getWorld()).getHandle(), org.bukkit.craftbukkit.util.CraftLocation.toVec3D(to), entity.getDeltaMovement(), to.getYaw(), to.getPitch(), set, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_PORTAL);
+ return new TeleportTransition(((org.bukkit.craftbukkit.CraftWorld) to.getWorld()).getHandle(), org.bukkit.craftbukkit.util.CraftLocation.toVec3D(to), Vec3.ZERO, to.getYaw(), to.getPitch(), set, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_PORTAL); // Paper - fix TeleportTransition deltaMovement as vanilla
+ // CraftBukkit end
}
}
Expand Down
Loading