Skip to content

Commit c1408c2

Browse files
authored
Position riders before API teleportation (#13342)
1 parent a729264 commit c1408c2

10 files changed

Lines changed: 177 additions & 105 deletions

File tree

paper-server/patches/features/0001-Moonrise-optimisation-patches.patch

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24589,7 +24589,7 @@ index 5e5aad112058b567214c28ccd719271f12240a35..cd5a325d37f617431ceb568a65570160
2458924589

2459024590
@FunctionalInterface
2459124591
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
24592-
index 095617b58c955121e1dcf84246691c20fb3c5b74..513d6ea15d2b3577c649182422f051639d7fea49 100644
24592+
index 4a9e9707bebe85e26d28260b389e236156ba5637..c3da011196e9cac1d90b2ae40952680e0fbd90a1 100644
2459324593
--- a/net/minecraft/server/level/ChunkMap.java
2459424594
+++ b/net/minecraft/server/level/ChunkMap.java
2459524595
@@ -124,10 +124,7 @@ public class ChunkMap extends SimpleRegionStorage implements ChunkHolder.PlayerP
@@ -26459,7 +26459,7 @@ index a701288146a1d7cd258faae69f959edf466ec71c..3509df9dd423b38d1ca3e4a420d1352a
2645926459
}
2646026460

2646126461
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
26462-
index 5e0d2bbd9223f727ec337357ee7d0088eff11ab8..3d6765f284d1817d68db4d9ae0d90c7e73e6e068 100644
26462+
index 229035e15113419080187263c7fa5e004a12c3f3..550b915d4ed457231605247c3e21844fed2f67b6 100644
2646326463
--- a/net/minecraft/server/level/ServerChunkCache.java
2646426464
+++ b/net/minecraft/server/level/ServerChunkCache.java
2646526465
@@ -54,7 +54,7 @@ import net.minecraft.world.level.storage.SavedDataStorage;
@@ -27757,7 +27757,7 @@ index ce5bd957dbfe52cd81e571359c6de1028dc11cde..5bb8ddc9490ce6c7bc4544ef0ea05484
2775727757
"Server weather",
2775827758
() -> String.format(
2775927759
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
27760-
index 82ba52a9a265c113ed01ecd60957e97a6172445a..88173a3775734ca271d9ff6a7a253eeb343a82a4 100644
27760+
index b569df775fcc9885b7cfee1b8280b68f33f4cd71..220409fd6335e17445e1acdbfac8d83ae36a99b4 100644
2776127761
--- a/net/minecraft/server/level/ServerPlayer.java
2776227762
+++ b/net/minecraft/server/level/ServerPlayer.java
2776327763
@@ -206,7 +206,7 @@ import net.minecraft.world.scores.criteria.ObjectiveCriteria;
@@ -28864,7 +28864,7 @@ index 09b6da207530987b483444cebeadc2f1c9a15247..3666c3efd188508153b6482db425648e
2886428864
+ // Paper end - block counting
2886528865
}
2886628866
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
28867-
index 745aa8356fca102c6980363d126bfd6b23415b12..ba0cdbd064ad3e0cf645c50ab14adcddef48e932 100644
28867+
index d8e2adefabb1de2506faa0e6789801b3d1f0203a..0682b5a6d828141f50c62ff5ea56d5bbb25e1004 100644
2886828868
--- a/net/minecraft/world/entity/Entity.java
2886928869
+++ b/net/minecraft/world/entity/Entity.java
2887028870
@@ -164,7 +164,7 @@ public abstract class Entity
@@ -29332,7 +29332,7 @@ index 745aa8356fca102c6980363d126bfd6b23415b12..ba0cdbd064ad3e0cf645c50ab14adcdd
2933229332
}
2933329333

2933429334
public InteractionResult interact(final Player player, final InteractionHand hand, final Vec3 location) {
29335-
@@ -4440,15 +4677,17 @@ public abstract class Entity
29335+
@@ -4447,15 +4684,17 @@ public abstract class Entity
2933629336
}
2933729337

