Cleaned up level seed handling

This commit is contained in:
Dylan K. Taylor
2018-06-07 19:39:24 +01:00
parent 3707a41b67
commit 996935e9b2
2 changed files with 23 additions and 15 deletions

View File

@ -29,11 +29,32 @@ namespace pocketmine\level\generator;
use pocketmine\level\ChunkManager;
use pocketmine\math\Vector3;
use pocketmine\utils\Random;
use pocketmine\utils\Utils;
abstract class Generator{
/**
* Converts a string level seed into an integer for use by the generator.
*
* @param string $seed
*
* @return int|null
*/
public static function convertSeed(string $seed) : ?int{
if($seed === ""){ //empty seed should cause a random seed to be selected - can't use 0 here because 0 is a valid seed
$convertedSeed = null;
}elseif(ctype_digit($seed)){ //this avoids treating seeds like "404.4" as integer seeds
$convertedSeed = (int) $seed;
}else{
$convertedSeed = Utils::javaStringHash($seed);
}
return $convertedSeed;
}
abstract public function __construct(array $settings = []);
abstract public function init(ChunkManager $level, Random $random);
abstract public function generateChunk(int $chunkX, int $chunkZ);