GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
BaseLevelProvider Class Reference

Public Member Functions

 __construct (Level $level, string $path)
 
 getPath ()
 
 getServer ()
 
 getLevel ()
 
 getName ()
 
 getTime ()
 
 setTime ($value)
 
 getSeed ()
 
 setSeed ($value)
 
 getSpawn ()
 
 setSpawn (Vector3 $pos)
 
 doGarbageCollection ()
 
 getLevelData ()
 
 saveLevelData ()
 
 requestChunkTask (int $x, int $z)
 
- Public Member Functions inherited from LevelProvider
 getWorldHeight ()
 
 getGenerator ()
 
 getGeneratorOptions ()
 
 getChunk (int $chunkX, int $chunkZ, bool $create=false)
 
 setChunk (int $chunkX, int $chunkZ, Chunk $chunk)
 
 saveChunk (int $chunkX, int $chunkZ)
 
 saveChunks ()
 
 loadChunk (int $chunkX, int $chunkZ, bool $create=false)
 
 unloadChunk (int $chunkX, int $chunkZ, bool $safe=true)
 
 unloadChunks ()
 
 isChunkLoaded (int $chunkX, int $chunkZ)
 
 isChunkGenerated (int $chunkX, int $chunkZ)
 
 isChunkPopulated (int $chunkX, int $chunkZ)
 
 getLoadedChunks ()
 
 close ()
 

Protected Attributes

 $level
 
 $path
 
 $levelData
 
 $asyncChunkRequest = false
 

Additional Inherited Members

- Static Public Member Functions inherited from LevelProvider
static getProviderName ()
 
static isValid (string $path)
 
static generate (string $path, string $name, $seed, string $generator, array $options=[])
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Level  $level,
string  $path 
)

BaseLevelProvider constructor.

Parameters
Level$level
string$path

Implements LevelProvider.

53  {
54  $this->level = $level;
55  $this->path = $path;
56  if(!file_exists($this->path)){
57  mkdir($this->path, 0777, true);
58  }
59  $nbt = new NBT(NBT::BIG_ENDIAN);
60  $nbt->readCompressed(file_get_contents($this->getPath() . "level.dat"));
61  $levelData = $nbt->getData();
62  if($levelData->Data instanceof CompoundTag){
63  $this->levelData = $levelData->Data;
64  }else{
65  throw new LevelException("Invalid level.dat");
66  }
67 
68  if(!isset($this->levelData->generatorName)){
69  $this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT"));
70  }
71 
72  if(!isset($this->levelData->generatorOptions)){
73  $this->levelData->generatorOptions = new StringTag("generatorOptions", "");
74  }
75  $this->asyncChunkRequest = (bool) $this->level->getServer()->getProperty("chunk-sending.async-chunk-request", false);
76  }

Member Function Documentation

◆ doGarbageCollection()

doGarbageCollection ( )

Implements LevelProvider.

150  {
151 
152  }

◆ getLevel()

getLevel ( )
Returns
Level

Implements LevelProvider.

95  {
96  return $this->level;
97  }

◆ getLevelData()

getLevelData ( )
Returns
CompoundTag
157  : CompoundTag{
158  return $this->levelData;
159  }

◆ getName()

getName ( )
Returns
string

Implements LevelProvider.

102  : string{
103  return (string) $this->levelData["LevelName"];
104  }

◆ getPath()

getPath ( )
Returns
string

Implements LevelProvider.

81  : string{
82  return $this->path;
83  }

◆ getSeed()

getSeed ( )
Returns
mixed|null

Implements LevelProvider.

123  {
124  return $this->levelData["RandomSeed"];
125  }

◆ getServer()

getServer ( )
Returns
88  {
89  return $this->level->getServer();
90  }

◆ getSpawn()

getSpawn ( )
Returns
Vector3

Implements LevelProvider.

137  : Vector3{
138  return new Vector3((float) $this->levelData["SpawnX"], (float) $this->levelData["SpawnY"], (float) $this->levelData["SpawnZ"]);
139  }

◆ getTime()

getTime ( )
Returns
mixed|null

Implements LevelProvider.

109  {
110  return $this->levelData["Time"];
111  }

◆ requestChunkTask()

requestChunkTask ( int  $x,
int  $z 
)
Parameters
int$x
int$z
Returns
null|ChunkRequestTask

Implements LevelProvider.

176  {
177  $chunk = $this->getChunk($x, $z, false);
178  if(!($chunk instanceof Chunk)){
179  throw new ChunkException("Invalid Chunk sent");
180  }
181 
182  if($this->asyncChunkRequest){
183  return new ChunkRequestTask($this->level, $chunk);
184  }
185 
186  //non-async, call the callback directly with serialized data
187  $this->getLevel()->chunkRequestCallback($x, $z, $chunk->networkSerialize());
188 
189  return null;
190  }

◆ saveLevelData()

saveLevelData ( )
161  {
162  $nbt = new NBT(NBT::BIG_ENDIAN);
163  $nbt->setData(new CompoundTag("", [
164  "Data" => $this->levelData
165  ]));
166  $buffer = $nbt->writeCompressed();
167  file_put_contents($this->getPath() . "level.dat", $buffer);
168  }

◆ setSeed()

setSeed (   $value)
Parameters
int | string$value

Implements LevelProvider.

130  {
131  $this->levelData->RandomSeed = new LongTag("RandomSeed", (int) $value);
132  }

◆ setSpawn()

setSpawn ( Vector3  $pos)
Parameters
Vector3$pos

Implements LevelProvider.

144  {
145  $this->levelData->SpawnX = new IntTag("SpawnX", (int) $pos->x);
146  $this->levelData->SpawnY = new IntTag("SpawnY", (int) $pos->y);
147  $this->levelData->SpawnZ = new IntTag("SpawnZ", (int) $pos->z);
148  }

◆ setTime()

setTime (   $value)
Parameters
int | string$value

Implements LevelProvider.

116  {
117  $this->levelData->Time = new LongTag("Time", $value);
118  }

Field Documentation

◆ $asyncChunkRequest

$asyncChunkRequest = false
protected

◆ $level

$level
protected

◆ $levelData

$levelData
protected

◆ $path

$path
protected

The documentation for this class was generated from the following file: