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 all commits
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
30 changes: 19 additions & 11 deletions paper-api/src/main/java/org/bukkit/entity/LivingEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1115,10 +1115,13 @@ default void setArrowsInBody(final int count) {
* Retrieves the sideways movement direction of the entity.
* <p>
* The returned value ranges from -1 to 1, where:
* - 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.
* <ul>
* <li>Positive 1 represents movement to the left.</li>
* <li>Negative 1 represents movement to the right.</li>
* </ul>
*
* 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 All @@ -1131,9 +1134,11 @@ default void setArrowsInBody(final int count) {
* Retrieves the upwards movement direction of the entity.
* <p>
* The returned value ranges from -1 to 1, where:
* - Positive 1 represents upward movement.
* - Negative 1 represents downward movement.
* <p>
* <ul>
* <li>Positive 1 represents upward movement.</li>
* <li>Negative 1 represents downward movement.</li>
* </ul>
*
* Please note that for entities of type {@link Player}, this value is never updated.
* <p>
* This method specifically provides information about the entity's vertical movement,
Expand All @@ -1148,10 +1153,13 @@ default void setArrowsInBody(final int count) {
* Retrieves the forwards movement direction of the entity.
* <p>
* The returned value ranges from -1 to 1, where:
* - 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.
* <ul>
* <li>Positive 1 represents movement forwards.</li>
* <li>Negative 1 represents movement backwards.</li>
* </ul>
*
* 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,20 @@ 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();

return leftMovement == rightMovement ? 0 : leftMovement ? 1 : -1;
}

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

return forwardMovement == backwardMovement ? 0 : forwardMovement ? 1 : -1;
}
}
Loading