ChunkGenerators & BlockPopulators FAQ

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

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

    Corgano

    Anyone found a way to do biomes? Notch promised to but only went over noise generators, then jtjj222 teased us with 5 extremely nice tutorials and then got too busy...

    Does ANYONE have the time and know how to do a tutorial on biomes?!?
     
    Jbody likes this.
  2. Offline

    Celtic Minstrel

    What are you really asking...
     
  3. Offline

    jtjj222

    Use the biomegrid object to set/get biome data from the chunk generator. Use World.getBlock().getBiome() (I think) from a block populator. I will write up a tutorial later today :D
     
    deadlock989 likes this.
  4. Offline

    4am

    Been searching for this answer all over - should have started at the source!
     
  5. Offline

    Splated

    Is there a way to make the world type "The End" with just a ChunkGenerator ?

    Im trying to make the first loaded world The End.
     
  6. Offline

    Scorpion_vn

    Hi, is it normal that I get a ton of compile errors with 1.5 API?
    There is no Event.Type,
    There is no WorldListener,
    There is no Event.Priority.

    How could one port this snippet to 1.5 API?
    Thanks in advance.

    Well I did it:
    Code:
      public void onEnable(){
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvent(WorldInitEvent.class, new Listener (){}, EventPriority.NORMAL, new EventExecutor() {
                public void execute(Listener listener, Event event) throws EventException {
                    WorldInitEvent initEvent = (WorldInitEvent) event;
                    initEvent.getWorld().getPopulators().add(new MyPopulator());
                    getLogger().log(Level.FINEST, "injected MyPopulator");
                }
            }, this);
        }
    
     
  7. Offline

    El_Minadero

    Are there any good tutorials out there for customized ore generation using Vanilla terrain generation? jtj222 mentioned something about block populators, but I feel like i need a written tutorial to get it down.
     
  8. Offline

    jtjj222

    I wrote a tutorial about block popualtors. It was in the plugin tutorials I sent you :p
     
  9. Offline

    El_Minadero

    was it? how am i missing all of these. lol
     
  10. Offline

    Ewe Loon

    A word of warning, in case no-one has mentioned it

    as of 1.5 the plugin will reload when "/reload all" is called, but the populator isn't reloaed, so stored references to the plugin will become invalid, this is importat, if you need to shedule delated tasks
     
    Tim Visee likes this.
  11. Offline

    Sebi

    I have a problem with generating terrain, I've looked through the forums but with no results.

    I'm trying to create a generator that, for certain chunks, will use the original generator but for others I want to use my own generator.

    I was thinking of simply doing:
    Code:
    public byte[][] generateBlockSections(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
            if(...) {
                byte[][] result = new byte[world.getMaxHeight() / 16][];
               ... // generate my own terrain
                return result;
            }else{
                return defaultGenerator.generateBlockSections(world, random, chunkX, chunkZ, biomeGrid); // use default generator
            }
        }
    Where defaultGenerator is ChunkGenerator from the main world (normal generator) but it turns out that getGenerator method executed on world with default chunk generator returns null. Is there a way to pass certain chunks back to the default generator?

    Thanks
     
    NeeL likes this.
  12. Offline

    Zacky1

    There can only be one generator per world, and you can't change generators while the server is running... But I think you're on something :)
     
  13. Offline

    jtjj222

    Reflection perhaps? Create and maintain an instance of the default generator using reflection, then use it to generate the chunks you need?
     
  14. Offline

    lgoss007

    What's the way to generate terrains now? This FAQ and other tutorials/code all use generate or generateBlockSections (both deprecated) to generate and in order to set the block in a generator they all use BLOCK.getId(). Is there an alternative method or process to generate terrain now?
     
    jtjj222 likes this.
  15. Offline

    jtjj222

  16. Offline

    Draakor

    I didn't get this AT ALL. A little plain English would be nice, that's all :/
    And I don't know JavaScript T.T
     
  17. Offline

    jtjj222

    This post talks mostly about how to develop world generators, not how to use them. If you want to use one, look up instructions for your world management plugin, or (if you don't have one) you need to add a few options to the bukkit.yml configuration:
    Code:
    worlds:
      worldName:
        generator: generatorName
    
    Note that the spacing is very important. Worlds should have no spaces in front of it, worldName should have 2, and generator should have 2.[/code]
     
  18. Offline

    egetheking

  19. Offline

    Assist

    Goblom likes this.
  20. Offline

    2000callum

    Hmm /autobuild DirtHouse :)
     
  21. Offline

    mossyblog

    There appears to be a bug or unintended routine in the overall BlockPopulator workflow.

    I've been testing all day, but basically i've found that if you iterate over a chunk using the 16x256x16 (xyz) for loops (normal) and you swap out say "COAL_ORE" material for Glowstone then basically the overall Chunk will appear as per design.

    If you however swap out the COAL_ORE for STONE the BlockPopulator gives off the appearance of being ignored, that is to say at the time of your "populate()" the overal COAL_ORE found maybe say 217. Yet at Game-time, ie assuming post WorldLoad the COAL_ORE for that chunk is around 297 (numbers vary of course but the additional ore's dont).

    As far as I can tell there appears to be a last check on a chunk of some sort that injects additional ORE (iron, coal etc). I also found this happens AFTER the ChunkPopulateEvent aswell.

    A test I wrote was:
    • Iterate over the Chunk and set the ORE properties to GLOWSTONE
    • Iterate over the same Chunk again but within the ChunkPopulateEvent and swap out the GLOWSTONE for STONE.
    The results keep coming back with an additional 74+ COAL_ORE's being added post Populate event(s).
    If I swap the GLOWSTONE with STONE or COBBLESTONE the problem is back. If it's any other block, it goes away?
    So there is something somewhere looking for STONE/COBBLESTONE and propping up the ORE counts? Any pointers?
    Code:
    Code:java
    1. @EventHandler
    2. public void onChunkLoad(ChunkPopulateEvent event ) {
    3.  
    4.  
    5. Chunk ch = event.getChunk();
    6. String comp = ch +"";
    7. if(!comp.contains("x=-15z=15")) {
    8. return;
    9. }
    10. log("Loaded Chunk " + ch);
    11.  
    12.  
    13. for(int x = 0; x <= 16; x++) {
    14. for(int y = 0; y <= 256; y++) {
    15. for(int z = 0; z <= 16; z++) {
    16. Block b = ch.getBlock(x, y, z);
    17. if(b.getType() == Material.GLOWSTONE)
    18. b.setTypeIdAndData(1, (byte)0,false);
    19. }
    20. }
    21. }
    22. }


    Populator:
    Code:java
    1. @Override
    2. public void populate(World w, Random r, Chunk ch)
    3. {
    4. double cx = ch.getX();
    5. double cz = ch.getZ();
    6.  
    7. String comp = ch +"";
    8.  
    9.  
    10. if(!comp.contains("x=-15z=15")) {
    11.  
    12. return;
    13. }
    14. MossyPlugin.log("Processing: " + comp);
    15. int cntr = 0;
    16. for(int x = 0; x <= 16; x++) {
    17. for(int y = 0; y <= 256; y++) {
    18. for(int z = 0; z <= 16; z++) {
    19. Block b = ch.getBlock(x, y, z);
    20. if( b.getType() == Material.COAL_ORE
    21. || b.getType() == Material.IRON_ORE
    22. || b.getType() == Material.REDSTONE_ORE
    23. || b.getType() == Material.DIAMOND_ORE
    24. || b.getType() == Material.EMERALD_ORE
    25. || b.getType() == Material.GOLD_ORE
    26. || b.getType() == Material.LAPIS_ORE
    27. || b.getType() == Material.STONE
    28. ) {
    29. cntr+=1;
    30. b.setType(Material.GLOWSTONE);
    31. // b.setType(Material.STONE);
    32. }
    33. }
    34. }
    35. }
    36. MossyPlugin.log("Total Coal:"+cntr);
    37. }

    Attached Image shows that if I set the ORE to CobbleStone they work except the lingering few which are out of my iteration scopes control? (even though I am still setting it as STONE manually still ignores me).
     

    Attached Files:

  22. Offline

    RawCode

    If you want to replace some block with other block at generation stage - generate proper blocks initially.
    This makes absolutely no sence to generate chunk with block A and instantly replace it with block B.

    If you edit chunks generated by vanilla - vanilla can place ores into nearby chunks, just filtering chunks wont work, especially with large objects like nether fortresses of strongholds.
     
  23. Offline

    bars96

    How to remove ponds (small lakes) and trees (not mushrooms) from default populator?
     
  24. Offline

    Dirius77

    I'm trying to create a custom generator for a new dimension, and it needs to be able to place Stone Bricks in all of its different forms, how can I do this with these generators? As far as I've seen all I can get is Stone Brick.
     
  25. Offline

    deltahat


    What you are seeing is an unfortunate side effect of the ChunkGenerator API being neglected as bukkit evolved. To create stone blocks in different form, you have to change the block data associated with the block. The ChunkGenerator only allows you to set the block's ID, which specifies its material. You unfortunately cannot set the block data with a ChunkGenerator.
     
    jtjj222 likes this.
  26. Offline

    minelazz

    jtjj222 likes this.
Thread Status:
Not open for further replies.

Share This Page