Fixed player spawning in ungenerated terrain (#4087)

fixes #4044
fixes #2724

this is significantly more complex than I hoped for, but it's a start... and it works.
This commit is contained in:
Dylan T
2021-03-26 21:36:27 +00:00
committed by GitHub
parent 64886707b2
commit f047ecfd2d
7 changed files with 355 additions and 75 deletions

View File

@ -234,8 +234,18 @@ class NetworkSession{
}
protected function createPlayer() : void{
$this->player = $this->server->createPlayer($this, $this->info, $this->authenticated, $this->cachedOfflinePlayerData);
$this->server->createPlayer($this, $this->info, $this->authenticated, $this->cachedOfflinePlayerData)->onCompletion(
\Closure::fromCallable([$this, 'onPlayerCreated']),
fn() => $this->disconnect("Player creation failed") //TODO: this should never actually occur... right?
);
}
private function onPlayerCreated(Player $player) : void{
if(!$this->isConnected()){
//the remote player might have disconnected before spawn terrain generation was finished
return;
}
$this->player = $player;
$this->invManager = new InventoryManager($this->player, $this);
$effectManager = $this->player->getEffects();
@ -259,6 +269,7 @@ class NetworkSession{
$this->disposeHooks->add(static function() use ($permissionHooks, $permHook) : void{
$permissionHooks->remove($permHook);
});
$this->beginSpawnSequence();
}
public function getPlayer() : ?Player{
@ -680,13 +691,11 @@ class NetworkSession{
$this->logger->debug("Initiating resource packs phase");
$this->setHandler(new ResourcePacksPacketHandler($this, $this->server->getResourcePackManager(), function() : void{
$this->beginSpawnSequence();
$this->createPlayer();
}));
}
private function beginSpawnSequence() : void{
$this->createPlayer();
$this->setHandler(new PreSpawnPacketHandler($this->server, $this->player, $this));
$this->player->setImmobile(); //TODO: HACK: fix client-side falling pre-spawn