ChunkGenerators & BlockPopulators FAQ

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

Thread Status:
Not open for further replies.
  1. Can Mike Primm please explain, I cant figure what each byte[][] coord maps to
  2. OK - new format reflects the new structure of the chunks in vanilla:

    1) Chunks are taller - now 256 - and represented by a stack of 16 x 16 x 16 cubiods called sections. As each section is 16 blocks high, there potentially 16 in the current chunks. The index of the section containing the blocks with a given Y coordinate is (Y / 16) or (Y >> 4).
    2) To save memory, and improve performance, whole sections that are empty can be undefined - this is part of how maps were migrated, as existing maps were limited to 128, and thus only could have content in the first 8 sections (0-7).
    3) Within a given section, the native order of the blocks in the vanilla code was altered: for a given coordinate within the section (X = 0-15, as before; (Y & 0xF) = YY = 0-15; Z = 0-15, as before), the index is ((Y & 0xF) << 8) | (Z << 4) | X.

    So, the resulting return values have the following structure:


    The suggestion is to allocate the first level array based on the world height divided by 16:

    byte[][] result = new byte[16][];

    Then, the sections (each of which are 16 * 16 * 16 blocks) can be allocated as needed (that is, when you set one of their blocks to non-empty). Here are a pair of simple access wrappers that both illustrate the mapping, and the 'allocate sections when needed' characteristic:

      int getBlockID(byte[][] cdata, int x, int y, int z) {
          int sy = y >> 4;
          if (cdata[sy] == null) {
              return 0;
          return (int)cdata[sy][((y & 0xF) << 8) | (z << 4) | x) & 0xFF;
      void setBlockID(byte[][] cdata, int x, int y, int z, int blkid) {
          int sy = y >> 4;
          if(cdata[sy] == null) {
              cdata[sy] = new byte[4096];
          cdata[sy][((y & 0xF) << 8) | (z << 4) | x) = (byte)blkid;
    My apologies on the lack of clarity in the javadoc - I'll write up an updated version sometime today.
  3. could someone maybe help me with the beginnings of the ChunkGenerator? I'm not having troubles for two days and actually I only want to create a flatland generator...

    Oh And I'm using bukkit for 1.2

    Kind regards,
  4. Already fixed, and the worldgen is only part of the plugin I'm making

  5. Okay, did you read the post just above yours?
  6. Yes I did, however, it still didn't work, then I got the issue (very noobish) but I had an outdated dev build =)

  7. Oh wait, you said you fixed your issue. Never mind then, carry on!
  8. Question: is there anywhere some documentation but the API where you can learn about populators? I would really like to expiriment with some wgen plugins but it just don't seem that there are any good guides about it?

  9. I'm pretty sure it's as simple as "Here's a chunk; modify it as you please".
  10. lol yea but I mean how the methods work =(
  11. daddychurchill and zipron like this.
  12. Offline


    This was really helpful. For some reason I keep getting errors on the following things though:

    In the Moon Chunk Generator class I get an error at the beginning of the class on "MoonChunkGenerator" (public class MoonChunkGenerator extends ChunkGenerator)

    When I hover over it it says: "The type MoonChunkGenerator must implement the inherited abstract method ChunkGenerator.generate(World, Random, int, int)"

    Another error I get is in the same class on the line that says: "public byte[][] generateBlockSections(World world, Random random, int cx, int cz, BiomeGrid biomes" The error is on the text BiomeGrid, hovering over it it says "BiomeGrid cannot be resolved to a type"

    Sorry about posting this here, I am fairly new to Java so I am not very good with this sort of stuff yet.

    Just forgot to update my version of Bukkit. Problem solved.
  13. You're building with a downlevel bukkit.jar - you'll need to update to at least the 1.2.3-R0.2 one.
  14. Offline


    Well, I feel dumb, could have sworn that I updated Bukkit, but I guess I copied the old one back to the same folder.
    That fixed the problem.
    Thanks Mike.
  15. Offline


    Mike, Nice example THX
  16. I'm coding a small plugin that basically needs to do two things:
    1. Alter the size and rarity of natural spawning ore veins
    2. Whenever a vein is generated (I assume this is done by a BlockPopulator) retrieve and store the locations of the ore blocks.
    Is there an easy way to do this without writing my own generator from scratch?
  17. You can write your own ore BlockPopulator and add it to the default generator. I don't think you can remove the default ore populator, though.
  18. Offline


  19. Offline


  20. Offline


    odd this plugin example gives me an error on /moon
    10:50:56 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'moon
    ' in plugin BukkitFullOfMoon v0.1.0
            at org.bukkit.command.PluginCommand.execute(
            at org.bukkit.command.SimpleCommandMap.dispatch(
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(
            at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.
            at net.minecraft.server.NetServerHandler.a(
            at net.minecraft.server.Packet3Chat.handle(
            at net.minecraft.server.NetworkManager.b(
            at net.minecraft.server.NetServerHandler.a(
            at net.minecraft.server.NetworkListenThread.a(
            at net.minecraft.server.MinecraftServer.w(
    Caused by: java.lang.NoSuchMethodError: org.bukkit.Server.createWorld(Ljava/lang
            at com.dinnerbone.bukkit.moon.BukkitMoon.getMoon(
            at com.dinnerbone.bukkit.moon.MoonCommandExec.onCommand(MoonCommandExec.
            at org.bukkit.command.PluginCommand.execute(
            ... 12 more
  21. Offline


    Sorry, I didn't test it... It appears as if it is still using the old world creation methods.
  22. Offline


    thanks for looking into it xpansive. Dinnerbone, I'd be eternally grateful if you could fix this little snafu.
  23. Hi thanks for this but I've a problem. I searched on this topic if I could find how to generate mountains in my world generator. What I just want is generate small hills with a heigh difference of 5 or something, so yes really small smooth hills like the flatlands biome in minecraft. I tested the following code (the noice generator with the 'height' variable part);
    private NoiseGenerator generator;
    NoiseGenerator getGenerator(World world) {
            if (
    generator == null) {
    generator = new SimplexNoiseGenerator(world);
    int getHeight(World worlddouble xdouble yint variance) {
    NoiseGenerator gen getGenerator(world);
    double result gen.noise(xy);
    result *= variance;
    byte[] generate(World worldRandom randomint cxint cz) {
    byte[] result = new byte[32768];
            for (
    int x 016x++) {
                for (
    int z 016z++) {
    int height getHeight(worldcx 0.0625cz 0.06252) + 60;
                    for (
    int y 0heighty++) {
    result[(16 z) * 128 y] = (byte)Material.SPONGE.getId();
    but this doesn't look really smooth I want to spread it out to make it smoother but when I change some numbers in here;
     int height getHeight(worldcx 0.0625cz 0.06252) + 60;
    it won't work too. Could anyone help me with a explenation for noice generators to generate smooth hills? That would be really cool!
    Thanks in advance,
    Tim Visée

    I already found the solution. You could find the solution here;

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 17, 2016
  24. Offline


    I have been spinning around a problem that I think is actually buried in Bukkit. Specifically I was working on my CityWorld generator and was getting crazy NULL reference exception that I could not find. Eventually (about four hours later) I traced it down to the returning of certain Biomes via generateBlockSections. It seems that if you return SCRUBLAND eventually a null exception is thrown way down deep in Bukkit.

    From my glancing at the bukkit code via JD, it looks like the following biomes are not "referenced" in CraftBlock.class' static initializer...
    • TUNDRA

    I might be wrong but not using those biomes definitely make things work better. :)
    I am heading over to post an official bug report but figured I would alert the fellow world generators of the potential issue.

    [BUG -]
  25. Hmm, strange in my world generator (Dungeon Maze, released soon) I didn't have this problem, well I think, not sure. When I really don't have this problem I don't know what happend :(
  26. They may be old biomes from before they redid the biome code...
  27. Offline


    Based on my conversations with Mike it sounds like that is the case
Thread Status:
Not open for further replies.

Share This Page