diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index 33a9303a30d..ade2bf192b4 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -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 diff --git a/src/player/Player.php b/src/player/Player.php index d442c6a3b20..0c6c2bf6c3c 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -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 @@ -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"; @@ -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: + * - 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;