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

Solved Add skylight on sapling

Discussion in 'Plugin Help' started by AsponPL, May 30, 2020.

  1. AsponPL

    AsponPL Spider Jockey

    Messages:
    47
    Hello, I want to do a function that would make underground trees grow normally but I have no idea how to do it. If you know how to solve this problem, write in advance thanks.
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    It would still grow if you put torches around such that the light level is more than 7.
    If you want it to grow regardless of light level you would have to extend Sapling, override onRandomTick and register it
     
  3. AsponPL

    AsponPL Spider Jockey

    Messages:
    47
    Something like this?
    PHP:
    <?php

    namespace TreeFix;

    use 
    pocketmine\block\Sapling;

    use 
    pocketmine\level\generator\object\Tree;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\Random;

    class 
    TreeFix extends Sapling
    {

        public 
    $x;
        public 
    $y;
        public 
    $z;

        public function 
    onRandomTick() : void
        
    {
            if (
    $this->level->getFullLightAt($this->x$this->y$this->z) >= and mt_rand(17) === 1) {
                if ((
    $this->meta 0x08) === 0x08) {
                    
    Tree::growTree($this->getLevel(), $this->x$this->y$this->z, new Random(mt_rand()), $this->getVariant());
                } else {
                    
    $this->meta |= 0x08;
                    
    $this->getLevel()->setBlock($this$thistrue);
                }
            }
        }
    }

    when i try this i got that error:

    Error: "Call to a member function getFullLightAt() on null" (EXCEPTION) in "plugins/TreeFix/src/TreeFix/TreeFix" at line 20
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    You can remove that line actually since you dont need to check the light , just leave the mt_rand there, you dont need the public xyz too
     
  5. AsponPL

    AsponPL Spider Jockey

    Messages:
    47
    i got a new error:

    TypeError: "Argument 1 passed to pocketmine\level\generator\object\Tree::growTree() must implement interface pocketmine\level\ChunkManager, null given, called in C:\Users\aspon\Documents\Minecraft\Server\plugins\TreeFix\src\TreeFix\TreeFix.php on line 18" (EXCEPTION) in "src/pocketmine/level/generator/object/Tree" at line 55

    code:

    PHP:
    <?php

    namespace TreeFix;

    use 
    pocketmine\block\Sapling;

    use 
    pocketmine\level\ChunkManager;
    use 
    pocketmine\level\format\Chunk;
    use 
    pocketmine\level\generator\object\Tree;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\Random;

    class 
    TreeFix extends Sapling
    {

        public function 
    onRandomTick(): void{
            
    Tree::growTree($this->getLevel(), $this->x$this->y$this->z, new Random(mt_rand()), $this->getVariant());
        }
    }
     
  6. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Did you do anything else? I can't think of why $this->getLevel() will return null under normal circumstances
    Could you show the whole error stack trace?
     
  7. AsponPL

    AsponPL Spider Jockey

    Messages:
    47
    TypeError: "Argument 1 passed to pocketmine\level\generator\object\Tree::growTree() must implement interface pocketmine\level\ChunkManager, null given, called in C:\Users\aspon\Documents\Minecraft\Server\plugins\TreeFix\src\TreeFix\TreeFix.php on line 18" (EXCEPTION) in "src/pocketmine/level/generator/object/Tree" at line 55
    06:50:30 Server|DEBUG > #0 plugins/TreeFix/src/TreeFix/TreeFix(18): pocketmine\level\generator\object\Tree::growTree(NULL , NULL , NULL , NULL , object pocketmine\utils\Random, integer 0)
    06:50:30 Server|DEBUG > #1 plugins/TreeFix/src/TreeFix/Main(64): TreeFix\TreeFix->onRandomTick()
    06:50:30 Server|DEBUG > #2 src/pocketmine/plugin/PluginBase(115): TreeFix\Main->onEnable()
    06:50:30 Server|DEBUG > #3 src/pocketmine/plugin/PluginManager(541): pocketmine\plugin\PluginBase->setEnabled(boolean 1)
    06:50:30 Server|DEBUG > #4 src/pocketmine/Server(1894): pocketmine\plugin\PluginManager->enablePlugin(object TreeFix\Main)
    06:50:30 Server|DEBUG > #5 src/pocketmine/Server(1880): pocketmine\Server->enablePlugin(object TreeFix\Main)
    06:50:30 Server|DEBUG > #6 src/pocketmine/Server(1685): pocketmine\Server->enablePlugins(integer 1)
    06:50:30 Server|DEBUG > #7 src/pocketmine/PocketMine(273): pocketmine\Server->__construct(object BaseClassLoader, object pocketmine\utils\MainLogger, string[80] C:\Users\aspon\Documents\Minecraft\Server\, string[88] C:\Users\aspon\Documents\Minecraft\Server\)
    06:50:30 Server|DEBUG > #8 src/pocketmine/PocketMine(296): pocketmine\server()
    06:50:30 Server|DEBUG > #9 (11): require(string[127] phar://C:/Users/aspon/Documents/Minecraft/Server)
     
  8. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    No you are not supposed to call onRandomTick() yourself
    You just need to do BlockFactory::registerBlock(new TreeFix(),true); will do
     
  9. AsponPL

    AsponPL Spider Jockey

    Messages:
    47
    After doing this, nothing crashes in the console but nothing happens in the game, the trees continue to grow underground
     
  10. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Isn't that what you are trying to achieve?? For trees to grow underground?
     
  11. AsponPL

    AsponPL Spider Jockey

    Messages:
    47
    i Solved that
     
  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.