ChunkGenerators & BlockPopulators FAQ

Discussion in 'Plugin Development' started by Dinnerbone, Jun 23, 2011.

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


    I need to generate X chunks in any direction with default chunk generator, 101th and any futher chunks with custom script.

    Well generator is fine, but how can i jump to it from custom generator?
  2. Offline

    Dinnerbone Bukkit Team Member

    You can't do that. A generator can never change for a world at runtime.
  3. Offline


    There's a bug in the ChunkGenerator class. If you do not override the canSpawn() function, the default function will try to find a spot to spawn on top of gravel or sand. However, if you don't HAVE any gravel or sand on the map, or any on the highest layer, (you know, like what would happen if you're generator simply generates a simple flat grassy field forever in all directions - to test the thing) bukkit will just keep generating map forever, never finding a suitable location to spawn, eventually running the memory footprint right into the ceiling.

    Why only sand or gravel? Why not grass or dirt or stone?

    Edit: Actually... this might explain why I can never get a decent world spawn when using bukkit. Whenever I start a new world, it always manages to toss me onto a beach... and this is probably why.
  4. Offline

    Dinnerbone Bukkit Team Member

    That's default Minecraft behaviour, not bukkit. It will not let you spawn anywhere but sand or gravel for the default world. For nether and skylands, you can spawn anywhere.
  5. Offline


    Just an update from my initial attempts... this generator will have a config to allow people to set quite a bit of options... should be fun...

  6. Offline


    Huh... that's interesting. I guess it makes sense to not spawn in the middle of the woods...

    It still seems a bit off that the server will just keep generating map forever... maybe it should throw an error after about 500 chunks generated without a suitable spawn point with a custom chunk generator.
  7. Offline

    Thomas Bucher

    I will try to Hook my Plugins (SphereWorld / Dungeon) onto this.
    Looks really good so far, hope this wont change too many times in the near Future ;-P

    @Dinnerbone : Keep the work up and thank you
  8. Offline

    Celtic Minstrel

    • Looks like the generator cannot generate blocks with data values or tile entities? I guess you need a populator for that.
    • Are populators just called once per chunk?
    • Is there any way to give worlds attributes such as the perpetual but lower light of the nether or permanent day/night? Though maybe that's not in the scope of generators; still, I see that moon world and think it'd be nice if it were in perpetual darkness.
    • Does adding a world to bukkit.yml mean it will be automatically loaded on startup?
  9. Offline

    Daniel Heppner

    How do you force Maven to update/redownload the Bukkit dependencies? I'm currently coding to an ancient version of Bukkit because I refuse to go back to ANT.
  10. Offline


    Delete %userprofile%\.m2\repository\org\bukkit

    or the whole repository folder if that doesn't work, but it might take a while :)
  11. Offline


    Is there anyway to add a chunk generator to the World.Environment enum class? This is good for letting other plugins create worlds of your type, like MultiVerse.
  12. Offline


    How would you go about making mountains?

        public byte[] generate(World world, Random random, int cx, int cz) {
            this.result = new byte[32768];
            for (int x = 0; x < 16; x++) {
                for (int z = 0; z < 16; z++) {
                    int height = getHeight(world, cx +x*0.0625, cz +z*0.0625, 3) + 60;
                    for (int y = 0; y < height; y++) {
                        int idx = (x * 16 + z) * 128 + y;
                        if (y <= BEDROCK_HEIGHT) {
                            this.result[idx] = (byte) Material.BEDROCK.getId();
                        } else {
                            int r = random.nextInt(20);
                            if (r < 5) {
                                this.result[(x * 16 + z) * 128 + y] = (byte) Material.GRAVEL.getId();
                            } else if (r < 10) {
                                this.result[(x * 16 + z) * 128 + y] = (byte) Material.MOSSY_COBBLESTONE.getId();
                            } else {
                                this.result[(x * 16 + z) * 128 + y] = (byte) Material.STONE.getId();
            return this.result;
  13. Offline

    Celtic Minstrel

    No. Obviously.
  14. Offline


    Ok, just checking, but this really would be useful if it were added to bukkit. It would make it much easier to add new world types if using a plugin that manages worlds.
  15. Offline

    Dinnerbone Bukkit Team Member

    There's a system to get a generator by name. It's advised to use this. It's a much more flexible system when it comes to, for example, a library of different generators to chose from.

    As far as I understand it, MultiVerse 2.0 allows you to specify a generator name as an argument.
  16. Offline


    Sorry, but I'm a little loopy tonight, so I might just be confused with everything you're saying...

    Would it be possible to use these methods to generate (theoretically) infinite amounts of map/terrain that appear similar to the rest of the existing map?
    I want to generate a 5000x5000 block map, so that I can avoid lag later and for other reasons. >.>

    Like this guy did, except with Skylands?
  17. Offline


    You could make a plugin that would call the LoadChunk() method of the world for every chunk that you want to be generated, then unload them, and restart the server without the plugin installed.

    Thanks! I didn't think to try MV 2.0
    EDIT: Multiverse 2 isn't out yet...... Going to submit a fork request to implement alternate world generators.

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


    got another cool screenshot for PandaGen.

    what! where'd my picture go

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


    Try this:
    Or what I use for my generator (more info coming soon on that!): (also called voronoi or cell noise)

    If the description for the second one isn't really enough, basically what you do is generate say, 100 random points in a plane, iterate through every pixel and find the distance to the nearest point. It's not very fast like that though, so what I do is only go through the whole list if the nearest point is greater than x pixels away and if y % 2 == 0. Instead of going through the whole list you save the 10 or so nearest points and only calculate those most of the time, and it has very little error while still being almost 3x faster.
  20. Offline

    Dinnerbone Bukkit Team Member

    There's some noise generators (perlin and simplex) in org.bukkit.util :)
    Tim Visee and Windwaker like this.
  21. Offline


    Like tustin2121 pointed out, the server will keep generating new terrain until it finds a suitable spawn location, so this might do the trick (although its a bit hacky :))

        public boolean canSpawn(World world, int x, int z) {
            return x > 5000 && z > 5000;
    Its a good thing I didn't get around to coding my simplex generator yet! I'll definitely be using those.

    Also I'm encountering some problems with my generator right now and I need some tips. Here's what it looks like if I do everything I can to minimize the effect:
    It's a lot slower though than if I don't try to minimize it:
    I hope that picture makes sense :). You still see things like in the second picture in the first one, there just not as common.

    Edit: Now that I look at that paragraph, I realize it doesn't really make sense, so here's a github link to cancel it out:

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


    @Pandarr and everybody heres 6 pictures I took of PandaGen v0.1.

    @xpansive I think your missing a bukkit import, package org.bukkit.util.noise does not exist

    hey @Pandarr check out these files I made. it appears in cave.png that there are small (one block) pockets of stuff buried but the stats.txt doesn't show anything. Time to investigate :D
    EDIT: oops forgot the upload, its here: <Edit by Moderator: Redacted mediafire url>

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


    I just pushed some newer code which resolves the chunk border issues. Although it will crash if you walk too far.

    Don't investigate too much. If you read the code, every block has a 1 in 1000 chance of being air. Those pockets are just air.
  24. Offline


    oh :p and I noticed the crashing but thought it was something else. I did read through the code but must have missed that part.
  25. Offline


    You need to redownload your maven dependencies, just delete %userprofile%\.m2\repository\org\bukkit
    and do mvn clean install in the Bukkit source folder
  26. Offline


    Is there a way to get the biome of a block while generating in the generate() method of a ChunkGenerator?
  27. Offline


  28. Offline


    How exactly do you call generate(World world, Random random, int x, int z) ?
  29. Offline


  30. Offline


    I just meant how is it done. I've been doin' java for almost a year, and I'm still learning lingo and usage. haha
    Thanks for the link!!! :)

    Actually, I'm looking to use the default generator and just force it to trigger. Does your method do that? I don't know, I'm new to plugins. :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 17, 2016
Thread Status:
Not open for further replies.

Share This Page