1.17.1 How to get an instance of vanilla's ChunkGenerator?

Discussion in 'Spigot Plugin Development' started by JIR0_, Dec 5, 2021.

  1. I've been doing

    Code (Text):
    ChunkGenerator vanillaGenerator = super.getDefaultWorldGenerator("world", "");
    to get an instance of vanilla's ChunkGenerator but it seems to return null. How am I supposed to get it?

    And if you wonder why I need it, well, I want to add my own custom BlockPopulator, but to do so I need to override the function getDefaultPopulators inside of a custom ChunkGenerator class that i created. The problem is, as soon as I create that custom ChunkGenerator class to register my new populators, all the code of chunk generation is lost and my world is just void. I need to code myself the whole chunk generation in there.

    So I wanted to get an instance of the vanilla ChunkGenerator to pass it to my custom ChunkGenerator class and just use its generation.
     
  2. You don't need to create a ChunkGenerator if you only want to add a BlockPopulator.
    You can listen to the WorldInitEvent and add it to the worlds BlockPopulator List. You also need to set your plugin load to STARTUP in your plugin.yml.
     
    • Agree Agree x 1
    • Informative Informative x 1
    • Useful Useful x 1
  3. Thank you! This seems to work perfectly.

    However, just one small issue. Since my plugin now loads on STARTUP, some code inside my onEnable method is broken now. For example, "
    Bukkit.getScoreboardManager().getMainScoreboard();".

    I assume this is because the server hasn't fully finished starting up. My question is, what event is triggered just after the worlds have been fully loaded? So it can just replace what onEnable would be if I hadn't added load: startup

    Thank you
     
  4. WorldLoadEvent? Or even better ServerLoadEvent.
     
  5. Alternatively, you can schedule that code to run a tick later, which will only happen once the server is fully started up.
     
  6. Thank you all. One last question, how can I remove BlockPopulators? I just figured out how to add my own ones, but if for example I wanna reduce the amount of Iron that spawns, how can I remove vanilla Iron Ore populator and add my own reduced one?