1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-04-05 14:01:02 +02:00

Fix getForwards/SidewaysMovement for players ()

This commit is contained in:
Warrior 2025-02-18 01:03:48 +01:00 committed by GitHub
parent f070081825
commit 09f1f88f58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 11 deletions
paper-api/src/main/java/org/bukkit/entity
paper-server/src/main/java/org/bukkit/craftbukkit/entity

View file

@ -1115,10 +1115,13 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
* 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.
@ -1131,9 +1134,11 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
* 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,
@ -1148,10 +1153,13 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
* 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.

View file

@ -3583,4 +3583,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
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;
}
}