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

SkyBlock. Create Tree

Discussion in 'Plugin Help' started by Ngao, May 10, 2017.

  1. Ngao

    Ngao Silverfish

    Messages:
    18
    Can help me code tree creation, TreeOak
     
  2. XCodeMCPE

    XCodeMCPE Slime

    Messages:
    96
    GitHub:
    xcodemcpe
    SkyBlock?
     
  3. Ngao

    Ngao Silverfish

    Messages:
    18
    Yes, create OakTree code please :))
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You can use the pocketmine\level\generator\object\Tree class with the static function growTree.
     
  5. Lazer

    Lazer Spider

    Messages:
    10
    GitHub:
    Lazerplayz
    It's somthing like this
    use pocketmine\level\generator\object\Tree;

    Tree::growTree(ChunkManager $level, $x, $y, $z, $this->random, 0);
     
    Last edited: May 10, 2017
  6. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    It looks like you just took that code snippet out of a plugin. Those parameters aren't really accurate. None of them need to be attributes of the class. The function is:
    PHP:
     Tree::growTree(ChunkManager $level$x$y$zRandom $random$type); 
    $level does not necessarily need to be a Level. It can be an instance of ChunkManager instead. I wouldn't use chunkX and chunkZ values, because in my experience, it causes the tree to be generated weirdly. $x, $y, and $z are self explanatory. $random must be an instance of pocketmine\utils\Random, and $type is the type of tree that will be generated.
     
  7. Ngao

    Ngao Silverfish

    Messages:
    18
    Here
    PHP:
    <?php

    namespace SkyBlock\generator\generators;

    use 
    pocketmine\block\Block;
    use 
    pocketmine\level\ChunkManager;
    use 
    pocketmine\level\generator\normal\object\Tree;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\utils\Random;
    use 
    SkyBlock\generator\SkyBlockGenerator;

    class 
    BasicIsland extends SkyBlockGenerator {

        
    /** @var array */
        
    private $settings;

        
    /** @var string */
        
    private $name;

        
    /** @var ChunkManager */
        
    private $level;

        
    /** @var Random */
        
    private $random;

        
    /**
         * BasicIsland constructor.
         *
         * @param array $settings
         */
        
    public function __construct(array $settings = []) {
            
    $this->settings $settings;
        }

        
    /**
         * Initialize BasicIsland
         *
         * @param ChunkManager $level
         * @param Random $random
         */
        
    public function init(ChunkManager $levelRandom $random) {
            
    $this->level $level;
            
    $this->random $random;
            
    $this->name "basic";
            
    $this->islandName "Basic Island";
        }

        
    /**
         * Return generator name
         *
         * @return string
         */
        
    public function getName() {
            return 
    $this->name;
        }

        public function 
    getSettings() {
            return 
    $this->settings;
        }

        public function 
    generateChunk($chunkX$chunkZ) {
            
    $chunk $this->level->getChunk($chunkX$chunkZ);
            
    $chunk->setGenerated();
            if (
    $chunkX 20 == && $chunkZ 20 == 0) {
                for (
    $x 0$x 16$x++) {
                    for (
    $z 0$z 16$z++) {
                        
    $chunk->setBlock($x0$zBlock::BEDROCK);
                        for (
    $y 1$y <= 3$y++) {
                            
    $chunk->setBlock($x$y$zBlock::STONE);
                        }
                        
    $chunk->setBlock($x4$zBlock::DIRT);
                        
    $chunk->setBlock($x5$zBlock::GRASS);
                    }
                    
    Tree::growTree($this->level$chunkX 16 86$chunkZ 16 8$this->random0);
                }
                
    $chunk->setX($chunkX);
                
    $chunk->setZ($chunkZ);
                
    $this->level->setChunk($chunkX$chunkZ$chunk);
            }
        }

        public function 
    populateChunk($chunkX$chunkZ) {
            
    //TODO: Set Biome ID?
            
    return;
        }

        
    /**
         * Return BasicIsland spawn
         *
         * @return Vector3
         */
        
    public function getSpawn() {
            return new 
    Vector3(8710);
        }

    }
     
  8. Lazer

    Lazer Spider

    Messages:
    10
    GitHub:
    Lazerplayz
    You just solved your own question, lol
     
  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.