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

Add flight speed #6076

Open
wants to merge 17 commits into
base: minor-next
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions src/network/mcpe/NetworkSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,7 @@ public function syncAbilities(Player $for) : void{
];

$layers = [
//TODO: dynamic flying speed! FINALLY!!!!!!!!!!!!!!!!!
new AbilitiesLayer(AbilitiesLayer::LAYER_BASE, $boolAbilities, 0.05, 0.1),
new AbilitiesLayer(AbilitiesLayer::LAYER_BASE, $boolAbilities, $for->getFlightSpeed(), 0.1),
];
if(!$for->hasBlockCollision()){
//TODO: HACK! In 1.19.80, the client starts falling in our faux spectator mode when it clips into a
Expand Down
37 changes: 37 additions & 0 deletions src/player/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
private const MAX_REACH_DISTANCE_SURVIVAL = 7;
private const MAX_REACH_DISTANCE_ENTITY_INTERACTION = 8;

public const DEFAULT_FLIGHT_SPEED = 0.05;

public const TAG_FIRST_PLAYED = "firstPlayed"; //TAG_Long
public const TAG_LAST_PLAYED = "lastPlayed"; //TAG_Long
private const TAG_GAME_MODE = "playerGameType"; //TAG_Int
Expand Down Expand Up @@ -278,6 +280,8 @@ public static function isValidUserName(?string $name) : bool{
protected bool $blockCollision = true;
protected bool $flying = false;

protected float $flightSpeed = self::DEFAULT_FLIGHT_SPEED;

/** @phpstan-var positive-int|null */
protected ?int $lineHeight = null;
protected string $locale = "en_US";
Expand Down Expand Up @@ -504,6 +508,39 @@ public function isFlying() : bool{
return $this->flying;
}

/**
* Sets the player's speed when flying.
*
* The flight speed is calculated as `blocks per tick = flightSpeed * 10`. For example, setting the
* flight speed to 0.05 means the player will fly at approximately 0.5 blocks per tick.
*
* If set to zero, the player will not be able to move in the xz plane when flying, and negative values
* will invert the controls.
*
* Notes:
IvanCraft623 marked this conversation as resolved.
Show resolved Hide resolved
* - The value of the movement speed attribute has no effect on the flight speed.
* - When a player sprints while flying, their flight speed is doubled on the client-side.
*/
public function setFlightSpeed(float $flightSpeed) : void{
if($this->flightSpeed !== $flightSpeed){
$this->flightSpeed = $flightSpeed;
$this->getNetworkSession()->syncAbilities($this);
}
}

/**
* Returns the player's speed when flying.
*
* The flight speed is calculated as `blocks per tick = flightSpeed * 10`. For example, if the
* flight speed is set to 0.05, the player will fly at approximately 0.5 blocks per tick.
*
* If zero, the player is not be able to move in the xz plane when flying, and negative values
* will invert the controls.
*/
public function getFlightSpeed() : float{
return $this->flightSpeed;
}

public function setAutoJump(bool $value) : void{
if($this->autoJump !== $value){
$this->autoJump = $value;
Expand Down