Spawning Trees

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

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

    justcool393

    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:

    Code:java
    1.  
    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...
    16.  


    TreeFarmUtil class
    Code:java
    1.  
    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. }
    25.  


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

    Code:java
    1.  
    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. }
    7.  


    Success (open)
    [​IMG]

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


    Error (when there is air) (open)
    [​IMG]

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


    Not enough space but still generates (open)
    [​IMG]

    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.

    Bumping...

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

    justcool393

    Bump de dum bump...
     
  3. Offline

    RawCode

    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

    justcool393

    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

    justcool393

    Bump...
     
  6. Offline

    xTrollxDudex

    justcool393
    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

    justcool393

    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

    xTrollxDudex

    justcool393
    Hmm, try
    PHP:
    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