How do I connect chunks in a ChunkGenerator?

Discussion in 'Plugin Development' started by ocomobock, Dec 4, 2017.

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

    ocomobock

    I will marry whoever can help me figure this out.

    Let's say I want to create a line of blocks using the ChunkGenerator class. The ChunkGenerator class only lets you work in one chunk at a time. SO: If I can't go outside of the chunk I'm modifying, how am I supposed to create a line of blocks?

    I can do setBlock(14,128,14), but if I do setBlock(17,128,17), this won't work, because it is greater than 16.

    Please help. I'm dying here. I've posted about this before but I still can't figure it out. Would seriously love some help
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    ocomobock

    Well I just kind of used the line as an example. What I'm actually doing is creating cave systems, but I don't necessarily calculate a line to do it. Here is some very pseudo code:

    - create sphere
    - shift center in a random direction
    - create another sphere
    - repeat

    This works in the BlockPopulator class, but not the ChunkGenerator class as I've explained
     
  4. Offline

    timtower Administrator Administrator Moderator

    @ocomobock Caves are generally also a blockpopulator thing, why would you want it in the generator?
     
  5. Offline

    ocomobock

    Ah ok, well I was told bigger structures are typically used in a ChunkGenerator. I figured caves fit into that category.

    The caves I'm making cause lag sometimes, and I thought that was because they were being made through the BlockPopulator class. So that's why I thought I should move it to the ChunkGenerator

    Basically I just wanted the caves to generate with the chunks, not after the chunks were generated. I believe this is how it works in normal Minecraft generation anyway
     
  6. ChunkGenerators basically let you set the chunk data all in one go. Doing block.setType or otherwise manipulating it causes block updates, which is best to only be done where necessary. In fact though Mojang does prettymuch all the generation without block updates, and does a few to fix things like floating gravel I think.

    If you are using perlin noise to calculate when the caves are generated or are otherwise able to repeatedly get the same answer when you get a random number at the given coordinates, you can check if any spheres would generate by this random chance in the neighboring chunks, and if so continue to generate the spheres in this chunk around the starting point of the sphere.

    Also, do not use block.getRelative to modify blocks outside the chunk unless you know that the chunk is generated and loaded already; that will throw errors and not work.
     
  7. Offline

    ocomobock

    Okay, so basically for each chunk I've gotta check if the perlin noise generator allowed caves to be generated there by chance, and then continue the cave?

    I probably could have worded that better, but I'm just trying to make sure I understand.
     
  8. Yes, that is correct. Any method which will tell you the random numbers/data the chunk will get, without the chunk necessarily being loaded yet. java.util.Random will not work for this properly in most cases I think.
     
  9. Offline

    ocomobock

    Okay, I will give this a shot. Thanks so much for the suggestion, I may actually be able to solve this now.
     
Thread Status:
Not open for further replies.

Share This Page