作者:ClearSkyTea
项目:ClearSk
public function generateChunk($chunkX, $chunkZ)
{
$this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
$noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16);
$chunk = $this->level->getChunk($chunkX, $chunkZ);
for ($x = 0; $x < 16; ++$x) {
for ($z = 0; $z < 16; ++$z) {
$biome = Biome::getBiome(Biome::HELL);
$chunk->setBiomeId($x, $z, $biome->getId());
$color = [0, 0, 0];
$bColor = $biome->getColor();
$color[0] += ($bColor >> 16) ** 2;
$color[1] += ($bColor >> 8 & 0xff) ** 2;
$color[2] += ($bColor & 0xff) ** 2;
$chunk->setBiomeColor($x, $z, $color[0], $color[1], $color[2]);
for ($y = 0; $y < 128; ++$y) {
if ($y === 0 or $y === 127) {
$chunk->setBlockId($x, $y, $z, Block::BEDROCK);
continue;
}
$noiseValue = abs($this->emptyHeight - $y) / $this->emptyHeight * $this->emptyAmplitude - $noise[$x][$z][$y];
$noiseValue -= 1 - $this->density;
if ($noiseValue > 0) {
$chunk->setBlockId($x, $y, $z, Block::NETHERRACK);
} elseif ($y <= $this->waterHeight) {
$chunk->setBlockId($x, $y, $z, Block::STILL_LAVA);
}
}
}
}
foreach ($this->generationPopulators as $populator) {
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
}
}
作者:Skull3
项目:MineBloc
public function onLoad()
{
Generator::addGenerator(NoneGN::class, "None");
Generator::addGenerator(OreFlatGN::class, "OreFlat");
Generator::addGenerator(SkyBlockGN::class, "SkyBlock");
Generator::addGenerator(SkyGridGN::class, "SkyGrid");
}
作者:Gumbra
项目:Pocketmine-Plugin
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
if (strtolower($command->getName()) === "buyworld") {
if (count($args) < 1 || count($args) > 4) {
return false;
}
if (EconomyAPI::getInstance()->myMoney($sender->getName()) < 10000) {
$sender->sendMessage(TextFormat::RED . "[HyperPlot] You don't have enought money. It cost \$10000");
return true;
}
$world = array_shift($args);
if (strlen($world) < 3) {
$sender->sendMessage(TextFormat::RED . "[HyperPlot] Small World name");
return true;
}
if ($this->getServer()->isLevelGenerated($world)) {
$sender->sendMessage(TextFormat::RED . "[HyperPlot] A world named " . $world . " already exists");
return true;
}
EconomyAPI::getInstance()->reduceMoney($sender->getName(), 10000);
$this->getServer()->broadcastMessage($sender->sendMessage(TextFormat::RED . "[HyperPlot] Creating level " . $sender->getName() . "-" . $world . "..."));
$generator = Generator::getGenerator("ownworld");
$this->getServer()->generateLevel($sender->getName() . "-" . $world, null, $generator, []);
$this->getServer()->loadLevel($sender->getName() . "-" . $world);
return true;
}
return false;
}
作者:DWW
项目:pocketmine-plugin
public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args)
{
if (count($args) < 1 || count($args) > 4) {
return false;
}
$world = array_shift($args);
if ($this->owner->getServer()->isLevelGenerated($world)) {
$c->sendMessage(TextFormat::RED . mc::_("[MW] A world named %1% already exists", $world));
return true;
}
$seed = null;
$generator = null;
$opts = [];
if (isset($args[0])) {
$seed = intval($args[0]);
}
if (isset($args[1])) {
$generator = Generator::getGenerator($args[1]);
if (strtolower($args[1]) != Generator::getGeneratorName($generator)) {
$c->sendMessage(TextFormat::RED . mc::_("[MW] Unknown generator %1%", $args[1]));
return true;
}
$c->sendMessage(TextFormat::GREEN . mc::_("[MW] Using %1%", Generator::getGeneratorName($generator)));
}
if (isset($args[2])) {
$opts = ["preset" => $args[2]];
}
$this->owner->getServer()->broadcastMessage(mc::_("[MW] Creating level %1%... (Expect Lag)", $world));
$this->owner->getServer()->generateLevel($world, $seed, $generator, $opts);
$this->owner->getServer()->loadLevel($world);
return true;
}
作者:AvivShope
项目:bad-plugin
public function onEnable()
{
$api = $this->getServer()->getApiVersion();
if (version_compare($api, "1.12.0") >= 0) {
$this->getLogger()->info(TextFormat::RED . "WARNING: PMv1.5 support is experimental!");
Generator::addGenerator(NotSoFlat::class, "notsoflat");
} else {
Generator::addGenerator(NotSoFlatOld::class, "notsoflat");
}
}
作者:boyboo
项目:PocketMine-M
public static function generate($path, $name, $seed, $generator, array $options = [])
{
@mkdir($path, 0777, true);
@mkdir($path . "/region", 0777);
//TODO, add extra details
$levelData = new Compound("Data", ["hardcore" => new Byte("hardcore", 0), "initialized" => new Byte("initialized", 1), "GameType" => new Int("GameType", 0), "generatorVersion" => new Int("generatorVersion", 1), "SpawnX" => new Int("SpawnX", 128), "SpawnY" => new Int("SpawnY", 70), "SpawnZ" => new Int("SpawnZ", 128), "version" => new Int("version", 19133), "DayTime" => new Int("DayTime", 0), "LastPlayed" => new Long("LastPlayed", microtime(true) * 1000), "RandomSeed" => new Long("RandomSeed", $seed), "SizeOnDisk" => new Long("SizeOnDisk", 0), "Time" => new Long("Time", 0), "generatorName" => new String("generatorName", Generator::getGeneratorName($generator)), "generatorOptions" => new String("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""), "LevelName" => new String("LevelName", $name), "GameRules" => new Compound("GameRules", [])]);
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->setData(new Compound(null, ["Data" => $levelData]));
$buffer = $nbt->writeCompressed();
@file_put_contents($path . "level.dat", $buffer);
}
作者:DWW
项目:pocketmine-plugin
public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args)
{
if (count($args) != 0) {
return false;
}
if (MPMU::apiVersion("1.12.0")) {
$c->sendMessage(implode(", ", Generator::getGeneratorList()));
} else {
$c->sendMessage("normal, flat");
$c->sendMessage(TextFormat::RED . mc::_("[MW] Plugin provided world generators\n are not included in\n this list."));
}
return true;
}
作者:orlando09
项目:ImagicalMin
public static function generate($path, $name, $seed, $generator, array $options = [])
{
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
if (!file_exists($path . "/db")) {
mkdir($path . "/db", 0777, true);
}
//TODO, add extra details
$levelData = new Compound("", ["hardcore" => new Byte("hardcore", 0), "initialized" => new Byte("initialized", 1), "GameType" => new Int("GameType", 0), "generatorVersion" => new Int("generatorVersion", 1), "SpawnX" => new Int("SpawnX", 128), "SpawnY" => new Int("SpawnY", 70), "SpawnZ" => new Int("SpawnZ", 128), "version" => new Int("version", 19133), "DayTime" => new Int("DayTime", 0), "LastPlayed" => new Long("LastPlayed", microtime(true) * 1000), "RandomSeed" => new Long("RandomSeed", $seed), "SizeOnDisk" => new Long("SizeOnDisk", 0), "Time" => new Long("Time", 0), "RainTime" => new Int("RainTime", 0), "Raining" => new String("Raining", false), "ThunderTime" => new Int("ThunderTime", 0), "Thundering" => new String("Thundering", false), "generatorName" => new String("generatorName", Generator::getGeneratorName($generator)), "generatorOptions" => new String("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""), "LevelName" => new String("LevelName", $name), "GameRules" => new Compound("GameRules", [])]);
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->setData($levelData);
$buffer = $nbt->write();
file_put_contents($path . "level.dat", Binary::writeLInt(3) . Binary::writeLInt(strlen($buffer)) . $buffer);
$db = new \LevelDB($path . "/db");
$db->close();
}
作者:stoastye8
项目:Plugin
public function onEnable()
{
Generator::addGenerator(ApartGN::class, "Apart");
Generator::addGenerator(Ice::class, "Ice");
Generator::addGenerator(Lava::class, "Lava");
Generator::addGenerator(ManySkyBlockGN::class, "ManySkyBlock");
Generator::addGenerator(ManyTreeGN::class, "ManyTree");
Generator::addGenerator(MultySkyBlockGN::class, "MultySkyBlock");
Generator::addGenerator(MultySpecialSkyBlockGN::class, "MultySpecialSkyBlock");
Generator::addGenerator(NoneGN::class, "None");
Generator::addGenerator(OreFlatGN::class, "OreFlat");
Generator::addGenerator(OreTreeFlatGN::class, "OreTreeFlat");
Generator::addGenerator(SkyBlockGN::class, "SkyBlock");
Generator::addGenerator(SkyGridGN::class, "SkyGrid");
Generator::addGenerator(TreeGN::class, "Tree");
Generator::addGenerator(WaterGN::class, "Water");
Generator::addGenerator(WhiteWayGN::class, "WhiteWay");
}
作者:NewDelio
项目:PocketMine-0.13.
public function __construct(Level $level, $path)
{
$this->level = $level;
$this->path = $path;
if (!file_exists($this->path)) {
mkdir($this->path, 0777, true);
}
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->readCompressed(file_get_contents($this->getPath() . "level.dat"));
$levelData = $nbt->getData();
if ($levelData->Data instanceof Compound) {
$this->levelData = $levelData->Data;
} else {
throw new LevelException("Invalid level.dat");
}
if (!isset($this->levelData->generatorName)) {
$this->levelData->generatorName = new String("generatorName", Generator::getGenerator("DEFAULT"));
}
if (!isset($this->levelData->generatorOptions)) {
$this->levelData->generatorOptions = new String("generatorOptions", "");
}
}
作者:ZenaGamingsk
项目:Steadfast
/**
* Init the default level data
*
* @param Server $server
* @param string $name
* @param string $path
* @param string $provider Class that extends LevelProvider
*
* @throws \Exception
*/
public function __construct(Server $server, $name, $path, $provider)
{
$this->blockStates = Block::$fullList;
$this->levelId = static::$levelIdCounter++;
$this->blockMetadata = new BlockMetadataStore($this);
$this->server = $server;
$this->autoSave = $server->getAutoSave();
/** @var LevelProvider $provider */
if (is_subclass_of($provider, LevelProvider::class, true)) {
$this->provider = new $provider($this, $path);
} else {
throw new LevelException("Provider is not a subclass of LevelProvider");
}
$this->server->getLogger()->info("Preparing level \"" . $this->provider->getName() . "\"");
$this->generator = Generator::getGenerator($this->provider->getGenerator());
$this->blockOrder = $provider::getProviderOrder();
$this->useSections = $provider::usesChunkSection();
$this->folderName = $name;
$this->updateQueue = new ReversePriorityQueue();
$this->updateQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
$this->time = (int) $this->provider->getTime();
$this->chunkTickRadius = min($this->server->getViewDistance(), max(1, (int) $this->server->getProperty("chunk-ticking.tick-radius", 4)));
$this->chunksPerTick = (int) $this->server->getProperty("chunk-ticking.per-tick", 0);
$this->chunkTickList = [];
$this->clearChunksOnTick = (bool) $this->server->getProperty("chunk-ticking.clear-tick-list", false);
$this->timings = new LevelTimings($this);
$this->temporalPosition = new Position(0, 0, 0, $this);
$this->temporalVector = new Vector3(0, 0, 0);
}
作者:Timm0
项目:MyPlo
public function onEnable()
{
self::$instance = $this;
$folder = $this->getDataFolder();
if (!is_dir($folder)) {
mkdir($folder);
}
if (!is_dir($folder . "worlds")) {
mkdir($folder . "worlds");
}
Generator::addGenerator(MyPlotGenerator::class, "myplot");
$this->saveDefaultConfig();
$this->reloadConfig();
$this->getLogger()->info(TextFormat::GREEN . "Loading the Plot Framework!");
$this->getLogger()->warning(TextFormat::YELLOW . "It seems that you are running the development build of MyPlot! Thats cool, but it CAN be very, very buggy! Just be careful when using this plugin and report any issues to" . TextFormat::GOLD . " http://github.com/wiez/MyPlot/issues");
$this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
$this->getServer()->getCommandMap()->register(Commands::class, new Commands($this));
switch (strtolower($this->getConfig()->get("DataProvider"))) {
case "sqlite":
default:
$this->dataProvider = new SQLiteDataProvider($this);
break;
}
if ($this->getConfig()->get("UseEconomy") == true) {
if ($this->getServer()->getPluginManager()->getPlugin("EconomyAPI") !== null) {
$this->economyProvider = new EconomySProvider();
} elseif (($plugin = $this->getServer()->getPluginManager()->getPlugin("PocketMoney")) !== null) {
$this->economyProvider = new PocketMoneyProvider($plugin);
} else {
$this->economyProvider = null;
}
} else {
$this->economyProvider = null;
}
}
作者:ken7773
项目:PocketMine-0.13.
public function generateChunk($chunkX, $chunkZ)
{
$this->random->setSeed(0.0 ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
$noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16);
$chunk = $this->level->getChunk($chunkX, $chunkZ);
$biomeCache = [];
for ($x = 0; $x < 16; ++$x) {
for ($z = 0; $z < 16; ++$z) {
$minSum = 0;
$maxSum = 0;
$weightSum = 0;
$biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
$chunk->setBiomeId($x, $z, $biome->getId());
$color = [0, 0, 0];
for ($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx) {
for ($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz) {
$weight = self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE][$sz + self::$SMOOTH_SIZE];
if ($sx === 0 and $sz === 0) {
$adjacent = $biome;
} else {
$index = ($chunkX * 16 + $x + $sx & 4294967295.0) << 32 | $chunkZ * 16 + $z + $sz & 4294967295.0;
if (isset($biomeCache[$index])) {
$adjacent = $biomeCache[$index];
} else {
$biomeCache[$index] = $adjacent = $this->pickBiome($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz);
}
}
$minSum += ($adjacent->getMinElevation() - 1) * $weight;
$maxSum += $adjacent->getMaxElevation() * $weight;
$bColor = $adjacent->getColor();
$color[0] += ($bColor >> 16) ** 2 * $weight;
$color[1] += ($bColor >> 8 & 0xff) ** 2 * $weight;
$color[2] += ($bColor & 0xff) ** 2 * $weight;
$weightSum += $weight;
}
}
$minSum /= $weightSum;
$maxSum /= $weightSum;
$chunk->setBiomeColor($x, $z, \sqrt($color[0] / $weightSum), \sqrt($color[1] / $weightSum), \sqrt($color[2] / $weightSum));
$smoothHeight = ($maxSum - $minSum) / 2;
for ($y = 0; $y < 128; ++$y) {
if ($y === 0) {
$chunk->setBlockId($x, $y, $z, Block::BEDROCK);
continue;
}
$noiseValue = $noise[$x][$z][$y] - 1 / $smoothHeight * ($y - $smoothHeight - $minSum);
if ($noiseValue > 0) {
$chunk->setBlockId($x, $y, $z, Block::STONE);
} elseif ($y <= $this->waterHeight) {
$chunk->setBlockId($x, $y, $z, Block::STILL_WATER);
}
}
}
}
foreach ($this->generationPopulators as $populator) {
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
}
}
作者:iTXTec
项目:Genisy
public function generateChunk($chunkX, $chunkZ)
{
$this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
$seaFloorNoise = Generator::getFastNoise2D($this->noiseSeaFloor, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16);
$landNoise = Generator::getFastNoise2D($this->noiseLand, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16);
$mountainNoise = Generator::getFastNoise2D($this->noiseMountains, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16);
$baseNoise = Generator::getFastNoise2D($this->noiseBaseGround, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16);
$riverNoise = Generator::getFastNoise2D($this->noiseRiver, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16);
$chunk = $this->level->getChunk($chunkX, $chunkZ);
for ($genx = 0; $genx < 16; $genx++) {
for ($genz = 0; $genz < 16; $genz++) {
$canBaseGround = false;
$canRiver = true;
//using a quadratic function which smooth the world
//y = (2.956x)^2 - 0.6, (0 <= x <= 2)
$landHeightNoise = $landNoise[$genx][$genz] + 1;
$landHeightNoise *= 2.956;
$landHeightNoise = $landHeightNoise * $landHeightNoise;
$landHeightNoise = $landHeightNoise - 0.6;
$landHeightNoise = $landHeightNoise > 0 ? $landHeightNoise : 0;
//generate mountains
$mountainHeightGenerate = $mountainNoise[$genx][$genz] - 0.2;
$mountainHeightGenerate = $mountainHeightGenerate > 0 ? $mountainHeightGenerate : 0;
$mountainGenerate = (int) ($this->mountainHeight * $mountainHeightGenerate);
$landHeightGenerate = (int) ($this->landHeightRange * $landHeightNoise);
if ($landHeightGenerate > $this->landHeightRange) {
if ($landHeightGenerate > $this->landHeightRange) {
$canBaseGround = true;
}
$landHeightGenerate = $this->landHeightRange;
}
$genyHeight = $this->seaFloorHeight + $landHeightGenerate;
$genyHeight += $mountainGenerate;
//prepare for generate ocean, desert, and land
if ($genyHeight < $this->beathStartHeight) {
if ($genyHeight < $this->beathStartHeight - 5) {
$genyHeight += (int) ($this->seaFloorGenerateRange * $seaFloorNoise[$genx][$genz]);
}
$biome = Biome::getBiome(Biome::OCEAN);
if ($genyHeight < $this->seaFloorHeight - $this->seaFloorGenerateRange) {
$genyHeight = $this->seaFloorHeight;
}
$canRiver = false;
} else {
if ($genyHeight <= $this->beathStopHeight && $genyHeight >= $this->beathStartHeight) {
//todo: there is no beach biome, use desert temporarily
$biome = Biome::getBiome(Biome::DESERT);
} else {
$biome = $this->pickBiome($chunkX * 16 + $genx, $chunkZ * 16 + $genz);
if ($canBaseGround) {
$baseGroundHeight = (int) ($this->landHeightRange * $landHeightNoise) - $this->landHeightRange;
$baseGroundHeight2 = (int) ($this->basegroundHeight * ($baseNoise[$genx][$genz] + 1));
if ($baseGroundHeight2 > $baseGroundHeight) {
$baseGroundHeight2 = $baseGroundHeight;
}
if ($baseGroundHeight2 > $mountainGenerate) {
$baseGroundHeight2 = $baseGroundHeight2 - $mountainGenerate;
} else {
$baseGroundHeight2 = 0;
}
$genyHeight += $baseGroundHeight2;
}
}
}
if ($canRiver && $genyHeight <= $this->seaHeight - 5) {
$canRiver = false;
}
//generate river
if ($canRiver) {
$riverGenerate = $riverNoise[$genx][$genz];
if ($riverGenerate > -0.25 && $riverGenerate < 0.25) {
$riverGenerate = $riverGenerate > 0 ? $riverGenerate : -$riverGenerate;
$riverGenerate = 0.25 - $riverGenerate;
//y=x^2 * 4 - 0.0000001
$riverGenerate = $riverGenerate * $riverGenerate * 4;
//smooth again
$riverGenerate = $riverGenerate - 1.0E-7;
$riverGenerate = $riverGenerate > 0 ? $riverGenerate : 0;
$genyHeight -= $riverGenerate * 64;
if ($genyHeight < $this->seaHeight) {
$biome = Biome::getBiome(Biome::RIVER);
//to generate river floor
if ($genyHeight <= $this->seaHeight - 8) {
$genyHeight1 = $this->seaHeight - 9 + (int) ($this->basegroundHeight * ($baseNoise[$genx][$genz] + 1));
$genyHeight2 = $genyHeight < $this->seaHeight - 7 ? $this->seaHeight - 7 : $genyHeight;
$genyHeight = $genyHeight1 > $genyHeight2 ? $genyHeight1 : $genyHeight2;
}
}
}
}
$chunk->setBiomeId($genx, $genz, $biome->getId());
//biome color
//todo: smooth chunk color
$biomeColor = $biome->getColor();
$chunk->setBiomeColor($genx, $genz, $biomeColor >> 16, $biomeColor >> 8 & 0xff, $biomeColor & 0xff);
//generating
$generateHeight = $genyHeight > $this->seaHeight ? $genyHeight : $this->seaHeight;
for ($geny = 0; $geny <= $generateHeight; $geny++) {
if ($geny <= $this->bedrockDepth && ($geny == 0 or $this->random->nextRange(1, 5) == 1)) {
$chunk->setBlockId($genx, $geny, $genz, Block::BEDROCK);
//.........这里部分代码省略.........
作者:kniffo8
项目:Genisy
public function getWaterHeight() : int
{
if ($this->generatorInstance instanceof Generator) {
return $this->generatorInstance->getWaterHeight();
}
return 0;
}
作者:boyboo
项目:PocketMine-M
/**
* Init the default level data
*
* @param Server $server
* @param string $name
* @param string $path
* @param string $provider Class that extends LevelProvider
*
* @throws \Exception
*/
public function __construct(Server $server, $name, $path, $provider)
{
$this->levelId = static::$levelIdCounter++;
$this->blockMetadata = new BlockMetadataStore($this);
$this->server = $server;
/** @var LevelProvider $provider */
if (is_subclass_of($provider, "pocketmine\\level\\format\\LevelProvider", true)) {
$this->provider = new $provider($this, $path);
} else {
throw new \Exception("Provider is not a subclass of LevelProvider");
}
$this->server->getLogger()->info("Preparing level \"" . $this->provider->getName() . "\"");
$generator = Generator::getGenerator($this->provider->getGenerator());
$this->server->getGenerationManager()->openLevel($this, $generator, $this->provider->getGeneratorOptions());
$this->blockOrder = $provider::getProviderOrder();
$this->useSections = $provider::usesChunkSection();
$this->folderName = $name;
$this->updateQueue = new ReversePriorityQueue();
$this->updateQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
$this->time = (int) $this->provider->getTime();
$this->chunkTickRadius = min($this->server->getViewDistance(), max(1, (int) $this->server->getProperty("chunk-ticking.tick-radius", 3)));
$this->chunksPerTick = (int) $this->server->getProperty("chunk-ticking.per-tick", 80);
$this->chunkTickList = [];
$this->clearChunksOnTick = (bool) $this->server->getProperty("chunk-ticking.clear-tick-list", false);
$this->timings = new LevelTimings($this);
}
作者:Creeperface0
项目:ImagicalMin
public function generateChunk($chunkX, $chunkZ)
{
$this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
$noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16);
$chunk = $this->level->getChunk($chunkX, $chunkZ);
$biomeCache = [];
for ($x = 0; $x < 16; ++$x) {
for ($z = 0; $z < 16; ++$z) {
$minSum = 0;
$maxSum = 0;
$weightSum = 0;
$biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
$chunk->setBiomeId($x, $z, $biome->getId());
$color = [0, 0, 0];
for ($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx) {
for ($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz) {
$weight = self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE][$sz + self::$SMOOTH_SIZE];
if ($sx === 0 and $sz === 0) {
$adjacent = $biome;
} else {
$index = Level::chunkHash($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz);
if (isset($biomeCache[$index])) {
$adjacent = $biomeCache[$index];
} else {
$biomeCache[$index] = $adjacent = $this->pickBiome($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz);
}
}
$minSum += ($adjacent->getMinElevation() - 1) * $weight;
$maxSum += $adjacent->getMaxElevation() * $weight;
$bColor = $adjacent->getColor();
$color[0] += ($bColor >> 16) ** 2 * $weight;
$color[1] += ($bColor >> 8 & 0xff) ** 2 * $weight;
$color[2] += ($bColor & 0xff) ** 2 * $weight;
$weightSum += $weight;
}
}
$minSum /= $weightSum;
$maxSum /= $weightSum;
$chunk->setBiomeColor($x, $z, sqrt($color[0] / $weightSum), sqrt($color[1] / $weightSum), sqrt($color[2] / $weightSum));
$solidLand = false;
for ($y = 127; $y >= 0; --$y) {
if ($y === 0) {
$chunk->setBlockId($x, $y, $z, Block::BEDROCK);
continue;
}
// A noiseAdjustment of 1 will guarantee ground, a noiseAdjustment of -1 will guarantee air.
//$effHeight = min($y - $smoothHeight - $minSum,
$noiseAdjustment = 2 * (($maxSum - $y) / ($maxSum - $minSum)) - 1;
// To generate caves, we bring the noiseAdjustment down away from 1.
$caveLevel = $minSum - 10;
$distAboveCaveLevel = max(0, $y - $caveLevel);
// must be positive
$noiseAdjustment = min($noiseAdjustment, 0.4 + $distAboveCaveLevel / 10);
$noiseValue = $noise[$x][$z][$y] + $noiseAdjustment;
if ($noiseValue > 0) {
$chunk->setBlockId($x, $y, $z, Block::STONE);
$solidLand = true;
} elseif ($y <= $this->waterHeight && $solidLand == false) {
$chunk->setBlockId($x, $y, $z, Block::STILL_WATER);
}
}
}
}
foreach ($this->generationPopulators as $populator) {
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
}
}
作者:gitter-badge
项目:MyPlo
public function onEnable()
{
$this->getLogger()->info("Loading MyPlot");
self::$instance = $this;
$this->saveDefaultConfig();
$this->reloadConfig();
@mkdir($this->getDataFolder());
@mkdir($this->getDataFolder() . "worlds");
Generator::addGenerator(MyPlotGenerator::class, "myplot");
$lang = $this->getConfig()->get("language", BaseLang::FALLBACK_LANGUAGE);
$this->baseLang = new BaseLang($lang, $this->getFile() . "resources/");
// Initialize DataProvider
$cacheSize = $this->getConfig()->get("PlotCacheSize");
switch (strtolower($this->getConfig()->get("DataProvider"))) {
case "sqlite":
default:
$this->dataProvider = new SQLiteDataProvider($this, $cacheSize);
break;
}
// Initialize EconomyProvider
if ($this->getConfig()->get("UseEconomy") == true) {
if ($this->getServer()->getPluginManager()->getPlugin("EconomyAPI") !== null) {
$this->economyProvider = new EconomySProvider();
} elseif (($plugin = $this->getServer()->getPluginManager()->getPlugin("PocketMoney")) !== null) {
$this->economyProvider = new PocketMoneyProvider($plugin);
}
}
$this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
$this->getServer()->getCommandMap()->register(Commands::class, new Commands($this));
}
作者:xuxugz
项目:Genisy
//.........这里部分代码省略.........
Timings::init();
$this->consoleSender = new ConsoleCommandSender();
$this->commandMap = new SimpleCommandMap($this);
$this->registerEntities();
$this->registerTiles();
InventoryType::init(min(32, $this->inventoryNum));
//Bigger than 32 with cause problems
Block::init();
Item::init();
Biome::init();
Effect::init();
Enchantment::init();
Attribute::init();
/** TODO: @deprecated */
//TextWrapper::init();
$this->craftingManager = new CraftingManager($this->readRecipesFromJson);
$this->pluginManager = new PluginManager($this, $this->commandMap);
$this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender);
$this->pluginManager->setUseTimings($this->getProperty("settings.enable-profiling", false));
$this->profilingTickRate = (double) $this->getProperty("settings.profile-report-trigger", 20);
$this->pluginManager->registerInterface(PharPluginLoader::class);
$this->pluginManager->registerInterface(FolderPluginLoader::class);
$this->pluginManager->registerInterface(ScriptPluginLoader::class);
//set_exception_handler([$this, "exceptionHandler"]);
register_shutdown_function([$this, "crashDump"]);
$this->queryRegenerateTask = new QueryRegenerateEvent($this, 5);
$this->network->registerInterface(new RakLibInterface($this));
$this->pluginManager->loadPlugins($this->pluginPath);
//$this->updater = new AutoUpdater($this, $this->getProperty("auto-updater.host", "www.pocketmine.net"));
$this->enablePlugins(PluginLoadOrder::STARTUP);
LevelProviderManager::addProvider($this, Anvil::class);
LevelProviderManager::addProvider($this, McRegion::class);
if (extension_loaded("leveldb")) {
$this->logger->debug($this->getLanguage()->translateString("pocketmine.debug.enable"));
LevelProviderManager::addProvider($this, LevelDB::class);
}
Generator::addGenerator(Flat::class, "flat");
Generator::addGenerator(Normal::class, "normal");
Generator::addGenerator(Normal::class, "default");
Generator::addGenerator(Nether::class, "hell");
Generator::addGenerator(Nether::class, "nether");
foreach ((array) $this->getProperty("worlds", []) as $name => $worldSetting) {
if ($this->loadLevel($name) === false) {
$seed = $this->getProperty("worlds.{$name}.seed", time());
$options = explode(":", $this->getProperty("worlds.{$name}.generator", Generator::getGenerator("default")));
$generator = Generator::getGenerator(array_shift($options));
if (count($options) > 0) {
$options = ["preset" => implode(":", $options)];
} else {
$options = [];
}
$this->generateLevel($name, $seed, $generator, $options);
}
}
if ($this->getDefaultLevel() === null) {
$default = $this->getConfigString("level-name", "world");
if (trim($default) == "") {
$this->getLogger()->warning("level-name cannot be null, using default");
$default = "world";
$this->setConfigString("level-name", "world");
}
if ($this->loadLevel($default) === false) {
$seed = $this->getConfigInt("level-seed", time());
$this->generateLevel($default, $seed === 0 ? time() : $seed);
}
$this->setDefaultLevel($this->getLevelByName($default));
}
$this->properties->save(true);
if (!$this->getDefaultLevel() instanceof Level) {
$this->getLogger()->emergency($this->getLanguage()->translateString("pocketmine.level.defaultError"));
$this->forceShutdown();
return;
}
if ($this->netherEnabled) {
if (!$this->loadLevel($this->netherName)) {
//$this->logger->info("正在生成地狱 ".$this->netherName);
$this->generateLevel($this->netherName, time(), Generator::getGenerator("nether"));
}
$this->netherLevel = $this->getLevelByName($this->netherName);
}
if ($this->getProperty("ticks-per.autosave", 6000) > 0) {
$this->autoSaveTicks = (int) $this->getProperty("ticks-per.autosave", 6000);
}
$this->enablePlugins(PluginLoadOrder::POSTWORLD);
if ($this->aiEnabled) {
$this->aiHolder = new AIHolder($this);
}
if ($this->dserverConfig["enable"] and $this->getAdvancedProperty("dserver.server-list", "") != "") {
$this->scheduler->scheduleRepeatingTask(new CallbackTask([$this, "updateDServerInfo"]), $this->dserverConfig["timer"]);
}
if ($cfgVer != $advVer) {
$this->logger->notice("Your genisys.yml needs update");
$this->logger->notice("Current Version: {$advVer} Latest Version: {$cfgVer}");
}
$this->generateRecipeList();
$this->start();
} catch (\Throwable $e) {
$this->exceptionHandler($e);
}
}
作者:robske11
项目:ClearSk
//.........这里部分代码省略.........
ini_set('assert.exception', 1);
if ($this->logger instanceof MainLogger) {
$this->logger->setLogDebug(\pocketmine\DEBUG > 1);
}
if (\pocketmine\DEBUG >= 0) {
@cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion());
}
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.networkStart", [$this->getIp() === "" ? "*" : $this->getIp(), $this->getPort()]));
define("BOOTUP_RANDOM", random_bytes(16));
$this->serverID = Utils::getMachineUniqueId($this->getIp() . $this->getPort());
$this->getLogger()->debug("Server unique id: " . $this->getServerUniqueId());
$this->getLogger()->debug("Machine unique id: " . Utils::getMachineUniqueId());
$this->network = new Network($this);
$this->network->setName($this->getMotd());
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.info", [$this->getName(), $this->getPocketMineVersion(), $this->getCodename(), $this->getApiVersion(), $this->getPocketMineBuild()]));
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.license", [$this->getName()]));
Timings::init();
$this->consoleSender = new ConsoleCommandSender();
$this->commandMap = new SimpleCommandMap($this);
$this->registerEntities();
$this->registerTiles();
InventoryType::init();
Block::init();
Item::init();
Biome::init();
Effect::init();
Enchantment::init();
Attribute::init();
EnchantmentLevelTable::init();
Color::init();
$this->craftingManager = new CraftingManager();
$this->pluginManager = new PluginManager($this, $this->commandMap);
$this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender);
$this->pluginManager->setUseTimings($this->getProperty("settings.enable-profiling", false));
$this->profilingTickRate = (double) $this->getProperty("settings.profile-report-trigger", 20);
$this->pluginManager->registerInterface(PharPluginLoader::class);
$this->pluginManager->registerInterface(ScriptPluginLoader::class);
register_shutdown_function([$this, "crashDump"]);
$this->queryRegenerateTask = new QueryRegenerateEvent($this, 5);
$this->network->registerInterface(new RakLibInterface($this));
$this->pluginManager->loadPlugins($this->pluginPath);
$this->updater = new AutoUpdater($this, $this->getProperty("auto-updater.host", "jenkins.clearskyteam.org"));
$this->enablePlugins(PluginLoadOrder::STARTUP);
LevelProviderManager::addProvider($this, Anvil::class);
LevelProviderManager::addProvider($this, McRegion::class);
if (extension_loaded("leveldb")) {
$this->logger->debug($this->getLanguage()->translateString("pocketmine.debug.enable"));
LevelProviderManager::addProvider($this, LevelDB::class);
}
Generator::addGenerator(Flat::class, "flat");
Generator::addGenerator(Normal::class, "normal");
Generator::addGenerator(Normal::class, "default");
Generator::addGenerator(Nether::class, "hell");
Generator::addGenerator(Nether::class, "nether");
foreach ((array) $this->getProperty("worlds", []) as $name => $worldSetting) {
if ($this->loadLevel($name) === false) {
$seed = $this->getProperty("worlds.{$name}.seed", time());
$options = explode(":", $this->getProperty("worlds.{$name}.generator", Generator::getGenerator("default")));
$generator = Generator::getGenerator(array_shift($options));
if (count($options) > 0) {
$options = ["preset" => implode(":", $options)];
} else {
$options = [];
}
$this->generateLevel($name, $seed, $generator, $options);
}
}
if ($this->getDefaultLevel() === null) {
$default = $this->getConfigString("level-name", "world");
if (trim($default) == "") {
$this->getLogger()->warning("level-name cannot be null, using default");
$default = "world";
$this->setConfigString("level-name", "world");
}
if ($this->loadLevel($default) === false) {
$seed = getopt("", ["level-seed::"])["level-seed"] ?? $this->properties->get("level-seed", time());
if (!is_numeric($seed) or bccomp($seed, "9223372036854775807") > 0) {
$seed = Utils::javaStringHash($seed);
} elseif (PHP_INT_SIZE === 8) {
$seed = (int) $seed;
}
$this->generateLevel($default, $seed === 0 ? time() : $seed);
}
$this->setDefaultLevel($this->getLevelByName($default));
}
$this->properties->save(true);
if (!$this->getDefaultLevel() instanceof Level) {
$this->getLogger()->emergency($this->getLanguage()->translateString("pocketmine.level.defaultError"));
$this->forceShutdown();
return;
}
if ($this->getProperty("ticks-per.autosave", 6000) > 0) {
$this->autoSaveTicks = (int) $this->getProperty("ticks-per.autosave", 6000);
}
$this->enablePlugins(PluginLoadOrder::POSTWORLD);
$this->start();
} catch (\Throwable $e) {
$this->exceptionHandler($e);
}
}