|
| __construct (Level $level, string $path) |
|
| getWorldHeight () |
|
| saveLevelData () |
|
| unloadChunks () |
|
| getGenerator () |
|
| getGeneratorOptions () |
|
| getLoadedChunks () |
|
| isChunkLoaded (int $x, int $z) |
|
| saveChunks () |
|
| loadChunk (int $chunkX, int $chunkZ, bool $create=false) |
|
| unloadChunk (int $x, int $z, bool $safe=true) |
|
| saveChunk (int $chunkX, int $chunkZ) |
|
| getChunk (int $chunkX, int $chunkZ, bool $create=false) |
|
| getDatabase () |
|
| setChunk (int $chunkX, int $chunkZ, Chunk $chunk) |
|
| isChunkGenerated (int $chunkX, int $chunkZ) |
|
| isChunkPopulated (int $chunkX, int $chunkZ) |
|
| close () |
|
| __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) |
|
◆ __construct()
__construct |
( |
Level |
$level, |
|
|
string |
$path |
|
) |
| |
LevelDB constructor.
- Parameters
-
Implements LevelProvider.
78 if(!file_exists($this->path)){
79 mkdir($this->path, 0777,
true);
82 $nbt->read(substr(file_get_contents($this->
getPath() .
"level.dat"), 8));
87 throw new LevelException(
"Invalid level.dat");
90 $this->db = new \LevelDB($this->path .
"/db", [
91 "compression" => LEVELDB_ZLIB_COMPRESSION
94 if(isset($this->levelData->StorageVersion) and $this->levelData->StorageVersion->getValue() > self::CURRENT_STORAGE_VERSION){
95 throw new LevelException(
"Specified LevelDB world format version is newer than the version supported by the server");
98 if(!isset($this->levelData->generatorName)){
99 if(isset($this->levelData->Generator)){
100 switch((
int) $this->levelData->Generator->getValue()){
101 case self::GENERATOR_FLAT:
103 if(($layers = $this->db->get(self::ENTRY_FLAT_WORLD_LAYERS)) !==
false){
104 $layers = trim($layers,
"[]");
108 $this->levelData->generatorOptions =
new StringTag(
"generatorOptions",
"2;" . $layers .
";1");
110 case self::GENERATOR_INFINITE:
113 $this->levelData->generatorOptions =
new StringTag(
"generatorOptions",
"");
115 case self::GENERATOR_LIMITED:
116 throw new LevelException(
"Limited worlds are not currently supported");
118 throw new LevelException(
"Unknown LevelDB world format type, this level cannot be loaded");
125 if(!isset($this->levelData->generatorOptions)){
126 $this->levelData->generatorOptions =
new StringTag(
"generatorOptions",
"");
◆ chunkIndex()
static chunkIndex |
( |
int |
$chunkX, |
|
|
int |
$chunkZ |
|
) |
| |
|
static |
◆ close()
◆ generate()
static generate |
( |
string |
$path, |
|
|
string |
$name, |
|
|
|
$seed, |
|
|
string |
$generator, |
|
|
array |
$options = [] |
|
) |
| |
|
static |
- Parameters
-
string | $path | |
string | $name | |
int | string | $seed | |
string | $generator | |
array | $options | |
Implements LevelProvider.
161 if(!file_exists(
$path)){
162 mkdir(
$path, 0777,
true);
165 if(!file_exists(
$path .
"/db")){
166 mkdir(
$path .
"/db", 0777,
true);
171 $generatorType = self::GENERATOR_FLAT;
174 $generatorType = self::GENERATOR_INFINITE;
180 "DayCycleStopTime" =>
new IntTag(
"DayCycleStopTime", -1),
181 "Difficulty" =>
new IntTag(
"Difficulty", 2),
182 "ForceGameType" =>
new ByteTag(
"ForceGameType", 0),
183 "GameType" =>
new IntTag(
"GameType", 0),
184 "Generator" =>
new IntTag(
"Generator", $generatorType),
185 "LastPlayed" =>
new LongTag(
"LastPlayed", time()),
186 "LevelName" =>
new StringTag(
"LevelName", $name),
189 "RandomSeed" =>
new LongTag(
"RandomSeed", $seed),
190 "SpawnX" =>
new IntTag(
"SpawnX", 0),
191 "SpawnY" =>
new IntTag(
"SpawnY", 32767),
192 "SpawnZ" =>
new IntTag(
"SpawnZ", 0),
193 "StorageVersion" =>
new IntTag(
"StorageVersion", self::CURRENT_STORAGE_VERSION),
194 "Time" =>
new LongTag(
"Time", 0),
195 "eduLevel" =>
new ByteTag(
"eduLevel", 0),
196 "falldamage" =>
new ByteTag(
"falldamage", 1),
197 "firedamage" =>
new ByteTag(
"firedamage", 1),
198 "hasBeenLoadedInCreative" =>
new ByteTag(
"hasBeenLoadedInCreative", 1),
199 "immutableWorld" =>
new ByteTag(
"immutableWorld", 0),
200 "lightningLevel" =>
new FloatTag(
"lightningLevel", 0.0),
201 "lightningTime" =>
new IntTag(
"lightningTime", 0),
202 "pvp" =>
new ByteTag(
"pvp", 1),
203 "rainLevel" =>
new FloatTag(
"rainLevel", 0.0),
204 "rainTime" =>
new IntTag(
"rainTime", 0),
205 "spawnMobs" =>
new ByteTag(
"spawnMobs", 1),
206 "texturePacksRequired" =>
new ByteTag(
"texturePacksRequired", 0),
210 "hardcore" =>
new ByteTag(
"hardcore", 0),
212 "generatorOptions" =>
new StringTag(
"generatorOptions", $options[
"preset"] ??
"")
217 $buffer = $nbt->write();
222 "compression" => LEVELDB_ZLIB_COMPRESSION
225 if($generatorType === self::GENERATOR_FLAT and isset($options[
"preset"])){
226 $layers = explode(
";", $options[
"preset"])[1] ??
"";
230 $out .= $result[0] .
",";
232 $out = rtrim($out,
",") .
"]";
233 $db->put(self::ENTRY_FLAT_WORLD_LAYERS, $out);
◆ getChunk()
getChunk |
( |
int |
$chunkX, |
|
|
int |
$chunkZ, |
|
|
bool |
$create = false |
|
) |
| |
- Parameters
-
int | $chunkX | |
int | $chunkZ | |
bool | $create | |
- Returns
- Chunk|null
Implements LevelProvider.
569 if(isset($this->chunks[$index])){
570 return $this->chunks[$index];
572 $this->
loadChunk($chunkX, $chunkZ, $create);
574 return $this->chunks[$index] ?? null;
◆ getDatabase()
◆ getGenerator()
- Returns
- string
Implements LevelProvider.
259 return $this->levelData[
"generatorName"];
◆ getGeneratorOptions()
- Returns
- array
Implements LevelProvider.
266 return [
"preset" => $this->levelData[
"generatorOptions"]];
◆ getLoadedChunks()
◆ getProviderName()
static getProviderName |
( |
| ) |
|
|
static |
◆ getWorldHeight()
◆ isChunkGenerated()
isChunkGenerated |
( |
int |
$chunkX, |
|
|
int |
$chunkZ |
|
) |
| |
- Parameters
-
- Returns
- bool
Implements LevelProvider.
628 if($this->chunkExists($chunkX, $chunkZ) and ($chunk = $this->
getChunk($chunkX, $chunkZ,
false)) !== null){
◆ isChunkLoaded()
isChunkLoaded |
( |
int |
$x, |
|
|
int |
$z |
|
) |
| |
◆ isChunkPopulated()
isChunkPopulated |
( |
int |
$chunkX, |
|
|
int |
$chunkZ |
|
) |
| |
- Parameters
-
- Returns
- bool
Implements LevelProvider.
642 $chunk = $this->
getChunk($chunkX, $chunkZ);
643 if($chunk instanceof Chunk){
644 return $chunk->isPopulated();
◆ isValid()
static isValid |
( |
string |
$path | ) |
|
|
static |
- Parameters
-
- Returns
- bool
Implements LevelProvider.
150 return file_exists(
$path .
"/level.dat") and is_dir(
$path .
"/db/");
◆ loadChunk()
loadChunk |
( |
int |
$chunkX, |
|
|
int |
$chunkZ, |
|
|
bool |
$create = false |
|
) |
| |
- Parameters
-
int | $chunkX | |
int | $chunkZ | |
bool | $create | |
- Returns
- bool
Implements LevelProvider.
304 $this->level->timings->syncChunkLoadDataTimer->startTiming();
305 $chunk = $this->readChunk($chunkX, $chunkZ);
306 if($chunk === null and $create){
309 $this->level->timings->syncChunkLoadDataTimer->stopTiming();
312 $this->chunks[$index] = $chunk;
◆ saveChunk()
saveChunk |
( |
int |
$chunkX, |
|
|
int |
$chunkZ |
|
) |
| |
- Parameters
-
- Returns
- bool
Implements LevelProvider.
548 $chunk = $this->
getChunk($chunkX, $chunkZ);
549 if(!$chunk->isGenerated()){
550 throw new \InvalidStateException(
"Cannot save un-generated chunk");
552 $this->writeChunk($chunk);
◆ saveChunks()
Implements LevelProvider.
287 foreach($this->chunks as $chunk){
288 $this->
saveChunk($chunk->getX(), $chunk->getZ());
◆ saveLevelData()
243 $nbt->setData($this->levelData);
244 $buffer = $nbt->write();
◆ setChunk()
setChunk |
( |
int |
$chunkX, |
|
|
int |
$chunkZ, |
|
|
Chunk |
$chunk |
|
) |
| |
- Parameters
-
int | $chunkX | |
int | $chunkZ | |
Chunk | $chunk | |
Implements LevelProvider.
591 $chunk->setX($chunkX);
592 $chunk->setZ($chunkZ);
594 if(isset($this->chunks[$index =
Level::chunkHash($chunkX, $chunkZ)]) and $this->chunks[$index] !== $chunk){
598 $this->chunks[$index] = $chunk;
◆ unloadChunk()
unloadChunk |
( |
int |
$x, |
|
|
int |
$z, |
|
|
bool |
$safe = true |
|
) |
| |
- Parameters
-
- Returns
- bool
Implements LevelProvider.
531 if($chunk instanceof Chunk and $chunk->unload($safe)){
532 unset($this->chunks[$index]);
◆ unloadChunks()
Implements LevelProvider.
249 foreach($this->chunks as $chunk){
250 $this->
unloadChunk($chunk->getX(), $chunk->getZ(),
false);
◆ $chunks
◆ $db
◆ CURRENT_STORAGE_VERSION
const CURRENT_STORAGE_VERSION = 5 |
◆ ENTRY_FLAT_WORLD_LAYERS
const ENTRY_FLAT_WORLD_LAYERS = "game_flatworldlayers" |
◆ GENERATOR_FLAT
◆ GENERATOR_INFINITE
const GENERATOR_INFINITE = 1 |
◆ GENERATOR_LIMITED
const GENERATOR_LIMITED = 0 |
◆ TAG_BIOME_STATE
const TAG_BIOME_STATE = "5" |
◆ TAG_BLOCK_ENTITY
const TAG_BLOCK_ENTITY = "1" |
◆ TAG_BLOCK_EXTRA_DATA
const TAG_BLOCK_EXTRA_DATA = "4" |
◆ TAG_DATA_2D
const TAG_DATA_2D = "\x2d" |
◆ TAG_DATA_2D_LEGACY
const TAG_DATA_2D_LEGACY = "\x2e" |
◆ TAG_ENTITY
◆ TAG_LEGACY_TERRAIN
const TAG_LEGACY_TERRAIN = "0" |
◆ TAG_PENDING_TICK
const TAG_PENDING_TICK = "3" |
◆ TAG_SUBCHUNK_PREFIX
const TAG_SUBCHUNK_PREFIX = "\x2f" |
◆ TAG_VERSION
The documentation for this class was generated from the following file:
- src/pocketmine/level/format/io/leveldb/LevelDB.php