The always up-to-date definitive guide to terrain generation: part three - Populators galore

Discussion in 'Resources' started by jtjj222, Aug 17, 2012.

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

    jtjj222

    Part one
    Part Two

    Last time, we left off with a flat world generator. Today, we will cover adding grass to the world with a block populator! Create a new class and call it GrassPopulator. It should extend BlockPopulator. Add the following code to it:

    Code:java
    1.  
    2. @Override
    3. public void populate(World world, Random rand, Chunk chunk) {
    4. for (int x=0; x<16; x++) {
    5. for (int z=0;z<16;z++) {
    6. int realX = x + chunk.getX() * 16; //find the world location of chunk location x
    7. int realZ = z + chunk.getZ() * 16;
    8. world.getBlockAt(realX, 64, realZ).setType(Material.GRASS);
    9. }
    10. }
    11. }

    Most of this should make sense. We loop through all of the blocks in the chunk at level 64, and replace them with grass.
    The populate function is called after the chunk generator by bukkit. But how does bukkit know about it? We tell it! Inside BasicChunkGenerator.java, in the getDefaultPopulators method, right under the comment that says "add your populators here", add an instance of GrassPopulator to the array list:
    Code:java
    1. pops.add(new me.<your name>.BasicTerrain.GrassPopulator());

    Test it out now.
    [​IMG]
    Sucsess!
    In a later section, we will cover making multi-chunk block populators, as well as some interesting structures such as npc villages (Hopefully someone with more experience can help with that section)
    Stay tuned for the next part of this sereis which will cover more interesting terrain using "noise"!

    (placeholder for errors and later section links)
    Part 4: http://forums.bukkit.org/threads/th...-to-terrain-generation-part-four-hills.94164/
    Part 5: http://forums.bukkit.org/threads/th...-to-terrain-generation-part-5-3d-noise.94312/

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

    Limeth

    I love those tutorials! I can't wait for more 8D
     
  3. Offline

    jtjj222

    What shall the next topic be?
     
  4. Offline

    Limeth

    Probably some amazing block populators =D
     
  5. Offline

    Hoolean Retired Staff

    Where should this be :/
    I have no getDefaultPopulators method :O
     
  6. Offline

    jtjj222

    Sorry, just edited part 2. It was in the zip file, but never covered in any of the tutorials.
     
  7. Offline

    Hoolean Retired Staff

    Should be...

     
  8. Offline

    jtjj222

    Thank you for correcting my typo. Fixed.
     
    MrBluebear3 likes this.
  9. Offline

    EnvisionRed

    I've been getting some patchiness with this. Some chunks don't have the layer of grass on top, as if Bukkit never passed those chunks to the populator. Any help with this?
     
  10. Offline

    jtjj222

    That is strange, I honestly can't think of why that would happen. You stumped me :\
     
  11. Offline

    EnvisionRed

    Might just be my computer or maybe the new version of bukkit. Who knows?
     
  12. Offline

    ignirtoq

    I've been working through these tutorials the past few hours, and I have exactly the same problem. It seems to be entire chunks aren't getting the GrassPopulator called. I'm running the latest bukkit dev version. Did you ever figure out what caused this?
     
  13. Offline

    jtjj222

    I can't reproduce the problem. Anyway, the grass/water should be put on in the chunkgenerator, and bp's should be for smaller things :D
     
  14. Offline

    ZachBora

    jtjj222 I think you can replace any "*16" by "<< 4".
     
    jtjj222 likes this.
  15. Offline

    jtjj222

    JVM does this automatically, doesn't it?
     
  16. Offline

    ZachBora

    Yes, but it will still be faster. And in a world generator, we can't afford slow code.


    (prays that jtjj222 doesn't look at the * 16 and / 16 in the PlotMe source)
     
  17. Offline

    jtjj222

    Most jvm's will optimize it for us (so there is no speed increase). Besides, it doesn't cause a problem. As the old adage says: "premature optimization is the root of all evil."
     
  18. Offline

    jtjj222

    Fyi, I buckled down and changed it in the latest tutorial :p
     
  19. Offline

    ZachBora

    jtjj222 by the way, do you know how to make a worldgen with schematics?
     
  20. Offline

    jtjj222

  21. Offline

    ZachBora

    jtjj222 Thanks I'll check that out. Some people asked me to allow plotme to work with a schematic.
     
  22. Offline

    jtjj222

Thread Status:
Not open for further replies.

Share This Page