Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Grow a tree on BlockPlaceEvent();

Comments in 'Plugin Development' started by RumDaDuMCPE, Oct 19, 2016.

  1. RumDaDuMCPE
    Offline

    RumDaDuMCPE New Member

    Joined:
    Oct 18, 2016
    Posts:
    12
    Minecraft User:
    RumDaDuMCPE
    Hello,

    Could you please tell me the code to grow a tree upon placing an oak sapling [Item ID 6] (using BlockPlaceEvent())?

    For example, If I place a sapling on a grass block, It immediately grows into a tree, without using BoneMeal on it (if you know what I mean).

    The tree needs to be grown on the same co-ordinates as of the oak sapling which was placed.

    [ps. I'm new to the Forums so please forgive me if I made any mistake(s) or broke any rule(s) in this post.]

    Thanks in advance,
    RumDaDuMCPE. :)
    Last edited: Oct 19, 2016
  2. RumDaDuMCPE
    Offline

    RumDaDuMCPE New Member

    Joined:
    Oct 18, 2016
    Posts:
    12
    Minecraft User:
    RumDaDuMCPE
    Here's a plugin that I coded but failed to function:

    <?php

    namespace RumDaDuMCPE;

    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\item\Item;
    use pocketmine\level\generator\object\Tree;
    use pocketmine\level\Level;
    use pocketmine\Player;
    use pocketmine\utils\Random;

    use pocketmine\event\block\BlockPlaceEvent;

    class Main extends PluginBase implements Listener {
    public function onEnable() {
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    public function tree(BlockPlaceEvent $e) {
    $i = $e->getItem();
    $b = $e->getBlock();
    $p = $e->getPlayer();
    if ($i->getId() === 6 && $this->getSide(0)->getId() === self::GRASS) {
    $level = $p->getLevel();
    if ($level !== "world") {
    $pos = new Vector3(128, 64, 128);
    $random = new Random();
    $type = 0;
    TreeObject::growTree($level, $pos, $random, $type);
    }
    }
    }
    }
    ?>

    please tell me what's wrong with this.
    Last edited: Oct 19, 2016
  3. MineBuilderFR
    Offline

    MineBuilderFR Active Member

    Joined:
    Mar 14, 2015
    Posts:
    56
    Minecraft User:
    MineBuilderFR
    PHP:
    $levelname $level->getName(); //Or $level->getFolderName()
    if($levelname !== "world"){

    }

    And Why TreeObject?

    PHP:
    Tree::growTree($level$x$y$z$random$type$noBigTree);
    or

    PHP:
    use pocketmine\level\generator\object\Tree as TreeObject;
    Last edited: Oct 19, 2016
  4. RumDaDuMCPE
    Offline

    RumDaDuMCPE New Member

    Joined:
    Oct 18, 2016
    Posts:
    12
    Minecraft User:
    RumDaDuMCPE
    What's $noBigTree?
  5. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    Here is a massive clue.

    No - Meaning opposite to "YES"
    Big - Meaning opposite to "SMALL"
    Tree - The thing you wanted to grow upon BlockPlaceEvent.

    Sarcasm aside,

    Its simply a thing to stop big trees growing.
    MichaelM04 and ImagicalGamer like this.
  6. RumDaDuMCPE
    Offline

    RumDaDuMCPE New Member

    Joined:
    Oct 18, 2016
    Posts:
    12
    Minecraft User:
    RumDaDuMCPE
    So,

    $noSmallTree spawns a big tree, and $noMediumTree, what does that spawn? please help, I cant figure this out...
  7. RumDaDuMCPE
    Offline

    RumDaDuMCPE New Member

    Joined:
    Oct 18, 2016
    Posts:
    12
    Minecraft User:
    RumDaDuMCPE
    I'm Just joking, Chill.

    Thanks for your help :)
  8. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan

Share This Page

Advertisement