Custom Generator

Discussion in 'Spigot Plugin Development' started by Spedwards, Jun 17, 2016.

  1. So I got all the errors sorted out with my Custom Generator, except it doesn't actually populate the world :oops:.

    Looking through the API, I couldn't find the normal chunk generator, so I'm not sure what I'm to return. What am I to return in the generateChunkData method to use the normal chunk generator?
     
  2. I know not many people are experienced with ChunkGenerators but I had hoped for at least one response. :/
     
  3. Why would you need the default chunk generator? And you can create a new ChunkData instance with I believe Bukkit.createChunkData()
     
  4. If this works, I'm going to kill myself... I looked through all the generator code in both Bukkit and NMS expecting the answer to be there, never expected it to be in the main class.

    Will test and let you know.

    UPDATE: Did not work. Still a Void World Generator.
     
  5. Any other suggestions?
     
  6. I just use pure NMS for world generators, it gives more control and is a lot less work, just inserting a class that extends ChunkProviderGenerate (i think it is called) into the generator field in each WorldServer object works fine.
     
  7. I only know how to do flat worlds.
     
  8. Are you able to provide an example at all? I've never worked with NMS before.

    If it changes anything, all I'm doing is removing certain biomes, and I also have a BlockPopulator.
     
  9. MiniDigger

    Supporter

  10. If you've been following any of what I've been doing, I already have a ChunkGenerator and BlockPopulator, except it doesn't generate the world. Just void.
     
  11. MiniDigger

    Supporter

    well, try and debug it. check if your generator gets called and if you populator gets called.
     
  12. The BlockPopulator definitely, 100%, no doubt about it gets called:
    [​IMG]

    Also, so does the ChunkGenerator. The biomes I've removed don't get created.
     
  13. MiniDigger

    Supporter

    well without code we can't help you. something seems to be wrong with your chunk generator. at what level are the shrooms located?
     
  14. I've got it in some other posts but I'll share it again here.

    Generator:
    Code (Text):
    public class DeathGamesGenerator extends ChunkGenerator {
     
        List<BlockPopulator> populators = new ArrayList<BlockPopulator>();
     
        public DeathGamesGenerator() {
            populators.add(new MushroomPopulator());
        }
     
        @Override
        public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) {
            List<Biome> blacklist = Arrays.asList(Biome.BEACHES, Biome.COLD_BEACH, Biome.FROZEN_OCEAN, Biome.HELL, Biome.MUSHROOM_ISLAND, Biome.MUSHROOM_ISLAND_SHORE, Biome.OCEAN, Biome.SKY, Biome.STONE_BEACH, Biome.VOID, Biome.EXTREME_HILLS, Biome.EXTREME_HILLS_WITH_TREES, Biome.MUTATED_EXTREME_HILLS, Biome.MUTATED_EXTREME_HILLS_WITH_TREES);
         
            for (int X = 0; X < 16; X++) {
                for (int Z = 0; Z < 16; Z++) {
                    if (blacklist.contains(biome.getBiome(X, Z))) {
                        biome.setBiome(X, Z, Biome.PLAINS);
                    }
                }
            }
         
            return createChunkData(world);
        }
     
        public List<BlockPopulator> getDefaultPopulators(World world) {
            return populators;
        }
     
    }
    Populator:
    Code (Text):
    public class MushroomPopulator extends BlockPopulator {

        @Override
        public void populate(World world, Random r, Chunk chunk) {
            // TODO Auto-generated method stub
            int cX = chunk.getX();
            int cZ = chunk.getZ();
            int cXOffset;
            int cZOffset;
            Material mushroom;
         
            for (int i = 0; i < 16*16; i++) {
                cXOffset = cX + r.nextInt(16);
                cZOffset = cZ + r.nextInt(16);
                if (world.getBiome(cXOffset, cZOffset) == Biome.SWAMPLAND) {
                    if (r.nextBoolean()) {
                        mushroom = r.nextBoolean() ? Material.BROWN_MUSHROOM : Material.RED_MUSHROOM;
                        world.getHighestBlockAt(cXOffset, cZOffset).getRelative(BlockFace.UP).setType(mushroom);
                    } else if (r.nextBoolean() && r.nextBoolean()) {
                        world.getHighestBlockAt(cXOffset, cZOffset).getRelative(BlockFace.UP).setType(Material.LONG_GRASS);
                    }
                }
            }
        }

    }
    And before anyone says anything, I'm aware of what my BlockPopulator is doing. I am yet to improve the loop.
     
  15. @Spedwards in case you didn't know, Bukkit.createChunkData () creates an empty chunk, it does not fill it with default blocks.
     
    • Informative Informative x 1
  16. This was made obvious by it generating a void world :p

    I want to know what to use to get it to generate a normal world.
     
  17. MiniDigger

    Supporter

    take a look at bukkits integrated chunk generators.
     
  18. @Spedwards it will make your plugin work on a specific version only (unless you use special handling of stuff), but you could extend org.bukkit.craftbukkit.v<version>.generator.NormalChunkGenerator
     
  19. That's a good idea... Any ideas on getting the NMS World from a string of the world name? Currently searching the CraftBukkit code looking for a method myself.