Solved Growing saplings

Discussion in 'Spigot Plugin Development' started by daniel_crime, Mar 11, 2020.

Thread Status:
Not open for further replies.
  1. So there's a plugin called "Tree Twerk" since it didn't work on the latest version I decided to try and remake it on my own tho I don't know where to go now

    First I tried setting the sapling stage to the max stage, the tree didn't grow and the debug info said the sapling is still at the stage it started on

    Second I tried using generateTree but the problem with that was it doesn't just generate the tree but also dirt underneath it and some change the dirt around it

    The last option I had in my head was using bonemeal on the sapling tho I have no idea how to do that
     
  2. Oh wow, i would recommend you first reading some informations about the java docs how their methods actually work.
    The last thing you want to do would be an virtual non player interact but that's not the right way.

    in first case you have your sapling right? so basically you have an location that can be found in the world right? Okay.
    so there are just simple steps for you to let an tree grow, spigot has an wonderful object data implementation, in this case its an MaterialData / now BlockData.

    So first make sure your block is an existing BlockData.

    If so, then cast your block as the following Sapling if it is one!

    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/type/Sapling.html
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/type/Sapling.html#setStage-int-

    The method setStage will do all the growing things for you :)
    Easy ;)
     
    • Like Like x 1
  3. I tried that already but to no success, it was the first thing I tried actually

    Code (Java):
        public void isSapling(Player player, Location loc){
            Block block = loc.getBlock();
            BlockData sapling = block.getBlockData();
            if (sapling instanceof Sapling) {
                Sapling sap = (Sapling) sapling;
                player.sendMessage(String.valueOf(sap.getStage()));
                sap.setStage(sap.getMaximumStage());
                player.sendMessage(String.valueOf(sap.getStage()));
            }
        }
    So the first message displays 0 and after the stage is set it displays as 1 but after crouching again the cycle repeats and the sapling still doesn't grow
     
  4. I guess the maxium stage is the previous step to grow and it would requiere a random tick to do so. You would have to generate the tree instead of growing the sapling.
     
    • Agree Agree x 1
  5. you will have to update the BlockData/ BlockState after you modified it
     
    • Agree Agree x 3
Thread Status:
Not open for further replies.