2933829338
public Iterable<Entity> getIndirectPassengers() {
@@ -29358,7 +29358,7 @@ index 745aa8356fca102c6980363d126bfd6b23415b12..ba0cdbd064ad3e0cf645c50ab14adcdd
2935829358
}
2935929359

2936029360
public int countPlayerPassengers() {
29361-
@@ -4759,6 +4998,15 @@ public abstract class Entity
29361+
@@ -4766,6 +5005,15 @@ public abstract class Entity
2936229362
}
2936329363

2936429364
public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) {
@@ -29374,7 +29374,7 @@ index 745aa8356fca102c6980363d126bfd6b23415b12..ba0cdbd064ad3e0cf645c50ab14adcdd
2937429374
if (!checkPosition(this, x, y, z)) {
2937529375
return;
2937629376
}
29377-
@@ -4908,6 +5156,12 @@ public abstract class Entity
29377+
@@ -4915,6 +5163,12 @@ public abstract class Entity
2937829378

2937929379
@Override
2938029380
public final void setRemoved(final Entity.RemovalReason reason, org.bukkit.event.entity.EntityRemoveEvent.@Nullable Cause cause) { // CraftBukkit - add Bukkit remove cause
@@ -29387,7 +29387,7 @@ index 745aa8356fca102c6980363d126bfd6b23415b12..ba0cdbd064ad3e0cf645c50ab14adcdd
2938729387
org.bukkit.craftbukkit.event.CraftEventFactory.callEntityRemoveEvent(this, cause); // CraftBukkit
2938829388
final boolean alreadyRemoved = this.removalReason != null; // Paper - Folia schedulers
2938929389
if (this.removalReason == null) {
29390-
@@ -4918,7 +5172,7 @@ public abstract class Entity
29390+
@@ -4925,7 +5179,7 @@ public abstract class Entity
2939129391
this.stopRiding();
2939229392
}
2939329393

@@ -29396,7 +29396,7 @@ index 745aa8356fca102c6980363d126bfd6b23415b12..ba0cdbd064ad3e0cf645c50ab14adcdd
2939629396
this.levelCallback.onRemove(reason);
2939729397
this.onRemoval(reason);
2939829398
// Paper start - Folia schedulers
29399-
@@ -4952,7 +5206,7 @@ public abstract class Entity
29399+
@@ -4959,7 +5213,7 @@ public abstract class Entity
2940029400
public boolean shouldBeSaved() {
2940129401
return (this.removalReason == null || this.removalReason.shouldSave())
2940229402
&& !this.isPassenger()

paper-server/patches/features/0017-Optimise-EntityScheduler-ticking.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ index b1f5741d5d714f57795c53605db87d86ebb07051..b71f2e181334ad8646afb48c704c30b6
6666
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.ADVENTURE_CLICK_MANAGER.handleQueue(this.tickCount); // Paper
6767
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.DIALOG_CLICK_MANAGER.handleQueue(this.tickCount); // Paper
6868
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
69-
index 68855c16d2cb3e5b7d7a86f05e7bb2e7922a5ba0..1530810cdb74810e37e3e22ce4fcda4ee7511055 100644
69+
index abd46a9bdfa6d387e866e192230aa1f07e5c8936..0fa6006a7c344f9f12972008e586b4c1f03c470e 100644
7070
--- a/net/minecraft/world/entity/Entity.java
7171
+++ b/net/minecraft/world/entity/Entity.java
72-
@@ -5223,6 +5223,11 @@ public abstract class Entity
72+
@@ -5230,6 +5230,11 @@ public abstract class Entity
7373
this.getBukkitEntity().taskScheduler.retire();
7474
}
7575
// Paper end - Folia schedulers

paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@
597597
}
598598

599599
@Override
600-
@@ -1004,24 +_,98 @@
600+
@@ -1004,24 +_,87 @@
601601
return this.level().isPvpAllowed();
602602
}
603603

