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

World Generation

Discussion in 'Development' started by Aenteritas, Sep 29, 2019.

  1. Aenteritas

    Aenteritas Silverfish

    Messages:
    22
    Error:
    Cannot move in created world.

    Code (SkyBlockGenerator.php):
    PHP:
    <?php

    namespace net\phytonia\sb;

    use 
    pocketmine\level\generator\Generator;
    use 
    pocketmine\math\Vector3;

    class 
    SkyBlockGenerator extends Generator {

        const 
    NAME "phytonia";
        private 
    $options;
        private 
    $block$radius$floorLevel,$biome,$baseFloor;
        
    /** @var ChunkManager */
        
    private $level;
        
    /** @var Random */
        
    private $random;
        
    /** @var FullChunk Chunk master */
        
    private $chunk;

        public function 
    __construct(array $options = []) {
            
    $this->block Block::STONE;
            
    $this->radius 10;
            
    $this->floorLevel 64;
            
    $this->biome 1;
            
    $this->options $options;
            
    $this->chunk  null;
            
    $this->baseFloor Block::AIR;
        }

        public function 
    init(ChunkManager $levelRandom $random) :void {
            
    $this->level $level;
            
    $this->random $random;
            
    // Parse options...
            
    if (isset($this->options["preset"])) {
                
    $preset ",".strtolower($this->options["preset"]).",";
                if (
    preg_match('/,\s*block\s*=\s*(\d+)\s*,/',$preset,$mv)) {
                    
    $this->block intval($mv[1]);
                }
                if (
    preg_match('/,\s*radius\s*=\s*(\d+)\s*,/',$preset,$mv)) {
                    
    $this->radius intval($mv[1]);
                }
                if (
    preg_match('/,\s*floorlevel\s*=\s*(\d+)\s*,/',$preset,$mv)) {
                    
    $this->floorLevel intval($mv[1]);
                }
                if (
    preg_match('/,\s*biome\s*=\s*(\d+)\s*,/',$preset,$mv)) {
                    
    $this->biome intval($mv[1]);
                }
                if (
    preg_match('/,\s*basefloor\s*=\s*(\d+)\s*,/',$preset,$mv)) {
                    
    $this->baseFloor intval($mv[1]);
                }
            }
        }
        protected static function 
    inSpawn($rad2,$spx,$spz,$x,$z){
            
    $xoff $spx $x;
            
    $zoff $spz $z;
            return 
    $rad2 > ($xoff $xoff $zoff $zoff);
        }
        public function 
    generateChunk($chunkX$chunkZ) :void {
            
    $spawn $this->getSpawn();
            
    // Adjust spawn so it is relative to current chunk...
            
    $spawn->$spawn->- ($chunkX << 4);
            
    $spawn->$spawn->- ($chunkZ << 4);
            
    $inSpawn = (-$this->radius <= $spawn->&& $spawn->16 $this->radius  &&
                -
    $this->radius <= $spawn->&& $spawn->16 $this->radius);
            if (
    $inSpawn || $this->chunk === null) {
                
    $chunk $this->level->getChunk($chunkX,$chunkZ);
                
    $chunk->setGenerated();
                
    $c Biome::getBiome($this->biome)->getColor();
                
    $R $c >> 16;
                
    $G = ($c >> 8) & 0xff;
                
    $B $c 0xff;
                
    $rad2 $this->radius $this->radius;
                for(
    $Z 0$Z 16; ++$Z){
                    for(
    $X 0$X 16; ++$X){
                        
    $chunk->setBiomeId($X$Z$this->biome);
                        
    $chunk->setBiomeColor($X$Z$R$G$B);
                        
    $chunk->setBlock($X0$Z$this->baseFloor0);
                        for(
    $y 1$y 128; ++$y){
                            
    $chunk->setBlock($X$y$ZBlock::AIR0);
                        }
                        if (
    self::inSpawn($rad2,$spawn->x,$spawn->z,$X,$Z)) {
                            
    $chunk->setBlock($X,$this->floorLevel,$Z,$this->block);
                        }
                    }
                }
                if (!
    $inSpawn) {
                    
    $this->chunk = clone $chunk;
                }
            } else {
                
    $chunk = clone $this->chunk;
            }
            
    $chunk->setX($chunkX);
            
    $chunk->setZ($chunkZ);
            
    $this->level->setChunk($chunkX,$chunkZ,$chunk);
        }
        public function 
    populateChunk($chunkX$chunkZ) :void {
            
    // Don't do nothing here...
        
    }
        public function 
    getSettings() :array {
            return 
    $this->options;
        }
        public function 
    getName() :string {
            return 
    self::NAME;
        }
        public function 
    getSpawn() :Vector3 {
            return new 
    Vector3(128,$this->floorLevel+1,128);
        }
    }
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    you probably hasn't set all the blocks in the chunks, if you want functional SkyBlock generator, look into the MultiWorld plugin.
     
  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.