Skip to content

Commit df48a8f

Browse files
authored
feat: entity teleportation API (#378)
1 parent 53c47c3 commit df48a8f

File tree

3 files changed

+71
-27
lines changed

3 files changed

+71
-27
lines changed

config/sidebar.paper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ const paper: SidebarsConfig = {
138138
"dev/api/pdc",
139139
"dev/api/custom-inventory-holder",
140140
"dev/api/scheduler",
141+
"dev/api/entity-teleport",
141142
"dev/api/plugin-messaging",
142143
"dev/api/plugin-configs",
143144
"dev/api/folia-support",
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
slug: /dev/entity-teleport
3+
description: The entity teleportation API and how to use it.
4+
---
5+
6+
# Entity Teleportation
7+
8+
Entities can be instantaneously teleported to specific positions, synchronously and asynchronously with the
9+
<Javadoc name={"org.bukkit.entity.Entity#teleport(org.bukkit.Location)"}>`teleport`</Javadoc> and
10+
<Javadoc name={"org.bukkit.entity.Entity#teleportAsync(org.bukkit.Location)"}>`teleportAsync`</Javadoc> API.
11+
12+
```java
13+
entity.teleport(location); // teleports the entity synchronously
14+
15+
entity.teleportAsync(location).thenAccept(success -> { // teleports the entity asynchronously
16+
// this code is ran when the teleport completes
17+
// the Future is completed on the main thread, so it is safe to use the API here
18+
19+
if (success) {
20+
// the entity was teleported successfully!
21+
}
22+
});
23+
```
24+
25+
## Look at
26+
27+
The <Javadoc name={"org.bukkit.entity.Player#lookAt(io.papermc.paper.math.Position,io.papermc.paper.entity.LookAnchor)"}>`lookAt`</Javadoc>
28+
API allows you to make a player look at a certain position or entity.
29+
30+
```java
31+
player.lookAt(
32+
position,
33+
LookAnchor.EYES // the player's eyes will be facing the position
34+
);
35+
36+
player.lookAt(
37+
entity,
38+
LookAnchor.EYES // the player's eyes will be facing the entity
39+
LookAnchor.FEET // the player will be facing the entity's feet
40+
);
41+
```
42+
43+
## Teleport flags
44+
45+
Teleport flags offer a way to teleport entities whilst being able to customize behavior.
46+
This allows you to do things like teleport players using relative flags and being able to retain passengers.
47+
48+
All available teleport flags can be found in the <Javadoc name={"io.papermc.paper.entity.TeleportFlag"}>`TeleportFlag`</Javadoc> class.
49+
50+
### Relative teleportation
51+
52+
Teleport a player relatively, preventing velocity from being reset in the X, Y and Z axes.
53+
54+
```java
55+
player.teleport(
56+
location,
57+
TeleportFlag.Relative.X,
58+
TeleportFlag.Relative.Y,
59+
TeleportFlag.Relative.Z
60+
);
61+
```
62+
63+
### Retaining passengers
64+
65+
Teleport an entity with the <Javadoc name={"io.papermc.paper.entity.TeleportFlag$EntityState#RETAIN_PASSENGERS"}>`RETAIN_PASSENGERS`</Javadoc> flag,
66+
allowing its passengers to be transferred with the entity.
67+
68+
```java
69+
entity.teleport(location, TeleportFlag.EntityState.RETAIN_PASSENGERS);
70+
```

docs/paper/dev/api/roadmap.mdx

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,6 @@ continue to function and will have their underlying instance replaced automatica
3535

3636
This is done to help reduce possible inconsistencies between world switching between Vanilla and Paper.
3737

38-
## Experimental API
39-
40-
### Teleport flags
41-
42-
Teleport flags offer a way to teleport entities whilst being able to customize behavior.
43-
This allows you to do things like teleport players using relative flags and being able to retain passengers.
44-
45-
This API is currently finalized and will be marked as stable in a future release.
46-
47-
#### Player teleportation
48-
Teleport a player relatively, preventing velocity from being reset in the X, Y and Z axes.
49-
```java
50-
player.teleport(
51-
location,
52-
TeleportFlag.Relative.X,
53-
TeleportFlag.Relative.Y,
54-
TeleportFlag.Relative.Z
55-
);
56-
```
57-
58-
#### Vehicle teleportation
59-
Teleport an entity with the <Javadoc name={"io.papermc.paper.entity.TeleportFlag$EntityState#RETAIN_PASSENGERS"}>`RETAIN_PASSENGERS`</Javadoc> flag,
60-
allowing its passengers to be transferred with the entity.
61-
```java
62-
entity.teleport(location, TeleportFlag.EntityState.RETAIN_PASSENGERS);
63-
```
64-
6538
## Deprecation policy
6639

6740
:::warning

0 commit comments

Comments
 (0)