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

Reworked Vehicle PlayerMoveEvent Handling #11835

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Owen1212055
Copy link
Member

@Owen1212055 Owen1212055 commented Dec 27, 2024

Reworked Vehicle PlayerMoveEvent Handling

The PlayerMoveEvent is triggered whenever a player controls a vehicle.
This event is generally broken, and does not represent what is actually happen. For example, the event used the player's location as the "from" position and the vehicle's location as the "to" position. This caused significant issues and confusion:

  • Teleporting the player from within this event was undone later by a positionPassengers call, rendering setTo calls effectively useless.
  • Cancelling the event led to desyncs and odd behavior, such as the player being rapidly teleported between two locations.
  • The event was not giving a straightforward way to control the actual movement of the player on a vehicle.

Fixes:
#8214
#7021

In order to best clean up the event logic, the solution is to center the event around the vehicle rather than the player.


Key Changes

  1. Player Remains Untouched

    • We no longer mutate the player’s position within PlayerMoveEvent when they are riding a vehicle.
    • Any forced teleportation of the player got reverted next tick.
    • Past exploits related to this have already been addressed, so there is no need to forcibly move the player now.
  2. Vehicle Based Event

    • Both getFrom() and getTo() now return the vehicle’s position, making the event specifically about the vehicle’s motion.
    • When you call event.setTo(), it teleports the vehicle, rather than trying to teleport the player. This allows movement to be pretty fluid.
  3. Improved Cancellation Logic

    • Cancelling the event now prevents the vehicle from moving at all (similar to Vanilla’s behavior).
    • The server resets the vehicle’s position to the old coordinates, effectively locking the vehicle when the move is disallowed.
    • The player, still riding, will remain in sync with the vehicle's new position, rather than being forcibly teleported around on the server.
  4. Player Desync

    • Note, that there is actually a player desync that happens when keeping the vehicle stationary. The client will try to move off the riding entity depending on the #getRiddenSpeed() of the vehicle.
    • So, when cancelling the move event, you may still notice small client side movement occurring.

Summary of the New Behavior

  • Cancelling the event when riding an entity now locks the vehicle vs locking the player server side but allowing the pig to move.
  • Setting the setTo now teleports the vehicle, rather than teleporting the player off.

Feedback Point:

Maybe make a new event entirely? As there is no PlayerMoveEvent called when a vehicle moves a player that isnt controlled by a player. It seems weird for us to continue supporting this event call.

8mb.video-Ear-qyB5Bf5T.mp4

@Owen1212055 Owen1212055 requested a review from a team as a code owner December 27, 2024 05:22
@NonSwag
Copy link
Contributor

NonSwag commented Dec 27, 2024

This Potentially resolves #11633

@NonSwag
Copy link
Contributor

NonSwag commented Dec 27, 2024

I would suggest improving the vehicle move event and/or adding a "mount steer event" and completely stop calling the player move event for passengers

@Leguan16
Copy link
Contributor

A VehicleMovePlayerEvent would be nice. (See #7791)

@NonSwag
Copy link
Contributor

NonSwag commented Dec 27, 2024

I think a PlayerSteerMountEvent would cover more cases
the event could be called for any entity the player is riding steerable or not
it could provide the exact inputs (jump left right forward backward and maybe dismount?)
and also provide the from and to location and even the applied vector
this wouldn't restrict the even to only movements but every steering input
in case the ridden entity is not steerable by the player the even could just be cancelled by default and/or not provide from and to

One case I didn't think about in advance that came to mind while writing this are pigs and striders
they are controlled by the players held item and therefore this event would not represent the movement properly

@electronicboy
Copy link
Member

The problem with vehicle movement is that there are a lot of overarching concepts which look similar but are entirely different, there were discussions over input events in the past, and there was no viable workable solution that I could see for providing events which are actually useful to devs within the context of the discussions they had (i.e. overriding the entities move controller)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Awaiting review
Development

Successfully merging this pull request may close these issues.

4 participants