本文整理匯總了PHP中pocketmine\level\generator\Generator類的典型用法代碼示例。如果您正苦於以下問題:PHP Generator類的具體用法?PHP Generator怎麽用?PHP Generator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Generator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: generateChunk
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);
}
}
示例2: onLoad
public function onLoad()
{
Generator::addGenerator(NoneGN::class, "None");
Generator::addGenerator(OreFlatGN::class, "OreFlat");
Generator::addGenerator(SkyBlockGN::class, "SkyBlock");
Generator::addGenerator(SkyGridGN::class, "SkyGrid");
}
示例3: onCommand
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;
}
示例4: onSCommand
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;
}
示例5: onEnable
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");
}
}
示例6: generate
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);
}
示例7: onSCommand
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;
}
示例8: generate
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();
}
示例9: onEnable
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");
}
示例10: __construct
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", "");
}
}
示例11: __construct
/**
* 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);
}
示例12: onEnable
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;
}
}
示例13: generateChunk
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);
}
}
示例14: generateChunk
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);
//.........這裏部分代碼省略.........
示例15: getWaterHeight
public function getWaterHeight() : int
{
if ($this->generatorInstance instanceof Generator) {
return $this->generatorInstance->getWaterHeight();
}
return 0;
}