Generate a chunk and include trees, flowers, snow, etc.

Discussion in 'Plugin Development' started by Brettflan, Jul 14, 2011.

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

    Brettflan

    When you use the World.loadChunk() function to generate a chunk which didn't previously exist, it only generates the basic terrain. Many details such as trees, flowers, and snow are not added. Of course, when a player gets close enough to the chunk for it to load for them, those missing details are then added to the chunk.

    So, has anyone found a way to have it go ahead and add those details without just having a player get near the chunk? I have a routine for my plugin which generates all missing chunks within a certain area, and naturally I'd like to be able to completely generate the chunks while I'm at it.
     
  2. I can only say that adding the details to the world is called "populating". With the introduction of custom WorldGenerators and -Populators, it should be possible to manually execute one.
    I've never done it though, so you might wanna look at the API by yourself and see if you can find something to populate a chunk.
     
  3. Offline

    Brettflan

    I played around with using a NormalChunkGenerator and the getChunkAt function, along with the necessary CraftBukkit imports and so forth, like ((CraftWorld)world).getHandle() to get the appropriate net.minecraft.server.World data to pass on to it. I also tried several other different things along similar lines. No luck, but it's very much possible I'm just missing something. From what I can tell, the BlockPopulator is not filling in the sought-after details.

    If I could track down the code used when the server is loading chunk data to be sent to a player, I might get somewhere. :oops:
     
  4. Offline

    bleachisback

    use world.getPopulators() to get a list of BlockPopulators and then use blockPopulator.populate(world,world.getSeed(),chunk) to populate the chunk. I don't know exactly how getPopulators() sorts the list, so you might want to play around with that.
     
  5. Offline

    Brettflan

    world.getPopulators().size() is 0. No blockPopulator(s) returned. Perhaps it only returns non-standard blockPopulators and not the default one(s)?
    EDIT: though this is the standard Bukkit World class; perhaps a CraftWorld or net.minecraft.server.World would fare better. Might try that in a bit. :(
    EDIT 2: no better luck with CraftWorld, and there is no blockPopulator in the basic net.minecraft.server.World.
    I also tried world.getGenerator().getDefaultPopulators(world), but world.getGenerator() returns null.

    Bah.

    EDIT 3: OK, to answer my own question (sort of), I found that loading the chunks and leaving them loaded had it populate them (yay!); I had previously been unloading them after generation to clear the memory up. I'd seen it mentioned elsewhere that a chunk is only populated if the chunks to all 4 sides of it exist; for some reason I thought that as long as they had been generated it would work, but apparently they have to be loaded into memory. It does seem that as soon as all 4 side chunks are loaded for any chunk, it will automatically populate that chunk without needing further prompting.

    So I guess I'll just need to come up with a queue to unload the blocks only after they're no longer needed, something like a trailing FIFO queue. At least I have a working method now, anyway. :D
     
Thread Status:
Not open for further replies.

Share This Page