1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

World Generator - generateChunk - Write in other chunk

Discussion in 'Development' started by benda95280, Jul 30, 2021.

  1. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    Hi All,

    I'm looking on how, when using a Generator (inside generateChunk), i can do to write 'correctly' in another chunk.

    Basicaly, Generator is like :
    PHP:
        public function generateChunk(int $chunkXint $chunkZ): void {
            
    $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ $this->level->getSeed());

            
    /** @phpstan-var Chunk $chunk */
            
    $chunk $this->level->getChunk($chunkX$chunkZ);
    When i try to do as below, it return NULL
    PHP:
    //level = ChunkManager//
    $this->level->getChunk($x,$z)
    If i try to do getBlockId() on the current chuck, to get data outside the chunk, it return 0.

    If i want to create a large structure, hole, bridge ... I'm not able to check if there is block.
    I've tried to set blocks, but some other 'rendering chunks' seems to override the data :

    [​IMG]

    I've tried to check in generator if the current chunk contain data before adding block, with something like
    PHP:
    if($chunk->getBlockId($x$y$z) != 0) continue;
    It do not work, like it do not 'see' the block populated by the other thread.
    https://github.com/CzechPMDevs/Mult...rld/generator/normal/NormalGenerator.php#L176

    Questions :
    # How i can avoid my corridor to be overrided ? (See image upper)
    # Is there a way to render the chuck before populating it ? (To be able to check block ID inside it)
    # Could it be done using the "ChunkPopulateEvent" ?

    Source of Generator :
    https://github.com/CzechPMDevs/Mult...ltiworld/generator/normal/NormalGenerator.php

    Source of Populator :
    https://github.com/Ad5001/BetterGen...01/BetterGen/populator/MineshaftPopulator.php

    Thanks, and correct me if i'm wrong :)
     
    Last edited: Jul 30, 2021
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    Perhaps, you can make your mineshaft populator run last?
     
  3. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    I don't think i could be possible because make running the populator at the end of the chuck generation won't make it able to have information on ungenerated chuck.
    (Could be possible if it was able to ask or launch this generation, and wait it)

    World Gereration could be initiated one time per world and (I think) generateChunk is called Async and multiples times simultaneously.

    Extract of 'pocketmine.yml' config file :
    Code:
    chunk-generation:
      #Max. amount of chunks in the waiting queue to be populated
      population-queue-size: 32
    • I don't know how one thread can write in other chunks (see previous screenshot) but it seems to do it
    • How i can do to prevent currently running, or next thread to not replace block already placed
    If i'm wrong somewhere please tell me.
     
  4. Primus

    Primus Zombie Pigman

    Messages:
    749
    I once was planning to implement mineshafts myself, didn't get to it. I did however implement something else you might find useful: https://github.com/BlockHorizons/BlockGenerator

    I would be more than happy to help you with this, however, I no longer develop such things and I might misguide. You might have a better chance if you asked in the discord server.
     
  5. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    Thanks for the answer, i've already tried in Discord :)

    I've found interesting things in your previous link in ravine populator, for the chunk management, but it is disabled.
    Do you know why ?

    [EDIT]
    First investigation show that Init() in generator is called :
    - 6 times when level is created
    - 6 times too when loaded and chunk not existing generated manually
    - 6 times when player TP into the world unloaded

    [EDIT2]
    Each Generation initiated are used to generate chunk.
    So i'm thinking that each generator can generate a set of chunks, and maybe be able to write more in these chunks.
     
    Last edited: Aug 1, 2021
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.