I have this little issue, I'd like to have players always respawn at a set location in the default world. The code below works somewhat but seems to always round the coordinates and the player spawn at 202 69 23 - rather than use the 201.5, 69, 22.5 coordinates that were set. PHP: public function onRespawn(PlayerRespawnEvent $event) { $level = $this->getServer()->getDefaultLevel(); $pos = new Location(201.5, 69, 22.5, 180, 0, $level); $event->setRespawnPosition($pos);} The code I used in the PlayerJoinEvent works as expected and teleports the player in the center of a single block. PHP: public function onJoin(PlayerJoinEvent $event) { $player = $event->getPlayer(); $level = $this->getServer()->getDefaultLevel(); $player->teleport(new Location(201.5, 69, 22.5, 180, 0, $level)); } I know it's a minor thing, but I'm new to coding and trying to understand why it doesn't work and want to learn how to solve it. Thanks in advance.
This happens for a very, very funny reason (I literally grinned when I saw it): https://github.com/pmmp/PocketMine-...53562bb41ece1/src/pocketmine/Player.php#L3686 Here's an excerpt of that file: PHP: protected function respawn() : void{if($this->server->isHardcore()){$this->setBanned(true);return;}$ev = new PlayerRespawnEvent($this, $this->getSpawn());$ev->call();$realSpawn = Position::fromObject($ev->getRespawnPosition()->add(0.5, 0, 0.5), $ev->getRespawnPosition()->getLevel()); // take a look at this line$this->teleport($realSpawn);$this->setSprinting(false);$this->setSneaking(false); PocketMine adds 0.5 to the coordinate lol (btw you don't need to bother with yaw and pitch as setRespawnPosition only uses a Position object which only has x, y, z and level)
Wow, lol so simple. I was looking in the wrong place but makes perfect sense now. Thank you for taking the time to explain. I appreciate it.