Player: allow controlling client-sided block collisions irrespective of Spectator Mode (#4563)

- Added the following API methods:
  - `Player::hasBlockCollision()`
  - `Player::setHasBlockCollision()`

This enables spectator-like noclip behaviour in other gamemodes (could be useful for builders).
This commit is contained in:
Drew B 2021-12-06 16:14:22 -05:00 committed by GitHub
parent cd850b111d
commit ce54d268f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -797,7 +797,7 @@ class NetworkSession{
$pk->setFlag(AdventureSettingsPacket::NO_PVP, $for->isSpectator());
$pk->setFlag(AdventureSettingsPacket::AUTO_JUMP, $for->hasAutoJump());
$pk->setFlag(AdventureSettingsPacket::ALLOW_FLIGHT, $for->getAllowFlight());
$pk->setFlag(AdventureSettingsPacket::NO_CLIP, $for->isSpectator());
$pk->setFlag(AdventureSettingsPacket::NO_CLIP, !$for->hasBlockCollision());
$pk->setFlag(AdventureSettingsPacket::FLYING, $for->isFlying());
//TODO: permission flags

View File

@ -234,6 +234,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
//TODO: Abilities
protected bool $autoJump = true;
protected bool $allowFlight = false;
protected bool $blockCollision = true;
protected bool $flying = false;
protected ?int $lineHeight = null;
@ -394,6 +395,15 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
return $this->allowFlight;
}
public function setHasBlockCollision(bool $value) : void{
$this->blockCollision = $value;
$this->getNetworkSession()->syncAdventureSettings($this);
}
public function hasBlockCollision() : bool{
return $this->blockCollision;
}
public function setFlying(bool $value) : void{
if($this->flying !== $value){
$this->flying = $value;
@ -970,6 +980,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
if($this->isSpectator()){
$this->setFlying(true);
$this->setHasBlockCollision(false);
$this->setSilent();
$this->onGround = false;
@ -980,6 +991,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
if($this->isSurvival()){
$this->setFlying(false);
}
$this->setHasBlockCollision(true);
$this->setSilent(false);
$this->checkGroundState(0, 0, 0, 0, 0, 0);
}