mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 07:39:57 +00:00
Improved tile spawning
There's no need to recreate the spawn packet for every single player, or re-serialize the NBT.
This commit is contained in:
parent
f4f2323518
commit
0b2b9126a2
@ -31,11 +31,7 @@ use pocketmine\Player;
|
|||||||
|
|
||||||
abstract class Spawnable extends Tile{
|
abstract class Spawnable extends Tile{
|
||||||
|
|
||||||
public function spawnTo(Player $player){
|
public function createSpawnPacket() : BlockEntityDataPacket{
|
||||||
if($this->closed){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
||||||
$nbt->setData($this->getSpawnCompound());
|
$nbt->setData($this->getSpawnCompound());
|
||||||
$pk = new BlockEntityDataPacket();
|
$pk = new BlockEntityDataPacket();
|
||||||
@ -43,7 +39,16 @@ abstract class Spawnable extends Tile{
|
|||||||
$pk->y = $this->y;
|
$pk->y = $this->y;
|
||||||
$pk->z = $this->z;
|
$pk->z = $this->z;
|
||||||
$pk->namedtag = $nbt->write(true);
|
$pk->namedtag = $nbt->write(true);
|
||||||
$player->dataPacket($pk);
|
|
||||||
|
return $pk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function spawnTo(Player $player){
|
||||||
|
if($this->closed){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$player->dataPacket($this->createSpawnPacket());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -58,11 +63,8 @@ abstract class Spawnable extends Tile{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->getLevel()->getChunkPlayers($this->chunk->getX(), $this->chunk->getZ()) as $player){
|
$pk = $this->createSpawnPacket();
|
||||||
if($player->spawned === true){
|
$this->level->addChunkPacket($this->chunk->getX(), $this->chunk->getZ(), $pk);
|
||||||
$this->spawnTo($player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function onChanged(){
|
protected function onChanged(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user