ChunkGenerators & BlockPopulators FAQ

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

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

    loganwm

    Did you resolve the issue about crashing after walking too far from spawn? I actually just saw your post today, but I've had the same recurring issue with my terrain generator for this project: http://forums.bukkit.org/threads/rp...iation-realism-perks-factions-and-more.23197/

    If you're having the same issue, then I suspect that it may not be a programmatic error, but instead some small issue with either bukkit or java.

    Any information that you have on the error [or fixing it] would be appreciated, the one recurring thing that I see when it crashes is a complaint from java that it's out of memory.
     
  2. Offline

    Pandarr

    You currently can't use the default generator.

    It's an error in my code. It is currently only generating terrain 1025 blocks away from spawn. So once you get to a point where it tries to find the 1026 block, it crashes. It's not an error with bukkit or java.
     
  3. Offline

    xpansive

    The lighting values don't seem to be right in a BlockPopulator... I'm trying to make a mushroom populator which only grows them in dark areas but no matter what I put the threshold to, it seems to grow them in any area with a light level less than the max. Is there any way to force lighting updates or something like that?
     
  4. Offline

    AnniKa

    Hey, it seems like the BlockPopulator will not runned for every chunk that is created?
    How can i make the Populator run for every new chunk?

    edit:eek:k it seems to run for every chunk =)

    plze ignore this post.
     
  5. Offline

    ewized

    Could i use this to run built in generators notch has added like the nether and skylands
     
  6. Offline

    Styx Reborn

    Not yet AFAIK. Someone ported Notchgens over though.
     
  7. Offline

    crazyegoist

    Could you make somthing to fix the wrong chunks errors?
     
  8. Offline

    xpansive

    I'm having a strange issue with a populator and I'm hoping someone can help me out. Here's the code:
    Code:
    int x = (source.getX() << 4) + random.nextInt(16);
    int z = (source.getZ() << 4) + random.nextInt(16);
    int highY = world.getHighestBlockYAt(x, z);
    if (highY == 0) {
        System.out.println("OrePopulator just failed! x:" + x + ", " + (source.getX() << 4) + " z:" + z + ", " + (source.getZ() << 4));
        return; //This happens sometimes for whatever reason
    }
    int y = random.nextInt(highY);
    It doesn't make sense why the highest Y would ever be zero, my chunk generator never does that and by playing you can easily confirm it. The reason it's a problem is because random.nextInt(0) causes an error. Maybe I should just ignore this case?
     
  9. Offline

    Celtic Minstrel

    I imagine highest y could be 0 if the void were exposed and there were nothing above it. It seems reasonable to ignore that case.
     
  10. Offline

    Sushen

    Hi,
    will there be a mechanism to reload the ChunkGenerator(s) after a "reload" command ?

    (actually, the ChunkGenerator is set only on world creation)
     
  11. Offline

    Nam

  12. Offline

    monkh

    Is it possible to add BlockPopulator to the default Chunk Generator?
     
  13. Offline

    Dinnerbone Bukkit Team Member

    Yes. world.getPopulators().addPopulator(populator)
     
  14. Offline

    ryanhamshire

    Hi guys, I'm having an issue in that I want to regenerate PART of a chunk. I'd like to call on the default generator and populators to give me a chunk or chunksnapshot without applying it to the world, so that I can then apply it to the parts of the chunk I'm interested in.

    Is there ANY way I can make this happen? I did try taking a chunksnapshot first, then regenerating the chunk and reverting changes to the parts I wanted to keep, but that loses data like the contents of containers (chests), because those details are not included ina chunk snapshot (as far as I can tell).
     
  15. Offline

    IceReaper

    Is there any way i can force bukkit to use for each and every world a specific ChunkGenerator? I know i can create new worlds via java code to use a specific chunk generator. but is there any way without modifying the bukkit.yml? the worst would be checking the file and adding the param, then restarting the server :/
     
  16. Offline

    Celtic Minstrel

    I think the bukkit.yml is the only way to change the generators for the default worlds.
     
  17. Offline

    Kierrow

    Will there be some sort of BiomeGenerator class in the 1.2 Craftbukkit??
     
  18. Offline

    Celtic Minstrel

    What would that do?
     
  19. Offline

    Kierrow

    According to _jeb, since 1.2 biomes (and with them grass colors) are saved within the Minecraft world file.
    This means, in theory, there could be a way to alter the biome generation from the server, and therefore
    change the grass colors on the client.

    This is a feature I have been hoping for ever since I started working with Bukkit,
    so I'm glad that now it is actually possible. It just has to be implemented.
     
  20. Offline

    Celtic Minstrel

    I would think it would be done within the existing generator class. Perhaps there'll be a new method in ChunkGenerator to do it. I really don't know, but I don't think a new class is required.
     
  21. Offline

    daddychurchill

    Ok, I'm stumped. I have updated my various WGens (http://dev.bukkit.org/profiles/DaddyChurchill/) with getMaxHeight and all the other "best practices" metioned here and in other threads but when I switch over to using 1.2.3 R0 (dev or beta) I get a strange "spreading" effect. It is as if there is a data width issue going on. In one simple test in 1.1 this generates a flat stone field, in 1.2.3 I get this...
    [​IMG]

    In CityWorld/Conurbation I see something like this...
    [​IMG]

    The heights are correct but with width between blocks are spread out. None of the blocks are missing best I can tell, there is "just" a empty row between them. I am open to the possiblity that I am doing something wrong but so far I don't see where my code is going astray.

    Has anyone else seen this effect?
    Thanks in advance

    I also tried the new "formula" mentioned on the wiki (http://www.minecraftwiki.net/wiki/Anvil_file_format) but that just screwed things up even worse (the world was rotated 90 degrees). I am pretty sure the formula is only for the storage files and not the in memory representation used by Bukkit.

    Here is a code snippit from my ByteChunk class that all my WGens use..
    Code:
    public class ByteChunk {
        public final static int chunkWidth = 16;
       
        public int chunkX;
        public int chunkZ;
        public byte[] blocks;
        public int width;
        public int height;
           
        public ByteChunk (World world, int chunkX, int chunkZ) {
            super();
            this.chunkX = chunkX;
            this.chunkZ = chunkZ;
            this.width = chunkWidth;
            this.height = world.getMaxHeight();
            this.blocks = new byte[width * width * height];
        }
       
        public void setBlock(int x, int y, int z, byte materialId) {
            blocks[(x * width + z) * height + y] = materialId;
        }
       
        public byte getBlock(int x, int y, int z) {
            return blocks[(x * width + z) * height + y];
        }
       
        public void setBlocks(int x, int y1, int y2, int z, byte materialId) {
    //        int xz = (x * width + z) * height;
    //        Arrays.fill(blocks, xz + y1, xz + y2, materialId);
            int xz = (x * width + z) * height;
            for (int y = y1; y < y2; y++)
                blocks[xz + y] = materialId;
        }
       
        public void setBlocks(int x1, int x2, int y1, int y2, int z1, int z2, byte materialId) {
    //        for (int x = x1; x < x2; x++) {
    //            for (int z = z1; z < z2; z++) {
    //                int xz = (x * width + z) * height;
    //                Arrays.fill(blocks, xz + y1, xz + y2, materialId);
    //            }
    //        }
            for (int x = x1; x < x2; x++) {
                for (int z = z1; z < z2; z++) {
                    int xz = (x * width + z) * height;
                    for (int y = y1; y < y2; y++)
                        blocks[xz + y] = materialId;
                }
            }
        }
       
    
    I commented out the Array.fill usage on the off chance that was goofing up things but it didn't help. (the Array.fill function is a bit faster than the Y for loop)

    After further investigation, the chunks are not being spread out. Every other column (or it could be row) isn't be "generated". Still no clue how or why this is happening... sigh...

    Ok... I am really confused now...

    It turns out I need to allocate the byte array with...

    blocks = new byte[Width * Width * Height];

    (where Height is 256 from getMaxHeight)

    BUT when I am calculating where the block's byte is I need to use

    blocks[(x * width + z) * halfheight + y] = blockId;

    where halfheight is half the height (127). Does this make sense? I thought where 127/128 was used before we should be using the results from getMaxHeight.

    I am really confused :-(

    Final question on all of this... Is the byte array used during ChunkGenerator's generate still using a 16x16x128 array? If so does this mean that I can't generate "worlds" taller than 128 blocks high, even in 1.2?

    [Edit]
    I suspect this is what Mr. DinnerBone is talking about in: https://bukkit.atlassian.net/browse/BUKKIT-874 but I could be wrong.

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

    DeLux

    By simply creating a bigger array, you can (with the latest 1.2.3 CB from github, didn't try with the RBs) successfully create more than 128 blocks of height. Yay.
     
  23. Offline

    Celtic Minstrel

    I would however advise against this, as it may cause your generator to break once this issue is properly fixed.
     
  24. Seeing this too ad my worldgenerators
     
  25. Offline

    Kierrow

    Dinnerbone, will there be something like a BiomeGenerator sometime soon? With the new Anvil world format, I've heard this could be very possible.
     
  26. Offline

    Celtic Minstrel

    The answer to that question is "yes".
     
    Kierrow likes this.
  27. Offline

    DeLux

    Example code to make blocks above 127 in the latest CB from github:

    Code:
        final byte[] world = new byte[16 * 16 * 256];
                for (int x = 0; x < 16; x++) {
                    for (int y = 0; y < 256; y++) {
                        for (int z = 0; z < 16; z++) {
                            world[y + x * 256 + z * 256 * 16] = (byte) (y < 200 ? 1 : 0);
                        }
                    }
                }
                return world;
    Erm, in case it's not obvious, that goes into your generate() method in your ChunkGenerator,

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

    Celtic Minstrel

     
  29. Offline

    DeLux

    Well until a new way is added we don't really have any choice, short of saying "no world generators other than vanilla" or generating maps with a client mod and copying them over.
     
  30. Offline

    Celtic Minstrel

    "until a new way is added" = "until the next beta", probably.

    At least, I'm pretty sure I saw the commit for it in master on github.
     
Thread Status:
Not open for further replies.

Share This Page