-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Teleportation API #6562
Teleportation API #6562
Conversation
Added new API for support relative teleportation + look at api. (Code for handling the position packet flags on client) boolean hasXFlag = packet.getFlags().contains(PlayerPositionLookS2CPacket.Flag.X);
boolean hasYFlag = packet.getFlags().contains(PlayerPositionLookS2CPacket.Flag.Y);
boolean hasZFlag = packet.getFlags().contains(PlayerPositionLookS2CPacket.Flag.Z);
double newXVelocity;
double newXCoord;
if (hasXFlag) {
newXVelocity = vec3d.getX();
newXCoord = playerEntity.getX() + packet.getX();
playerEntity.lastRenderX += packet.getX();
} else {
newXVelocity = 0.0D;
newXCoord = packet.getX();
playerEntity.lastRenderX = newXCoord;
}
double newYVelocity;
double newYCoord;
if (hasYFlag) {
newYVelocity = vec3d.getY();
newYCoord = playerEntity.getY() + packet.getY();
playerEntity.lastRenderY += packet.getY();
} else {
newYVelocity = 0.0D;
newYCoord = packet.getY();
playerEntity.lastRenderY = newYCoord;
}
double newZVelocity;
double newZCoord;
if (hasZFlag) {
newZVelocity = vec3d.getZ();
newZCoord = playerEntity.getZ() + packet.getZ();
playerEntity.lastRenderZ += packet.getZ();
} else {
newZVelocity = 0.0D;
newZCoord = packet.getZ();
playerEntity.lastRenderZ = newZCoord;
} This allows you to change a specific coordinate without causing the entire player's velocity to be reset. For example, setting the player's yaw/pitch while allowing the player to move freely. Unsure if this should be in the same patch, but this also includes look at api for players. |
c8df6f3
to
c495468
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the concept of relative teleportation flags is introduced, should those also be mirrored (be modified by) the PlayerTeleportEvent ?
Looking into this a bit more, this would require a bit more changes than I would like here. As alot of methods just hide these parameters (see this one) Additionally, it seems in some places the relative flags are removed completely. So, opinions would be appreciated. |
I agree, I don't think they are a 100% necessity especially with how incredibly niche the flags are anyway. At least the usage of these should be documented better in terms of javadocs though. Reading var finalLocation = new Location(player.getWorld(), 0, 1, 0, 0, 0);
player.teleport(finalLocation, PlayerTeleportEvent.TeleportCause.PLUGIN, false, false, RelativeTeleportFlag.values()); does still teleport the player to [0,1,0] and only has a client side effect in regards to cancelled motion. While event additions might not be required due to how few teleportations will actually use these (and want others to mutate them), documentation then becomes just the more important. |
Ahhh, so perhaps I did not actually describe it well enough in my PR. This does cause the player to be moved relatively 0 1 0. The behavior can be seen by using the teleport command and using /teleport @p ~ ~1 ~ Perhaps then a new type of teleport like |
Did you actually test this behaviour then ? Looking at the this.awaitingTeleportTime = this.tickCount;
this.player.moveTo(d0, d1, d2, f, f1); // Paper - use proper setPositionRotation for teleportation
this.player.forceCheckHighPriority(); // Paper
this.player.connection.send(new ClientboundPlayerPositionPacket(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.awaitingTeleport, flag)); Your method still just passed through the then "relative" or partially "relative" location, resulting in the behaviour I described above. Example listener showing the issue, teleporting the player to [0,0,0] instead of keeping them at their current position. @EventHandler
public void on(final PlayerDropItemEvent event) {
var relativeMotion = new Location(event.getPlayer().getWorld(), 0, 0, 0);
event.getPlayer().teleport(relativeMotion, PlayerTeleportEvent.TeleportCause.PLUGIN, true, false, RelativeTeleportFlag.values());
} |
You are totally correct here. I think I did some really botched testing, so I appreciate you double-checking me here. Again, thank you very much. |
I tried changing the documentation, do you have any feedback? |
I like it 👍 could you reflect the additional information in the parameter description ? -+ * @param teleportFlags Coordinates of the location that should be relative instead of absolute
++ * @param teleportFlags Coordinates of the location that the client should handle as relative teleportation. Just to ensure no one actually reads it and believes the flags cause any form of mutation to the final location. Your addition already covered it but half of the people barely read the javadocs, let alone something after the first |
Fair, thank you for all ur feedback lynx. I do appreciate it. |
d458f9e
to
6135340
Compare
Rebased and resolved. Changed keep passengers to ignore passengers, added throw javadoc and added stuff as default interface methods. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Shoo |
6135340
to
b68aa3b
Compare
rebased |
b68aa3b
to
2189bd9
Compare
Is there a reason you can't teleport with a vehicle or passenger to another world? If there is no technical reason stopping this the extra work might be worth considering to make the API simpler to use. If that can't be done I think the API should at least just return false in this case instead of throwing an exception. |
I’ll have to play around, I didn’t try messing with that too much as generally looking at how other people did cross world teleportation it seemed to be quite a large task. So, ill see if it works nicely or not. |
The Minecraft method itself forcibly removes passengers.. and judging how there is no logic for handling them either I don't think doing this is very safe. |
2189bd9
to
881fccc
Compare
Rebased |
881fccc
to
4e93d80
Compare
4e93d80
to
f4a1405
Compare
b3baddd
to
e350818
Compare
Rebase |
e350818
to
d20d49f
Compare
Rebased, all methods and classes have been marked with @org.jetbrains.annotations.ApiStatus.Experimental |
d20d49f
to
5284bbe
Compare
Rebased.... |
5284bbe
to
1e0429e
Compare
Rebased! |
This expands the teleport API to allow for teleporting entities while keeping passengers and allowing to teleport the player while keeping the player mounted.
⭐ Teleporting player while keeping passengers and dismounting
https://user-images.githubusercontent.com/23108066/132114747-25568ff0-7f46-4186-84ce-064903781465.mp4
The idea of this PR is to essentially allow
Keeping passengers when teleporting entities
Allowing the entity being teleported to stay mounted when teleported
Behavior (keepPassengers, dismount):
So basically it will return false if keepPassengers is false and they have passengers
Tested with players and entities, seems to work just fine. Feedback appreciated!