I have not tested this, i think it is possible by doing PHP: Biome::getBiome(Biome::FOREST)->addPopulator($populator);
The method is not working. PHP: $flowerPopulator = new FlowerPopulator(); $flowerPopulator->setBaseAmount(5); $flowerPopulator->addType([Block::DANDELION, 0]); $flowerPopulator->addType([Block::RED_FLOWER, 0]); $flowerPopulator->addType([Block::RED_FLOWER, Flower::TYPE_ALLIUM]); $flowerPopulator->addType([Block::RED_FLOWER, 3]); $flowerPopulator->addType([Block::RED_FLOWER, Flower::TYPE_OXEYE_DAISY]); $flowerPopulator->addType([Block::RED_FLOWER, Flower::TYPE_ORANGE_TULIP]); Biome::getBiome(Biome::PLAINS)->addPopulator($flowerPopulator); Plugin startup before world generation. Any other ways?
I checked, the populator is added, but does not work. Spoiler: var_dump(Biome::getBiome(Biome::pLAINS)->getPopulators()); Code: array(2) { [0]=> object(pocketmine\level\generator\populator\TallGrass)#5381 (3) { ["level":"pocketmine\level\generator\populator\TallGrass":private]=> NULL ["randomAmount":"pocketmine\level\generator\populator\TallGrass":private]=> NULL ["baseAmount":"pocketmine\level\generator\populator\TallGrass":private]=> int(12) } [1]=> object(myplugin\world\populator\FlowerPopulator)#10439 (4) { ["level":"myplugin\world\populator\FlowerPopulator":private]=> NULL ["randomAmount":"myplugin\world\populator\FlowerPopulator":private]=> NULL ["baseAmount":"myplugin\world\populator\FlowerPopulator":private]=> int(5) ["flowerTypes":"myplugin\world\populator\FlowerPopulator":private]=> array(6) { [0]=> array(2) { [0]=> int(37) [1]=> int(0) } [1]=> array(2) { [0]=> int(38) [1]=> int(0) } [2]=> array(2) { [0]=> int(38) [1]=> int(2) } [3]=> array(2) { [0]=> int(38) [1]=> int(3) } [4]=> array(2) { [0]=> int(38) [1]=> int(8) } [5]=> array(2) { [0]=> int(38) [1]=> int(5) } } } } Spoiler: FlowerPopulator class PHP: class FlowerPopulator extends Populator{ /** @var ChunkManager */ private $level; private $randomAmount; private $baseAmount = 8; private $flowerTypes = []; /** * @param $amount */ public function setRandomAmount($amount){ $this->randomAmount = $amount; } /** * @param $amount */ public function setBaseAmount($amount){ $this->baseAmount = $amount; } /** * @param $type */ public function addType($type){ $this->flowerTypes[] = $type; } /** * @return array */ public function getTypes() : array{ return $this->flowerTypes; } /** * @param ChunkManager $level * @param $chunkX * @param $chunkZ * @param Random $random * * @return mixed|void */ public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){ $this->level = $level; $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount; $endNum = count($this->flowerTypes) - 1; for($i = 0; $i < $amount; ++$i){ $x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15); $z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15); $y = $this->getHighestWorkableBlock($x, $z); if($y !== -1 and $this->canFlowerStay($x, $y, $z)){ $type = mt_rand(0, $endNum); $this->level->setBlockIdAt($x, $y, $z, $this->flowerTypes[$type][0]); $this->level->setBlockDataAt($x, $y, $z, $this->flowerTypes[$type][1]); } } } /** * @param $x * @param $y * @param $z * * @return bool */ private function canFlowerStay($x, $y, $z) : bool{ $b = $this->level->getBlockIdAt($x, $y, $z); return ($b === Block::AIR or $b === Block::SNOW_LAYER) and $this->level->getBlockIdAt($x, $y - 1, $z) === Block::GRASS; } /** * @param $x * @param $z * * @return int */ private function getHighestWorkableBlock($x, $z) : int{ for($y = 127; $y >= 0; --$y){ $b = $this->level->getBlockIdAt($x, $y, $z); if($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2 and $b !== Block::SNOW_LAYER){ break; } } return $y === 0 ? -1 : ++$y; }}
That won't work if you're executing it on the main thread. The generator tasks run on another thread (they are created asynchronously) and the generator probably maintain a copy of generators and populators at the time they were registered. Adding populators isn't possible without creating a generator class that extends the parent generator class (which is pocketmine's Normal generator if you don't use a custom world generator) and then registering the generator and changing your world's generator type. You can copy that addPopulator code into the constructor of the generator, I think that will work.
I could send you my generator which has pretty much all biomes and noise generator from java version. The biome selector isn't perfect. But might be useful anyways. Send me a message I'll drop it there due to licence the Nukkit has (Yea, I translated the generator PHP).