本文整理汇总了PHP中pocketmine\level\Level::generateChunk方法的典型用法代码示例。如果您正苦于以下问题:PHP Level::generateChunk方法的具体用法?PHP Level::generateChunk怎么用?PHP Level::generateChunk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\level\Level
的用法示例。
在下文中一共展示了Level::generateChunk方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateLevel
/**
* Generates a new level if it does not exists
*
* @param string $name
* @param int $seed
* @param string $generator Class name that extends pocketmine\level\generator\Generator
* @param array $options
*
* @return bool
*/
public function generateLevel($name, $seed = null, $generator = null, $options = [])
{
if (trim($name) === "" or $this->isLevelGenerated($name)) {
return false;
}
$seed = $seed === null ? PHP_INT_SIZE === 8 ? unpack("N", @Utils::getRandomBytes(4, false))[1] << 32 >> 32 : unpack("N", @Utils::getRandomBytes(4, false))[1] : (int) $seed;
if ($generator !== null and class_exists($generator) and is_subclass_of($generator, Generator::class)) {
$generator = new $generator($options);
} else {
$options["preset"] = $this->getConfigString("generator-settings", "");
$generator = Generator::getGenerator($this->getLevelType());
}
if (($provider = LevelProviderManager::getProviderByName($providerName = $this->getProperty("level-settings.default-format", "mcregion"))) === null) {
$provider = LevelProviderManager::getProviderByName($providerName = "mcregion");
}
try {
$path = $this->getDataPath() . "worlds/" . $name . "/";
/** @var \pocketmine\level\format\LevelProvider $provider */
$provider::generate($path, $name, $seed, $generator, $options);
$level = new Level($this, $name, $path, $provider);
$this->levels[$level->getId()] = $level;
$level->initLevel();
} catch (\Exception $e) {
$this->logger->error("Could not generate level \"" . $name . "\": " . $e->getMessage());
if ($this->logger instanceof MainLogger) {
$this->logger->logException($e);
}
return false;
}
$this->getPluginManager()->callEvent(new LevelInitEvent($level));
$this->getPluginManager()->callEvent(new LevelLoadEvent($level));
$this->getLogger()->notice("Spawn terrain for level \"{$name}\" is being generated in the background");
$centerX = $level->getSpawnLocation()->getX() >> 4;
$centerZ = $level->getSpawnLocation()->getZ() >> 4;
$order = [];
for ($X = -4; $X <= 4; ++$X) {
for ($Z = -4; $Z <= 4; ++$Z) {
$distance = $X ** 2 + $Z ** 2;
$chunkX = $X + $centerX;
$chunkZ = $Z + $centerZ;
$index = PHP_INT_SIZE === 8 ? ($chunkX & 0xffffffff) << 32 | $chunkZ & 0xffffffff : $chunkX . ":" . $chunkZ;
$order[$index] = $distance;
}
}
asort($order);
$chunkX = $chunkZ = null;
foreach ($order as $index => $distance) {
if (PHP_INT_SIZE === 8) {
$chunkX = $index >> 32 << 32 >> 32;
$chunkZ = ($index & 0xffffffff) << 32 >> 32;
} else {
list($chunkX, $chunkZ) = explode(":", $index);
$chunkX = (int) $chunkX;
$chunkZ = (int) $chunkZ;
}
$level->generateChunk($chunkX, $chunkZ, true);
}
return true;
}
示例2: generateLevel
/**
* Generates a new level if it does not exists
*
* @param string $name
* @param int $seed
* @param string $generator Class name that extends pocketmine\level\generator\Noise
* @param array $options
*
* @return bool
*/
public function generateLevel($name, $seed = null, $generator = null, $options = [])
{
if (trim($name) === "" or $this->isLevelGenerated($name)) {
return false;
}
$seed = $seed === null ? Binary::readInt(@Utils::getRandomBytes(4, false)) : (int) $seed;
if (!isset($options["preset"])) {
$options["preset"] = $this->getConfigString("generator-settings", "");
}
if (!($generator !== null and class_exists($generator, true) and is_subclass_of($generator, Generator::class))) {
$generator = Generator::getGenerator($this->getLevelType());
}
if (($provider = LevelProviderManager::getProviderByName($providerName = $this->getProperty("level-settings.default-format", "mcregion"))) === null) {
$provider = LevelProviderManager::getProviderByName($providerName = "mcregion");
}
try {
$path = $this->getDataPath() . "worlds/" . $name . "/";
/** @var \pocketmine\level\format\LevelProvider $provider */
$provider::generate($path, $name, $seed, $generator, $options);
$level = new Level($this, $name, $path, $provider);
$this->levels[$level->getId()] = $level;
$level->initLevel();
$level->setTickRate($this->baseTickRate);
} catch (\Exception $e) {
$this->logger->error($this->getLanguage()->translateString("pocketmine.level.generateError", [$name, $e->getMessage()]));
if ($this->logger instanceof MainLogger) {
$this->logger->logException($e);
}
return false;
}
$this->getPluginManager()->callEvent(new LevelInitEvent($level));
$this->getPluginManager()->callEvent(new LevelLoadEvent($level));
$this->getLogger()->notice($this->getLanguage()->translateString("pocketmine.level.backgroundGeneration", [$name]));
$centerX = $level->getSpawnLocation()->getX() >> 4;
$centerZ = $level->getSpawnLocation()->getZ() >> 4;
$order = [];
for ($X = -4; $X <= 4; ++$X) {
for ($Z = -4; $Z <= 4; ++$Z) {
$distance = $X ** 2 + $Z ** 2;
$chunkX = $X + $centerX;
$chunkZ = $Z + $centerZ;
$index = Level::chunkHash($chunkX, $chunkZ);
$order[$index] = $distance;
}
}
asort($order);
$chunkX = $chunkZ = null;
foreach ($order as $index => $distance) {
Level::getXZ($index, $chunkX, $chunkZ);
$level->generateChunk($chunkX, $chunkZ, true);
}
return true;
}
示例3: generateLevel
/**
* Generates a new level if it does not exists
*
* @param string $name
* @param int $seed
* @param string $generator Class name that extends pocketmine\level\generator\Generator
* @param array $options
*
* @return bool
*/
public function generateLevel($name, $seed = null, $generator = null, $options = [])
{
if (trim($name) === "" or $this->isLevelGenerated($name)) {
return false;
}
$seed = $seed === null ? Binary::readInt(@Utils::getRandomBytes(4, false)) : (int) $seed;
if ($generator !== null and class_exists($generator) and is_subclass_of($generator, Generator::class)) {
$generator = new $generator($options);
} else {
$options["preset"] = $this->getConfigString("generator-settings", "");
$generator = Generator::getGenerator($this->getLevelType());
}
if (($provider = LevelProviderManager::getProviderByName($providerName = $this->getProperty("level-settings.default-format", "mcregion"))) === null) {
$provider = LevelProviderManager::getProviderByName($providerName = "mcregion");
}
try {
$path = $this->getDataPath() . "worlds/" . $name . "/";
/** @var \pocketmine\level\format\LevelProvider $provider */
$provider::generate($path, $name, $seed, $generator, $options);
$level = new Level($this, $name, $path, $provider);
$this->levels[$level->getId()] = $level;
$level->initLevel();
} catch (\Exception $e) {
$this->logger->error("Could not generate level \"" . $name . "\": " . $e->getMessage());
if ($this->logger instanceof MainLogger) {
$this->logger->logException($e);
}
return false;
}
$this->getPluginManager()->callEvent(new LevelInitEvent($level));
$this->getPluginManager()->callEvent(new LevelLoadEvent($level));
$this->getLogger()->notice("Spawn terrain for level \"{$name}\" is being generated in the background");
$radiusSquared = ($this->getViewDistance() + 1) / M_PI;
$radius = ceil(sqrt($radiusSquared));
$centerX = $level->getSpawnLocation()->getX() >> 4;
$centerZ = $level->getSpawnLocation()->getZ() >> 4;
$order = [];
for ($X = -$radius; $X <= $radius; ++$X) {
for ($Z = -$radius; $Z <= $radius; ++$Z) {
$distance = $X ** 2 + $Z ** 2;
if ($distance > $radiusSquared) {
continue;
}
$chunkX = $X + $centerX;
$chunkZ = $Z + $centerZ;
$index = Level::chunkHash($chunkX, $chunkZ);
$order[$index] = $distance;
}
}
asort($order);
$chunkX = $chunkZ = null;
foreach ($order as $index => $distance) {
Level::getXZ($index, $chunkX, $chunkZ);
$level->generateChunk($chunkX, $chunkZ);
}
return true;
}
示例4: generateLevel
/**
* Generates a new level if it does not exists
*
* @param string $name
* @param int $seed
* @param array $options
*
* @return bool
*/
public function generateLevel($name, $seed = null, $options = [])
{
if (trim($name) === "" or $this->isLevelGenerated($name)) {
return false;
}
$seed = $seed === null ? PHP_INT_SIZE === 8 ? unpack("N", @Utils::getRandomBytes(4, false))[1] << 32 >> 32 : unpack("N", @Utils::getRandomBytes(4, false))[1] : (int) $seed;
if (($provider = LevelProviderManager::getProviderByName($providerName = $this->getProperty("level-settings.default-format", "mcregion"))) === null) {
$provider = LevelProviderManager::getProviderByName($providerName = "mcregion");
}
try {
$path = $this->getDataPath() . "worlds/" . $name . "/";
/** @var \pocketmine\level\format\LevelProvider $provider */
$provider::generate($path, $name, $seed, $options);
$level = new Level($this, $name, $path, $provider);
$this->levels[$level->getId()] = $level;
$level->initLevel();
} catch (\Exception $e) {
$this->logger->error("Could not generate level \"" . $name . "\": " . $e->getMessage());
if ($this->logger instanceof MainLogger) {
$this->logger->logException($e);
}
return false;
}
$this->getPluginManager()->callEvent(new LevelInitEvent($level));
$this->getPluginManager()->callEvent(new LevelLoadEvent($level));
$centerX = $level->getSpawnLocation()->getX() >> 4;
$centerZ = $level->getSpawnLocation()->getZ() >> 4;
$order = [];
for ($X = -3; $X <= 3; ++$X) {
for ($Z = -3; $Z <= 3; ++$Z) {
$distance = $X ** 2 + $Z ** 2;
$chunkX = $X + $centerX;
$chunkZ = $Z + $centerZ;
$index = Level::chunkHash($chunkX, $chunkZ);
$order[$index] = $distance;
}
}
asort($order);
foreach ($order as $index => $distance) {
Level::getXZ($index, $chunkX, $chunkZ);
$level->generateChunk($chunkX, $chunkZ, true);
}
return true;
}