@@ -684,18 +684,7 @@
684684
+ location = respawnEvent.getRespawnLocation();
685685
+
686686
+ return new RespawnResult(
687-
+ new TeleportTransition(
688-
+ ((org.bukkit.craftbukkit.CraftWorld) location.getWorld()).getHandle(),
689-
+ org.bukkit.craftbukkit.util.CraftLocation.toVec3(location),
690-
+ teleportTransition.deltaMovement(),
691-
+ location.getYaw(),
692-
+ location.getPitch(),
693-
+ teleportTransition.missingRespawnBlock(),
694-
+ teleportTransition.asPassenger(),
695-
+ teleportTransition.relatives(),
696-
+ teleportTransition.postTeleportTransition(),
697-
+ teleportTransition.cause()
698-
+ ),
687+
+ teleportTransition.withChangedLocation(location),
699688
+ isBedSpawn,
700689
+ isAnchorSpawn
701690
+ );
@@ -744,7 +733,7 @@
744733
if (this.isRemoved()) {
745734
return null;
746735
}
747-
@@ -1103,12 +_,46 @@
736+
@@ -1103,12 +_,36 @@
748737
ServerLevel newLevel = transition.newLevel();
749738
ServerLevel oldLevel = this.level();
750739
ResourceKey<Level> lastDimension = oldLevel.dimension();
@@ -769,17 +758,7 @@
769758
+ }
770759
+ if (!newExit.equals(exit)) {
771760
+ newLevel = ((org.bukkit.craftbukkit.CraftWorld) newExit.getWorld()).getHandle();
772-
+ transition = new TeleportTransition(
773-
+ newLevel,
774-
+ org.bukkit.craftbukkit.util.CraftLocation.toVec3(newExit),
775-
+ Vec3.ZERO,
776-
+ newExit.getYaw(),
777-
+ newExit.getPitch(),
778-
+ transition.missingRespawnBlock(),
779-
+ transition.asPassenger(),
780-
+ Set.of(),
781-
+ transition.postTeleportTransition(),
782-
+ transition.cause());
761+
+ transition = transition.withChangedLocation(newExit).withVelocity(Vec3.ZERO).withRelatives(Set.of());
783762
+ }
784763
+ // CraftBukkit end
785764
if (!transition.asPassenger()) {

paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@
14861486
+ }
14871487
+ if (!to.equals(teleEvent.getTo())) {
14881488
+ to = teleEvent.getTo();
1489-
+ transition = new TeleportTransition(((org.bukkit.craftbukkit.CraftWorld) to.getWorld()).getHandle(), org.bukkit.craftbukkit.util.CraftLocation.toVec3(to), Vec3.ZERO, to.getYaw(), to.getPitch(), transition.missingRespawnBlock(), transition.asPassenger(), Set.of(), transition.postTeleportTransition(), transition.cause());
1489+
+ transition = transition.withChangedLocation(to).withVelocity(Vec3.ZERO).withRelatives(Set.of());
14901490
+ // Paper start - Call EntityPortalExitEvent
14911491
+ velocity = Vec3.ZERO;
14921492
+ }
@@ -1512,7 +1512,7 @@
15121512
+ to = event.getTo().clone();
15131513
+ velocity = org.bukkit.craftbukkit.util.CraftVector.toVec3(event.getAfter());
15141514
+ }
1515-
+ transition = new TeleportTransition(((org.bukkit.craftbukkit.CraftWorld) to.getWorld()).getHandle(), org.bukkit.craftbukkit.util.CraftLocation.toVec3(to), velocity, to.getYaw(), to.getPitch(), transition.missingRespawnBlock(), transition.asPassenger(), Set.of(), transition.postTeleportTransition(), transition.cause());
1515+
+ transition = transition.withChangedLocation(to).withRelatives(Set.of()).withVelocity(velocity);
15161516
+ }
15171517
+ }
15181518
+ if (this.isRemoved()) {
@@ -1540,6 +1540,20 @@
15401540

15411541
for (Entity newPassenger : newPassengers) {
15421542
newPassenger.startRiding(newEntity, true, false);
1543+
@@ -3126,6 +_,13 @@
1544+
private TeleportTransition calculatePassengerTransition(final TeleportTransition transition, final Entity passenger) {
1545+
float passengerYRot = transition.yRot() + (transition.relatives().contains(Relative.Y_ROT) ? 0.0F : passenger.getYRot() - this.getYRot());
1546+
float passengerXRot = transition.xRot() + (transition.relatives().contains(Relative.X_ROT) ? 0.0F : passenger.getXRot() - this.getXRot());
1547+
+ // Paper start - reposition entity as rider when teleporting via API call
1548+
+ // This change is mostly required for plugins teleporting entities *every* tick with passengers, specifically player passengers.
1549+
+ // The relative teleport of players, which base their location on the server -> client -> server teleport packet cycle, means player
1550+
+ // positions can quickly be desynced from their rider position, leading to infinitely growing offsets from their vehicle.
1551+
+ // The addition to the teleport transition allows existing callers to this method to not accidentally mutate the entity state.
1552+
+ if (transition.passengerTeleportationMode() == TeleportTransition.PassengerTeleportationMode.POSITION_RIDER) this.positionRider(passenger);
1553+
+ // Paper end - reposition entity as rider when teleporting via API call
1554+
Vec3 passengerOffset = passenger.position().subtract(this.position());
1555+
Vec3 passengerPos = transition.position()
1556+
.add(
15431557
@@ -3187,9 +_,17 @@
15441558
}
15451559

@@ -1600,7 +1614,7 @@
16001614
+ // CraftBukkit end
16011615
Entity newEntity = this.teleport(
16021616
- new TeleportTransition(level, new Vec3(x, y, z), Vec3.ZERO, newYRot, newXRot, relatives, TeleportTransition.DO_NOTHING)
1603-
+ new TeleportTransition(level, new Vec3(x, y, z), Vec3.ZERO, newYRot, newXRot, relatives, TeleportTransition.DO_NOTHING, cause) // CraftBukkit
1617+
+ new TeleportTransition(level, new Vec3(x, y, z), Vec3.ZERO, newYRot, newXRot, relatives, TeleportTransition.DO_NOTHING).withCause(cause) // CraftBukkit
16041618
);
16051619
return newEntity != null;
16061620
}

paper-server/patches/sources/net/minecraft/world/entity/projectile/throwableitemprojectile/ThrownEnderpearl.java.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
+ final double preTeleportX = player.getX(), preTeleportY = player.getY(), preTeleportZ = player.getZ();
1010
+ final float preTeleportYRot = player.getYRot(), preTeleportXRot = player.getXRot();
1111
+ ServerPlayer newOwner = player.teleport(new TeleportTransition(
12-
+ level, teleportPos, Vec3.ZERO, 0.0F, 0.0F, Relative.union(Relative.ROTATION, Relative.DELTA), TeleportTransition.DO_NOTHING, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.ENDER_PEARL));
12+
+ level, teleportPos, Vec3.ZERO, 0.0F, 0.0F, Relative.union(Relative.ROTATION, Relative.DELTA), TeleportTransition.DO_NOTHING).withCause(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.ENDER_PEARL));
1313
+ if (newOwner == null) {
1414
+ this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.HIT);
1515
+ return;

