1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Add Structure in a chunk

Discussion in 'Development' started by SunsetTadpole78, Feb 20, 2021.

  1. SunsetTadpole78

    SunsetTadpole78 Creeper

    Messages:
    4
    Hi, i am wondering how could i add a structure in a chunk from this function:
    PHP:
    <?php

    use Pc\level\generator\ender\populator\EnderPilar;
    use 
    pocketmine\block\Block;
    use 
    Pc\level\generator\biome\Biome;
    use 
    pocketmine\level\{
        
    ChunkManager,
        
    generator\Generator,
        
    generator\noise\Simplex,
        
    generator\populator\Populator};
    use 
    pocketmine\math\Vector3 as Vector3;
    use 
    pocketmine\utils\Random;

    class 
    Ender extends Generator {

        private static 
    $GAUSSIAN_KERNEL null;
        private static 
    $SMOOTH_SIZE 1;
        
    /** @var ChunkManager */
        
    protected $level;
        
    /** @var Random */
        
    protected $random;
        
    /** @var Populator[] */
        
    private $populators = [];
        private 
    $waterHeight 0;
        private 
    $emptyHeight 24;
        private 
    $emptyAmplitude 2;
        private 
    $density 0;
        
    /** @var Populator[] */
        
    private $generationPopulators = [];
        
    /** @var Simplex */
        
    private $noiseBase;

        public function 
    __construct(array $options = []){
            if(
    self::$GAUSSIAN_KERNEL === null){
                
    self::generateKernel();
            }
        }

        private static function 
    generateKernel(){
            
    self::$GAUSSIAN_KERNEL = [];

            
    $bellSize self::$SMOOTH_SIZE;
            
    $bellHeight self::$SMOOTH_SIZE;

            for(
    $sx = -self::$SMOOTH_SIZE$sx <= self::$SMOOTH_SIZE; ++$sx){
                
    self::$GAUSSIAN_KERNEL[$sx self::$SMOOTH_SIZE] = [];

                for(
    $sz = -self::$SMOOTH_SIZE$sz <= self::$SMOOTH_SIZE; ++$sz){
                    
    $bx $bellSize $sx;
                    
    $bz $bellSize $sz;
                    
    self::$GAUSSIAN_KERNEL[$sx self::$SMOOTH_SIZE][$sz self::$SMOOTH_SIZE] = $bellHeight exp(-($bx $bx $bz $bz) / 2);
                }
            }
        }

        public function 
    getName(): string{
            return 
    "Ender";
        }

        public function 
    getWaterHeight(): int{
            return 
    $this->waterHeight;
        }

        public function 
    getSettings(): array{
            return [];
        }

        public function 
    init(ChunkManager $levelRandom $random): void{
            
    $this->level $level;
            
    $this->random $random;
            
    $this->random->setSeed($this->level->getSeed());
            
    $this->noiseBase = new Simplex($this->random4464);
            
    $this->random->setSeed($this->level->getSeed());
            
    $pilar = new EnderPilar();
            
    $pilar->setBaseAmount(0);
            
    $pilar->setRandomAmount(0);
            
    $this->populators[] = $pilar;
        }

        public function 
    generateChunk(int $chunkXint $chunkZ): void{
            
    $this->random->setSeed(0xa6fe78dc ^ ($chunkX << 8) ^ $chunkZ $this->level->getSeed());

            
    $noise $this->noiseBase->getFastNoise3D(1612816484$chunkX 160$chunkZ 16);

            
    $chunk $this->level->getChunk($chunkX$chunkZ);

            for(
    $x 0$x 16; ++$x){
                for(
    $z 0$z 16; ++$z){

                    
    $biome Biome::getBiome(Biome::END);
                    
    $biome->setGroundCover([
                        
    Block::get(Block::OBSIDIAN0),

                    ]);
                    
    $chunk->setBiomeId($x$z$biome->getId());

                    for(
    $y 0$y 128; ++$y){

                        
    $noiseValue = (abs($this->emptyHeight $y) / $this->emptyHeight) * $this->emptyAmplitude $noise[$x][$z][$y];
                        
    $noiseValue -= $this->density;

                        
    $distance = new Vector3(0640);
                        
    $distance $distance->distance(new Vector3($chunkX 16 $x, ($y 1.3), $chunkZ 16 $z));

                        if (
    $noiseValue && $distance 150 or $noiseValue < -0.2 && $distance 1000) {
                            
    $chunk->setBlockId($x$y$zBlock::END_STONE);
                        }
                    }
                }
            }

            foreach(
    $this->generationPopulators as $populator){
                
    $populator->populate($this->level$chunkX$chunkZ$this->random);
            }
        }

        public function 
    populateChunk(int $chunkXint $chunkZ): void{

        }

        public function 
    getSpawn(): Vector3{
            return new 
    Vector3(0.51280.5);
        }
    }
    (the code comes from teaspoon)
    https://github.com/CortexPE/TeaSpoo...CortexPE/level/generator/ender/Ender.php#L105

    The world is currently empty and I would like to add the portal structure in 0/0 for example

    Here is the field currently
    [​IMG]

    - SunsetTadpole78
     
    Last edited: Feb 24, 2021
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.