Spawning Trees

Discussion in 'Plugin Development' started by justcool393, Dec 29, 2013.

Thread Status:
Not open for further replies.
  1. Offline


    I have two problems related to trees in general.

    World.spawnTree(TreeType, Location) works for me, but, it will spawn a tree, even if there is no room for it to spawn. Also, after the spawnTree is used, it doesn't work again until after the plugin is reloaded (even if there is enough space).

    A way to get it double spawn trees is by using that World.spawnTree() method and reloading the plugin. Though, it shouldn't happen, correct?

    Part of Main class that is necessary:

    2. public List<Location> normalTree = new ArrayList<Location>();
    3. public List<Location> birchTree = new ArrayList<Location>();
    4. public List<Location> spruceTree = new ArrayList<Location>();
    5. public List<Location> jungleTree = new ArrayList<Location>();
    6. public List<Location> acaciaTree = new ArrayList<Location>();
    7. public List<Location> darkOakTree = new ArrayList<Location>();
    8. /* ... */
    9. normalTree = tfc.GetTreeFarmData("tree");
    10. birchTree = tfc.GetTreeFarmData("birch");
    11. spruceTree = tfc.GetTreeFarmData("redwood");
    12. jungleTree = tfc.GetTreeFarmData("small_jungle");
    13. acaciaTree = tfc.GetTreeFarmData("acacia");
    14. darkOakTree = tfc.GetTreeFarmData("dark_oak");
    15. // It gets the location data correctly...

    TreeFarmUtil class
    2. public class TreeFarmUtil {
    3. private Main m;
    4. public TreeFarmUtil(Main m) { this.m = m; }
    5. public void plantTrees() {
    6. m.treeFarmReady = false;
    7. generateTree(TreeType.TREE, m.normalTree);
    8. generateTree(TreeType.BIRCH, m.birchTree);
    9. generateTree(TreeType.REDWOOD, m.spruceTree);
    10. generateTree(TreeType.SMALL_JUNGLE, m.jungleTree);
    11. generateTree(TreeType.ACACIA, m.acaciaTree);
    12. generateTree(TreeType.DARK_OAK, m.darkOakTree);
    13. }
    14. private void generateTree(TreeType type, List<Location> list) {
    15. Main.sendDbg("Attempting to generate tree of type " + type.toString());
    16. Integer failedTimes = 0;
    17. for (Location l : list) {
    18. if (!l.getWorld().generateTree(l.add(0,1,0), type)) {
    19. failedTimes += 1;
    20. } else { continue; }
    21. }
    22. Main.sendDbg("Error while generating tree (x" + failedTimes.toString() + ")");
    23. }
    24. }

    Part of method that calls the generation of trees...

    2. if (m.treeFarmReady) {
    3. /* This returns true, it's not an issue with here */
    4. Main.sendDbg("Allowed to plant trees");
    5. t.plantTrees();
    6. }

    Success (open)

    That's when there is air everywhere, and after the plugin has been reloaded.

    Error (when there is air) (open)

    That's when there is enough space, and before the plugin is reloaded/restarted.

    Not enough space but still generates (open)

    This is when there is NOT enough space for trees to grow, but it still generates them nevertheless.

    (Note: I had this problem before, even before 1.7)

    Any suggestions would be appreciated.


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 6, 2016
  2. Offline


    Bump de dum bump...
  3. Offline


    add output of method params to System.out.

    add output of lists content to System.out.

    correct code indentation, use pastebin in case of emergency.
  4. Offline


    1. I verified all of the method params, and they look fine.
    2. The lists also are good.
    3. The Bukkit forums messed the indentation up. I don't think it likes tabs.
  5. Offline


  6. Offline


    Try using the a method for implementing classes of BlockSapling.TreeGenerator (net.minecraft.server). It takes a boolean (doesn't matter). Use a(World(NMS world to br precise), Random(shouldn't matter too much), int (x coord), int (y coord), int (z coord))
  7. Offline


    I honestly haven't used NMS, but I'll try and see what I can do with it.
    The random in there is probably when actually generating the tree, the shape and size, etc.
  8. Offline


    Hmm, try
    WorldGenForestTree tree = new WorldGenForestTree(false);

    WorldServer ws = ((CraftWorldBukkit.getServer().getWorld("world")).getHandle();
    Location l /* Stuff here */;
    Random seed = new Random();

    tree.a(wsseedl.getBlockX(), l.getBlockY(), l.getBlockZ());
Thread Status:
Not open for further replies.

Share This Page