PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
GenerationInstanceManager.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\level\generator;
23 
28 
30 
32  protected $server;
34  protected $generationManager;
35 
39  public function __construct(Server $server){
40  $this->server = $server;
41  $this->generationManager = new GenerationLevelManager($this->server, $this);
42  }
43 
44  public function process(){
45  $this->generationManager->process();
46  }
47 
48  public function shutdown(){
49  $this->generationManager->shutdown();
50  }
51 
57  public function openLevel(Level $level, $generator, array $options = []){
58  $this->generationManager->openLevel($level->getId(), $level->getSeed(), $generator, $options);
59  }
60 
64  public function closeLevel(Level $level){
65  $this->generationManager->closeLevel($level->getId());
66  }
67 
68  public function addNamespace($namespace, $path){
69 
70  }
71 
72  public function requestChunk(Level $level, $chunkX, $chunkZ){
73  $this->generationManager->enqueueChunk($level->getId(), $chunkX, $chunkZ);
74  }
75 
76  public function getChunk($levelID, $chunkX, $chunkZ){
77  if(($level = $this->server->getLevel($levelID)) instanceof Level){
78  $chunk = $level->getChunk($chunkX, $chunkZ, true);
79  if($chunk instanceof FullChunk){
80  return $chunk;
81  }else{
82  throw new ChunkException("Invalid Chunk given");
83  }
84  }else{
85  $this->generationManager->closeLevel($levelID);
86  return null;
87  }
88  }
89 
90  public function receiveChunk($levelID, FullChunk $chunk){
91  if(($level = $this->server->getLevel($levelID)) instanceof Level){
92  $level->generateChunkCallback($chunk->getX(), $chunk->getZ(), $chunk);
93  }else{
94  $this->generationManager->closeLevel($levelID);
95  }
96  }
97 
98 
99 }
getChunk($x, $z, $create=false)
Definition: Level.php:1732
openLevel(Level $level, $generator, array $options=[])