paper-server/patches/sources/net/minecraft/world/level/block/EndGatewayBlock.java.patch

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@
2121
} else {
2222
return entity instanceof ThrownEnderpearl
2323
- ? new TeleportTransition(currentLevel, teleportPosition, Vec3.ZERO, 0.0F, 0.0F, Set.of(), TeleportTransition.PLACE_PORTAL_TICKET)
24-
+ ? new TeleportTransition(currentLevel, teleportPosition, Vec3.ZERO, 0.0F, 0.0F, Set.of(), TeleportTransition.PLACE_PORTAL_TICKET, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_GATEWAY) // CraftBukkit
24+
+ ? new TeleportTransition(currentLevel, teleportPosition, Vec3.ZERO, 0.0F, 0.0F, Set.of(), TeleportTransition.PLACE_PORTAL_TICKET).withCause(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_GATEWAY) // CraftBukkit
2525
: new TeleportTransition(
2626
currentLevel,
2727
teleportPosition,
28-
@@ -119,7 +_,8 @@
29-
0.0F,
28+
@@ -120,7 +_,7 @@
3029
0.0F,
3130
Relative.union(Relative.DELTA, Relative.ROTATION),
32-
- TeleportTransition.PLACE_PORTAL_TICKET
33-
+ TeleportTransition.PLACE_PORTAL_TICKET,
34-
+ org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_GATEWAY // CraftBukkit
35-
);
31+
TeleportTransition.PLACE_PORTAL_TICKET
32+
- );
33+
+ ).withCause(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_GATEWAY); // CraftBukkit;
3634
}
3735
} else {
36+
return null;

paper-server/patches/sources/net/minecraft/world/level/block/EndPortalBlock.java.patch

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
yRot = Direction.WEST.toYRot();
3535
xRot = 0.0F;
3636
relatives = Relative.union(Relative.DELTA, Set.of(Relative.X_ROT));
37-
@@ -104,15 +_,26 @@
37+
@@ -104,15 +_,32 @@
3838
xRot = respawnData.pitch();
3939
relatives = Relative.union(Relative.DELTA, Relative.ROTATION);
4040
if (entity instanceof ServerPlayer serverPlayer) {
@@ -57,8 +57,15 @@
5757
+
5858
return new TeleportTransition(
5959
- newLevel, spawnPos, Vec3.ZERO, yRot, xRot, relatives, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET)
60-
+ ((org.bukkit.craftbukkit.CraftWorld) to.getWorld()).getHandle(), org.bukkit.craftbukkit.util.CraftLocation.toVec3(to), Vec3.ZERO, to.getYaw(), to.getPitch(), relatives, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_PORTAL
61-
);
60+
- );
61+
+ ((org.bukkit.craftbukkit.CraftWorld) to.getWorld()).getHandle(),
62+
+ org.bukkit.craftbukkit.util.CraftLocation.toVec3(to),
63+
+ Vec3.ZERO,
64+
+ to.getYaw(),
65+
+ to.getPitch(),
66+
+ relatives,
67+
+ TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET)
68+
+ ).withCause(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_PORTAL);
6269
+ // CraftBukkit end
6370
}
6471

