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.
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
Something like this? PHP: <?phpnamespace 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) >= 8 and mt_rand(1, 7) === 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, $this, true); } } }} 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
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
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: <?phpnamespace 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()); }}
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?
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)
No you are not supposed to call onRandomTick() yourself You just need to do BlockFactory::registerBlock(new TreeFix(),true); will do
After doing this, nothing crashes in the console but nothing happens in the game, the trees continue to grow underground