Problem with generating world

Discussion in 'Plugin Development' started by IkeVoodoo, Oct 12, 2020.

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

    IkeVoodoo

    Hello, i am having problems generating a world, first, i am trying to generate the world when something is said (as a test), but it runs on the chat thread, is there a way i could run it on the server thread? also, when generating the world it stops at

    12.10 14:41:06 [Server] Async Chat Thread - #0/INFO Arrow Despawn Rate: 1200 Trident Respawn Rate:1200

    any particular reason? (i don't get any errors, apart when disabling then re enabling the plugin trough plugman wich throws a:

    "12.10 14:50:01 [Server] Async Chat Thread - #2/ERROR Could not pass event AsyncPlayerChatEvent to WorldGeneratorTestPlugin v1.0")

    to generate a world i do:

    Code:
    WorldCreator c = new WorldCreator(worldName);
    c.type(type);
    c.environment(dimension);
    c.generateStructures(generateStructures);
    if(seed != null) c.seed(seed.longValue());
    if(chunkGen != null) c.generator(chunkGen);
    generatedWorld = c.createWorld();
    worldName is a string, in this case "TestingWorld"
    type is WorldType.NORMAL
    generateStructures is a boolean set to true
    seed is a "Long" (not long, i used the wrapper class) that is set to null unless set with a method
    chunkGen is a ChunkGenerator (in this case it is set to a custom chunk generator, ill show in a second)
    generatedWorld is to output it
    dimension is Envirioment.NORMAL

    now, for the chunk generator i followed bukkits tutorial page "https://bukkit.gamepedia.com/Developing_a_World_Generator_Plugin"

    here is the code:

    Code:
    SimplexOctaveGenerator generator = new SimplexOctaveGenerator(new Random(world.getSeed()), octaves);
            ChunkData chunk = createChunkData(world);
            generator.setScale(generatorScale);
            for (int X = 0; X < 16; X++)
                for (int Z = 0; Z < 16; Z++) {
                    currentHeight = (int) ((generator.noise(chunkX * 16 + X, chunkZ * 16 + Z, 0.5D, 0.5D, true) + 1) * maxWorldHeight + minWorldHeight);
                    blockGen.generateBlocks(X, Z, currentHeight, world);
                }
    
    octaves is an int set to 8
    currentHeight is an int set to 50
    minWorldHeight is a double set to 50D
    maxWorldHeight is a double set to 15D
    generatorScale is a double set to 0.005D
    blockGen is the block generator (ill show in a sec)

    also i have a list

    private List<BlockPopulator> populators = new ArrayList<>();

    wich has in it a TreePopulator (explaining this too in a sec)

    the block generator is an interface, with one method:

    public void generateBlocks(int X, int Z, int currentHeight, World world);

    wich i then use to make "MyBlockGenerator" (a test)

    Code:
    BlockUtils.setBlock(world, X, currentHeight, Z, Material.GRASS);
    BlockUtils.setBlock(world, X, currentHeight - 1, Z, Material.DIRT);
    for (int i = currentHeight - 2; i > 0; i--)
        BlockUtils.setBlock(world, X, i, Z, Material.STONE);
    BlockUtils.setBlock(world, X, 0, Z, Material.BEDROCK);
    
    
    Block utils is just a utility class for blocks, when setting a block it does

    world.getBlockAt(new Location(world, posX, posY, posZ)).setType(type);

    when i want to register a populator (like the TreePopulator) i add it to the list, and return the list, full thing:

    Code:
    private List<BlockPopulator> populators = new ArrayList<>();
       
    public void addPopulator(BlockPopulator populator) {
        populators.add(populator);
    }
       
    @Override
    public List<BlockPopulator> getDefaultPopulators(World world) {
        return populators;
    }
    
    
    in my chat method (as a test) i do:

    Code:
    MyBlockGenerator blockGen = new MyBlockGenerator(); 
    CustomChunkGenerator chunkGen = new CustomChunkGenerator(blockGen);
    TreePopulator treePop = new TreePopulator();
    treePop.biomeBased(false);
    treePop.setTreeAmount(8);
    chunkGen.addPopulator(treePop);
    WorldGenerator worldGen = new WorldGenerator("MyTestingWorld");
    worldGen.setChunkGenerator(chunkGen);
    worldGen.create();
    worldGen.teleportPlayer("IkeVoodoo");
    
    
    and thats pretty much all of it, any help is appreciated!
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    IkeVoodoo

    diden't think about that, i will try and report it

    it now ends with

    "12.10 15:22:40 [Server] Server thread/INFO Nerfing mobs spawned from spawners: false"

    and after 30 seconds or so it proceeds with

    https://pastebin.com/57tv998M

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 12, 2020
  4. Offline

    KingOfMars4

    What is the bukkit version you are trying to use?
     
  5. Offline

    IkeVoodoo

    1.16.3, wait, i have 1.16.2 i think, let me try update

    EDIT: nvm i have 1.16.3
     
    Last edited: Oct 12, 2020
  6. Offline

    IkeVoodoo

    still no luck, but i have made a step forward, i have figured wich class is causing the problem:

    so i tested my code with just


    WorldGenerator worldGen = new WorldGenerator("MyTestingWorld");
    worldGen.create();

    and surprisingly, it worked!

    however, when adding in the chunk generator


    MyBlockGenerator blockGen = new MyBlockGenerator();
    CustomChunkGenerator gen = new CustomChunkGenerator(blockGen);
    WorldGenerator worldGen = new WorldGenerator("MyTestingWorld");
    worldGen.setChunkGenerator(gen);
    worldGen.create();

    it caused the error, i will try to make it work without the block generation, and ill see how it goes

    ok, i tried and it dosent generate the world, at all. i will try again to getting this to work

    after looking more, i found out that on line 69 (nice) c.createWorld() throws an error, but it dosent say wich, ill find it

    ok now, what was i thinking, bukkit's page said


    currentHeight = (int) (generator.noise(chunkX*16+X, chunkZ*16+Z, 0.5D, 0.5D)*15D+50D);

    i did

    currentHeight = (int) ((generator.noise(chunkX * 16 + X, chunkZ * 16 + Z, 0.5D, 0.5D, true) + 1) * 15D+ 50D);

    ill try it again

    EDIT: it now works!
     
    Last edited: Oct 13, 2020
Thread Status:
Not open for further replies.

Share This Page