File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed
Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change 3131
3232abstract class Spawnable extends Tile{
3333
34- public function spawnTo (Player $ player ){
35- if ($ this ->closed ){
36- return false ;
37- }
38-
34+ public function createSpawnPacket () : BlockEntityDataPacket {
3935 $ nbt = new NBT (NBT ::LITTLE_ENDIAN );
4036 $ nbt ->setData ($ this ->getSpawnCompound ());
4137 $ pk = new BlockEntityDataPacket ();
4238 $ pk ->x = $ this ->x ;
4339 $ pk ->y = $ this ->y ;
4440 $ pk ->z = $ this ->z ;
4541 $ pk ->namedtag = $ nbt ->write (true );
46- $ player ->dataPacket ($ pk );
42+
43+ return $ pk ;
44+ }
45+
46+ public function spawnTo (Player $ player ){
47+ if ($ this ->closed ){
48+ return false ;
49+ }
50+
51+ $ player ->dataPacket ($ this ->createSpawnPacket ());
4752
4853 return true ;
4954 }
@@ -58,11 +63,8 @@ public function spawnToAll(){
5863 return ;
5964 }
6065
61- foreach ($ this ->getLevel ()->getChunkPlayers ($ this ->chunk ->getX (), $ this ->chunk ->getZ ()) as $ player ){
62- if ($ player ->spawned === true ){
63- $ this ->spawnTo ($ player );
64- }
65- }
66+ $ pk = $ this ->createSpawnPacket ();
67+ $ this ->level ->addChunkPacket ($ this ->chunk ->getX (), $ this ->chunk ->getZ (), $ pk );
6668 }
6769
6870 protected function onChanged (){
You can’t perform that action at this time.
0 commit comments