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

Fix getForwards/SidewaysMovement for players #12140

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions paper-api/src/main/java/org/bukkit/entity/LivingEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,8 @@ default void setArrowsInBody(final int count) {
* - Positive 1 represents movement to the left.
* - Negative 1 represents movement to the right.
* <p>
* Please note that for entities of type {@link Player}, this value is updated only when riding another entity.
* Please note that for entities of type {@link Player}, this value will only return whole numbers depending
* on what keys are held, see {@link Player#getCurrentInput()}.
* <p>
* This method specifically provides information about the entity's sideways movement, whereas {@link #getVelocity()} returns
* a vector representing the entity's overall current momentum.
Expand Down Expand Up @@ -1151,7 +1152,8 @@ default void setArrowsInBody(final int count) {
* - Positive 1 represents movement forwards.
* - Negative 1 represents movement backwards.
* <p>
* Please note that for entities of type {@link Player}, this value is updated only when riding another entity.
* Please note that for entities of type {@link Player}, this value will only return whole numbers depending
* on what keys are held, see {@link Player#getCurrentInput()}.
* <p>
* This method specifically provides information about the entity's forward and backward movement,
* whereas {@link #getVelocity()} returns a vector representing the entity's overall current momentum.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3583,4 +3583,26 @@ public void sendEntityEffect(final EntityEffect effect, final org.bukkit.entity.
handle.containerMenu.broadcastChanges();
return new PaperPlayerGiveResult(leftovers.build(), drops.build());
}

@Override
public float getSidewaysMovement() {
final boolean leftMovement = this.getHandle().getLastClientInput().left();
final boolean rightMovement = this.getHandle().getLastClientInput().right();

if (leftMovement == rightMovement)
return 0;

return leftMovement ? 1 : -1;
}

@Override
public float getForwardsMovement() {
final boolean forwardMovement = this.getHandle().getLastClientInput().forward();
final boolean backwardMovement = this.getHandle().getLastClientInput().backward();

if (forwardMovement == backwardMovement)
return 0;

return forwardMovement ? 1 : -1;
}
}
Loading