should have fixed spawn

This commit is contained in:
GameHerobrine 2023-07-08 22:06:58 +03:00
parent 28c0541164
commit 5b2c7bc9d0
3 changed files with 28 additions and 17 deletions

View file

@ -156,7 +156,7 @@ class Player{
$this->entity->check = true;
return false;
}
if($pos instanceof Position and $pos->level instanceof Level and $pos->level !== $this->level){
if($this->server->api->dhandle("player.teleport.level", ["player" => $this, "origin" => $this->level, "target" => $pos->level]) === false){
$this->entity->check = true;
@ -178,7 +178,6 @@ class Player{
}
}
}
$this->level->freeAllChunks($this);
$this->level = $pos->level;
$this->chunksLoaded = [];
@ -217,10 +216,6 @@ class Player{
$this->lastCorrect = $pos;
$this->entity->fallY = false;
$this->entity->fallStart = false;
$this->entity->setPosition($pos, $yaw, $pitch);
$this->entity->resetSpeed();
$this->entity->updateLast();
$this->entity->calculateVelocity();
//if($terrain === true){
//$this->getNextChunk($this->level);
@ -230,6 +225,13 @@ class Player{
$this->forceMovement = $pos;
}
}
if($this->spawned){
$this->entity->setPosition($pos, $yaw, $pitch);
$this->entity->resetSpeed();
$this->entity->updateLast();
$this->entity->calculateVelocity();
}
$this->orderChunks();
$this->getNextChunk($this->level);
$pk = new MovePlayerPacket;
@ -240,6 +242,7 @@ class Player{
$pk->bodyYaw = $yaw;
$pk->pitch = $pitch;
$pk->yaw = $yaw;
$pk->teleport = true;
$this->dataPacket($pk);
}
@ -1427,15 +1430,6 @@ class Player{
$this->entity->x = $this->data->get("position")["x"];
$this->entity->y = $this->data->get("position")["y"];
$this->entity->z = $this->data->get("position")["z"];
if(($level = $this->server->api->level->get($this->data->get("spawn")["level"])) !== false){
$this->spawnPosition = new Position($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"], $level);
$pk = new SetSpawnPositionPacket;
$pk->x = (int) $this->spawnPosition->x;
$pk->y = (int) $this->spawnPosition->y;
$pk->z = (int) $this->spawnPosition->z;
$this->dataPacket($pk);
}
$pk = new StartGamePacket;
$pk->seed = $this->level->getSeed();
$pk->spawnX = (int) $spawnPos->x;
@ -1448,6 +1442,17 @@ class Player{
$pk->gamemode = $this->gamemode & 0x01;
$pk->eid = 0;
$this->dataPacket($pk);
if(($level = $this->server->api->level->get($this->data->get("spawn")["level"])) !== false){
$this->spawnPosition = new Position($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"], $level);
$pk = new SetSpawnPositionPacket;
$pk->x = (int) $this->spawnPosition->x;
$pk->y = (int) $this->spawnPosition->y;
$pk->z = (int) $this->spawnPosition->z;
$this->dataPacket($pk);
}
//$this->entity->check = false; whaT?
$this->entity->setName($this->username);
$this->entity->data["CID"] = $this->CID;
@ -1552,6 +1557,9 @@ class Player{
$this->entity->updateAABB();
}
break;
case 0xa7:
//TODO 0xa7
break;
case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:
if($this->spawned === false){
break;

View file

@ -8,7 +8,7 @@ class MovePlayerPacket extends RakNetDataPacket{
public $yaw;
public $pitch;
public $bodyYaw;
public $teleport;
public function pid(){
return ProtocolInfo::MOVE_PLAYER_PACKET;
}
@ -19,8 +19,9 @@ class MovePlayerPacket extends RakNetDataPacket{
$this->y = $this->getFloat();
$this->z = $this->getFloat();
$this->yaw = $this->getFloat();
$this->pitch = $this->getFloat();
$this->bodyYaw = $this->getFloat();
$this->pitch = $this->getFloat();
$this->teleport = ($this->getByte() & 0x80) > 0;
}
public function encode(){
@ -32,6 +33,7 @@ class MovePlayerPacket extends RakNetDataPacket{
$this->putFloat($this->yaw);
$this->putFloat($this->pitch);
$this->putFloat($this->bodyYaw);
$this->putByte($this->teleport ? 0x80 : 0x00);
}
}

View file

@ -38,6 +38,7 @@ class MobSpawner{
}else{
return false;
}
if(empty($this->level->usedChunks)) return false;
$chunk = explode(".", array_rand($this->level->usedChunks, 1));
$x = $chunk[0] * 16;
$z = $chunk[1] * 16;