Implement difficulty per-world (#878)

* Moved Server::getDifficultyFromString() to Level
* Added ability to set difficulty in worlds section of pocketmine.yml for generation
This commit is contained in:
Dylan K. Taylor
2017-09-26 11:16:51 +01:00
committed by GitHub
parent e64076ec81
commit 38fad4b963
9 changed files with 132 additions and 50 deletions

View File

@ -168,7 +168,7 @@ class LevelDB extends BaseLevelProvider{
$levelData = new CompoundTag("", [
//Vanilla fields
new IntTag("DayCycleStopTime", -1),
new IntTag("Difficulty", 2),
new IntTag("Difficulty", Level::getDifficultyFromString((string) ($options["difficulty"] ?? "normal"))),
new ByteTag("ForceGameType", 0),
new IntTag("GameType", 0),
new IntTag("Generator", $generatorType),
@ -197,7 +197,7 @@ class LevelDB extends BaseLevelProvider{
//Additional PocketMine-MP fields
new CompoundTag("GameRules", []),
new ByteTag("hardcore", 0),
new ByteTag("hardcore", ($options["hardcore"] ?? false) === true ? 1 : 0),
new StringTag("generatorName", Generator::getGeneratorName($generator)),
new StringTag("generatorOptions", $options["preset"] ?? "")
]);
@ -253,6 +253,14 @@ class LevelDB extends BaseLevelProvider{
return ["preset" => $this->levelData["generatorOptions"]];
}
public function getDifficulty() : int{
return isset($this->levelData->Difficulty) ? $this->levelData->Difficulty->getValue() : Level::DIFFICULTY_NORMAL;
}
public function setDifficulty(int $difficulty){
$this->levelData->Difficulty = new IntTag("Difficulty", $difficulty);
}
public function getLoadedChunks() : array{
return $this->chunks;
}