Skip to content

Commit d98142e

Browse files
authored
Rework API teleportation to better align with Vanilla (#13181)
Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> This patch includes extensive changes to teleport logic in the API to better represent vanilla behavior. In particular, teleporting with passengers is now supported by default. This also allows for entities to be teleported across dimensions with passengers, except for players, which is still not supported. Entity state related teleportation flags have been deprecated, as that behavior occurs by default now. Additionally, relative teleportation flags are now supported on entities.  Most importantly, we no longer hack onto the respawn logic when teleporting players between dimensions in the API. This is a good step towards working on no longer reusing player entities on dimension swap, which is something we are trying to no longer do as it causes a large amount of desync issues on the client/server.  Entity teleportation via /tp now aligns with vanilla too, which now maintains velocity when teleporting.  This is a breaking change.
1 parent 080a72f commit d98142e

24 files changed

+444
-614
lines changed

paper-api/src/main/java/io/papermc/paper/entity/TeleportFlag.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
package io.papermc.paper.entity;
22

33
import org.bukkit.Location;
4+
import org.bukkit.entity.Entity;
5+
import org.bukkit.entity.Player;
46
import org.bukkit.event.player.PlayerTeleportEvent;
57

68
/**
79
* Represents a flag that can be set on teleportation that may
810
* slightly modify the behavior.
911
*
10-
* @see EntityState
1112
* @see Relative
1213
*/
1314
public sealed interface TeleportFlag permits TeleportFlag.EntityState, TeleportFlag.Relative {
1415

1516
/**
16-
* Note: These flags only work on {@link org.bukkit.entity.Player} entities.
17-
* <p>
18-
* Relative flags enable a player to not lose their velocity in the flag-specific axis/context when teleporting.
17+
* Relative flags enable an entity to not lose their velocity in the flag-specific axis/context when teleporting.
1918
*
2019
* @apiNote The relative flags exposed in the API do *not* mirror all flags known to vanilla, as relative flags concerning
2120
* the position are non-applicable given teleports always expect an absolute location.
22-
* @see org.bukkit.entity.Player#teleport(Location, PlayerTeleportEvent.TeleportCause, TeleportFlag...)
21+
* @see Player#teleport(Location, PlayerTeleportEvent.TeleportCause, TeleportFlag...)
22+
* @see Entity#teleport(Location, PlayerTeleportEvent.TeleportCause, TeleportFlag...)
2323
*/
2424
enum Relative implements TeleportFlag {
2525
/**
@@ -40,6 +40,7 @@ enum Relative implements TeleportFlag {
4040
VELOCITY_ROTATION;
4141
/**
4242
* Configures the player to not lose velocity in their x axis during the teleport.
43+
*
4344
* @deprecated Since 1.21.3, vanilla split up the relative teleport flags into velocity and position related
4445
* ones. As the API does not deal with position relative flags, this name is no longer applicable.
4546
* Use {@link #VELOCITY_X} instead.
@@ -48,6 +49,7 @@ enum Relative implements TeleportFlag {
4849
public static final Relative X = VELOCITY_X;
4950
/**
5051
* Configures the player to not lose velocity in their y axis during the teleport.
52+
*
5153
* @deprecated Since 1.21.3, vanilla split up the relative teleport flags into velocity and position related
5254
* ones. As the API does not deal with position relative flags, this name is no longer applicable.
5355
* Use {@link #VELOCITY_Y} instead.
@@ -56,6 +58,7 @@ enum Relative implements TeleportFlag {
5658
public static final Relative Y = VELOCITY_Y;
5759
/**
5860
* Configures the player to not lose velocity in their z axis during the teleport.
61+
*
5962
* @deprecated Since 1.21.3, vanilla split up the relative teleport flags into velocity and position related
6063
* ones. As the API does not deal with position relative flags, this name is no longer applicable.
6164
* Use {@link #VELOCITY_Z} instead.
@@ -83,30 +86,45 @@ enum Relative implements TeleportFlag {
8386
/**
8487
* Represents flags that effect the entity's state on
8588
* teleportation.
89+
*
90+
* @deprecated As of 1.21.10, the default behavior for teleportation is now aligned with vanilla
91+
* behavior. This means all of these flags are functionally done by default.
8692
*/
93+
@Deprecated(since = "1.21.10", forRemoval = true)
8794
enum EntityState implements TeleportFlag {
8895
/**
8996
* If all passengers should not be required to be removed prior to teleportation.
9097
* <p>
9198
* Note:
9299
* Teleporting to a different world with this flag present while the entity has entities riding it
93100
* will cause this teleportation to return false and not occur.
101+
*
102+
* @deprecated This is now default behavior in teleportation. If you want to dismount all passengers,
103+
* remove them with {@link Entity#removePassenger(Entity)}.
94104
*/
105+
@Deprecated(since = "1.21.10", forRemoval = true)
95106
RETAIN_PASSENGERS,
96107
/**
97108
* If the entity should not be dismounted if they are riding another entity.
98109
* <p>
99110
* Note:
100111
* Teleporting to a different world with this flag present while this entity is riding another entity will
101112
* cause this teleportation to return false and not occur.
113+
*
114+
* @deprecated This behavior was highly technical and is not replicatable due to client limitations,
115+
* and has not functioned for many updates.
102116
*/
117+
@Deprecated(since = "1.21.10", forRemoval = true)
103118
RETAIN_VEHICLE,
104119
/**
105120
* Indicates that a player should not have their current open inventory closed when teleporting.
106121
* <p>
107122
* Note:
108123
* This option will be ignored when teleported to a different world.
124+
*
125+
* @deprecated No longer done on teleportation, use {@link Player#closeInventory()} to do this yourself.
109126
*/
127+
@Deprecated(since = "1.21.10", forRemoval = true)
110128
RETAIN_OPEN_INVENTORY;
111129
}
112130

paper-api/src/main/java/org/bukkit/entity/Entity.java

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
138138
// Paper start - Teleport API
139139
/**
140140
* Teleports this entity to the given location.
141+
* <p>
142+
* Note: This uses default in game behavior for teleportation, especially in regard to handling
143+
* passengers and vehicles across dimensions. It should be noted at this moment, teleporting a {@link Player}
144+
* with passengers across dimensions is not supported and will cause this to return false. This behavior may
145+
* change in future versions.
141146
*
142147
* @param location New location to teleport this entity to
143148
* @param teleportFlags Flags to be used in this teleportation
@@ -149,6 +154,11 @@ default boolean teleport(@NotNull Location location, @NotNull io.papermc.paper.e
149154

150155
/**
151156
* Teleports this entity to the given location.
157+
* <p>
158+
* Note: This uses default in game behavior for teleportation, especially in regard to handling
159+
* passengers and vehicles across dimensions. It should be noted at this moment, teleporting a {@link Player}
160+
* with passengers across dimensions is not supported and will cause this to return false. This behavior may
161+
* change in future versions.
152162
*
153163
* @param location New location to teleport this entity to
154164
* @param cause The cause of this teleportation
@@ -179,17 +189,25 @@ default void lookAt(@NotNull io.papermc.paper.math.Position position, @NotNull L
179189
// Paper end - Teleport API
180190

181191
/**
182-
* Teleports this entity to the given location. If this entity is riding a
183-
* vehicle, it will be dismounted prior to teleportation.
192+
* Teleports this entity to the given location.
193+
* <p>
194+
* Note: This uses default in game behavior for teleportation, especially in regard to handling
195+
* passengers and vehicles across dimensions. It should be noted at this moment, teleporting a {@link Player}
196+
* with passengers across dimensions is not supported and will cause this to return false. This behavior may
197+
* change in future versions.
184198
*
185199
* @param location New location to teleport this entity to
186200
* @return <code>true</code> if the teleport was successful
187201
*/
188202
public boolean teleport(@NotNull Location location);
189203

190204
/**
191-
* Teleports this entity to the given location. If this entity is riding a
192-
* vehicle, it will be dismounted prior to teleportation.
205+
* Teleports this entity to the given location.
206+
* <p>
207+
* Note: This uses default in game behavior for teleportation, especially in regard to handling
208+
* passengers and vehicles across dimensions. It should be noted at this moment, teleporting a {@link Player}
209+
* with passengers across dimensions is not supported and will cause this to return false. This behavior may
210+
* change in future versions.
193211
*
194212
* @param location New location to teleport this entity to
195213
* @param cause The cause of this teleportation
@@ -198,17 +216,25 @@ default void lookAt(@NotNull io.papermc.paper.math.Position position, @NotNull L
198216
public boolean teleport(@NotNull Location location, @NotNull TeleportCause cause);
199217

200218
/**
201-
* Teleports this entity to the target Entity. If this entity is riding a
202-
* vehicle, it will be dismounted prior to teleportation.
219+
* Teleports this entity to the target Entity.
220+
* <p>
221+
* Note: This uses default in game behavior for teleportation, especially in regard to handling
222+
* passengers and vehicles across dimensions. It should be noted at this moment, teleporting a {@link Player}
223+
* with passengers across dimensions is not supported and will cause this to return false. This behavior may
224+
* change in future versions.
203225
*
204226
* @param destination Entity to teleport this entity to
205227
* @return <code>true</code> if the teleport was successful
206228
*/
207229
public boolean teleport(@NotNull Entity destination);
208230

209231
/**
210-
* Teleports this entity to the target Entity. If this entity is riding a
211-
* vehicle, it will be dismounted prior to teleportation.
232+
* Teleports this entity to the target Entity.
233+
* <p>
234+
* Note: This uses default in game behavior for teleportation, especially in regard to handling
235+
* passengers and vehicles across dimensions. It should be noted at this moment, teleporting a {@link Player}
236+
* with passengers across dimensions is not supported and will cause this to return false. This behavior may
237+
* change in future versions.
212238
*
213239
* @param destination Entity to teleport this entity to
214240
* @param cause The cause of this teleportation
@@ -219,6 +245,12 @@ default void lookAt(@NotNull io.papermc.paper.math.Position position, @NotNull L
219245
// Paper start
220246
/**
221247
* Loads/Generates(in 1.13+) the Chunk asynchronously, and then teleports the entity when the chunk is ready.
248+
* <p>
249+
* Note: This uses default in game behavior for teleportation, especially in regard to handling
250+
* passengers and vehicles across dimensions. It should be noted at this moment, teleporting a {@link Player}
251+
* with passengers across dimensions is not supported and will cause the future to return false. This behavior may
252+
* change in future versions.
253+
*
222254
* @param loc Location to teleport to
223255
* @return A future that will be completed with the result of the teleport
224256
*/
@@ -228,6 +260,12 @@ default void lookAt(@NotNull io.papermc.paper.math.Position position, @NotNull L
228260

229261
/**
230262
* Loads/Generates(in 1.13+) the Chunk asynchronously, and then teleports the entity when the chunk is ready.
263+
* <p>
264+
* Note: This uses default in game behavior for teleportation, especially in regard to handling
265+
* passengers and vehicles across dimensions. It should be noted at this moment, teleporting a {@link Player}
266+
* with passengers across dimensions is not supported and will cause the future to return false. This behavior may
267+
* change in future versions.
268+
*
231269
* @param loc Location to teleport to
232270
* @param cause Reason for teleport
233271
* @return A future that will be completed with the result of the teleport
@@ -241,9 +279,16 @@ final class Holder {
241279

242280
/**
243281
* Loads/Generates(in 1.13+) the Chunk asynchronously, and then teleports the entity when the chunk is ready.
282+
* <p>
283+
* Note: This uses default in game behavior for teleportation, especially in regard to handling
284+
* passengers and vehicles across dimensions. It should be noted at this moment, teleporting a {@link Player}
285+
* with passengers across dimensions is not supported and will cause the future to return false. This behavior may
286+
* change in future versions.
287+
*
244288
* @param loc Location to teleport to
245289
* @param cause Reason for teleport
246290
* @param teleportFlags Flags to be used in this teleportation
291+
*
247292
* @return A future that will be completed with the result of the teleport
248293
*/
249294
java.util.concurrent.@NotNull CompletableFuture<Boolean> teleportAsync(@NotNull Location loc, @NotNull TeleportCause cause, @NotNull io.papermc.paper.entity.TeleportFlag @NotNull... teleportFlags);

paper-api/src/main/java/org/bukkit/event/inventory/InventoryCloseEvent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ public enum Reason {
7777
UNKNOWN,
7878
/**
7979
* Player is teleporting
80+
*
81+
* @deprecated As of 1.21.10, this is not called anymore as inventories are not closed on teleportation.
8082
*/
83+
@Deprecated(since = "1.21.10")
8184
TELEPORT,
8285
/**
8386
* Player is no longer permitted to use this inventory

0 commit comments

Comments
 (0)