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 6 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
9 changes: 0 additions & 9 deletions src/item/ItemBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
namespace pocketmine\item;

use pocketmine\block\Block;
use pocketmine\block\BlockTypeIds;
use pocketmine\data\runtime\RuntimeDataDescriber;

/**
Expand Down Expand Up @@ -59,12 +58,4 @@ public function isFireProof() : bool{
public function getMaxStackSize() : int{
return $this->block->getMaxStackSize();
}

public function isNull() : bool{
//TODO: we really shouldn't need to treat air as a special case here
//this is needed because the "null" empty slot item is represented by an air block, but there's no real reason
//why air should be needed at all. A separate special item type (or actual null) should be used instead, but
//this would cause a lot of BC breaks, so we can't do it yet.
return parent::isNull() || $this->block->getTypeId() === BlockTypeIds::AIR;
}
}
3 changes: 1 addition & 2 deletions src/network/mcpe/NetworkSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,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
15 changes: 15 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 @@ -515,6 +519,17 @@ public function hasAutoJump() : bool{
return $this->autoJump;
}

public function setFlightSpeed(float $flightSpeed) : void{
if($this->flightSpeed !== $flightSpeed && $flightSpeed >= 0){
Sergittos marked this conversation as resolved.
Show resolved Hide resolved
$this->flightSpeed = $flightSpeed;
$this->getNetworkSession()->syncAbilities($this);
}
}

public function getFlightSpeed() : float{
return $this->flightSpeed;
}

public function spawnTo(Player $player) : void{
if($this->isAlive() && $player->isAlive() && $player->canSee($this) && !$this->isSpectator()){
parent::spawnTo($player);
Expand Down