[Basic] Creating custom world generators

Discussion in 'Resources' started by codename_B, Jul 4, 2011.

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

    codename_B

    This is a quick tutorial about how to use ChunkGenerator to write your own custom map gens;
    It will be aimed at the very basic generation level, assuming you know how to define packages and import the relevant classes.
    What I won't do is explain how to do seamless chunk generation - as I'm not 100% sure myself - you're better off checking out other peoples source in order to see how they do it.
    My way of getting around the issue was to generate huge areas of terrain in "memory" (as a heightmap) - this is a fairly efficient way of doing things, but you still have to generate the heightmap.

    If you're looking for some javadocs, you'll find them here.
    http://jd.bukkit.org/doxygen/d8/d49/classorg_1_1bukkit_1_1generator_1_1ChunkGenerator.html


    Anyway, on with lesson 1.
    Code:
    public class GenerateNothing extends ChunkGenerator {
        //This is where you stick your populators - these will be covered in another tutorial
        @Override
        public List<BlockPopulator> getDefaultPopulators(World world) {
            return Arrays.asList((BlockPopulator) new BlankPopulator());
        }
        //This needs to be set to return true to override minecraft's default behaviour
        @Override
        public boolean canSpawn(World world, int x, int z) {
            return true;
        }
        //This converts relative chunk locations to bytes that can be written to the chunk
        public int xyzToByte(int x, int y, int z) {
        return (x * 16 + z) * 128 + y;
        }
    
        @Override
        public byte[] generate(World world, Random rand, int chunkx, int chunkz) {
        result = new byte[32768];
        int y = 0;
        //This will set the floor of each chunk at bedrock level to bedrock
        for(int x=0; x<16; x++){
        for(int z=0; z<16; z++) {
        result[xyzToByte(x,y,z)] = (byte) Material.BEDROCK.getId();
        }
        }
        return result;
        }
    
    }
    
    This will create a 1 layer thin layer of bedrock flatmap - please don't use it as-is for a plugin, add new stuff before you release anything. Consider yourself warned :p

    Lesson 2 - actually getting the bloody thing to work.
    Have this method in your main class

    Code:
    public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
            return new GenerateNothing();
        }
    
    then add this code to bukkit.yml

    Code:
    worlds:
        yourworldname:
             generator: YourPluginName
    
     
    Damocles, Plo124, DeMaggo and 3 others like this.
  2. Offline

    Jaker232

    First!

    I say this mode is [Basic] mode because it uses easy codes.

    No more transferring SSP flat maps, finally!
     
  3. Offline

    codename_B

    Changed the title to [Basic] - done :) thanks for the feedback.
     
  4. Offline

    Jaker232

    Your welcome! I saw the [Basic] before you quoted it.
     
  5. Offline

    tprk77

    Is it possible to add custom populators to minecraft's default chunk generator?
     
  6. Offline

    codename_B

    I've never tried. I assume it would be possible.
     
  7. Offline

    tprk77

    dylanisawesome1 likes this.
  8. Offline

    Pencil

    I'm puzzled about this part:

    Code:
    new BlankPopulator());
    am I supposed to create a new class? D:
     
  9. Offline

    codename_B

    Only if you want to - that bit can just be removed if you don't want to use any populators.
     
  10. Offline

    Pencil

    Ah ok I get it now xD I wasn't 100% what you meant with that! Thanks!! :)
     
  11. Offline

    praccu

    I can't find anyone who does this. Any suggestions?

    Thanks.
     
  12. Offline

    codename_B

    Seamless terrain generation? Perhaps you should check out the seamless terrain generation tutorial using SimplexOctaves I wrote.
     
  13. Offline

    Kierrow

    I wanted to create a custom map generator because I think the one 1.8 offers is boring.
    Sorry Notch :(

    I've tried your code, but when I load bukkit, it says:
    >> Could not set generator for default world 'world': Plugin 'CT-World' is not enabled yet (is it load:STARTUP?)

    What can I do here?

    -Kierrow
     
  14. Offline

    Celtic Minstrel

    Add "load: startup" on a line in your plugin.yml.
     
  15. Offline

    Kierrow

    THANK YOU!
     
  16. Offline

    MasterAsp

    This post was amazing and helped me so much. THANK YOU!
     
  17. Offline

    iffa

    Bump for awesome ness
     
  18. Awesome thank you codename_B! You have helped me a lot already.
     
Thread Status:
Not open for further replies.

Share This Page