paper-server/patches/sources/net/minecraft/world/level/block/NetherPortalBlock.java.patch

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@
119119

120120
return getDimensionTransitionFromExit(entity, portalEntryPos, exitPortal, newLevel, post);
121121
}
122-
@@ -236,7 +_,7 @@
123-
);
122+
@@ -237,7 +_,7 @@
124123
Vec3 collisionFreePos = PortalShape.findCollisionFreePosition(targetPos, newLevel, entity, dimensions);
125124
return new TeleportTransition(
126-
- newLevel, collisionFreePos, Vec3.ZERO, outputRotation, 0.0F, Relative.union(Relative.DELTA, Relative.ROTATION), postTeleportTransition
127-
+ newLevel, collisionFreePos, Vec3.ZERO, outputRotation, 0.0F, Relative.union(Relative.DELTA, Relative.ROTATION), postTeleportTransition, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.NETHER_PORTAL // CraftBukkit
128-
);
125+
newLevel, collisionFreePos, Vec3.ZERO, outputRotation, 0.0F, Relative.union(Relative.DELTA, Relative.ROTATION), postTeleportTransition
126+
- );
127+
+ ).withCause(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.NETHER_PORTAL); // CraftBukkit
129128
}
130129

130+
@Override

0 commit comments

Comments
 (0)